0

Is it possible to get the list of validators which validate a particular block?

For instance, let's say we have at block 10 and if this block is finalised then I need to find the list of validators who approved this 10th block.

2
  • can you explain a bit more what you are trying to acheive? Commented Feb 1, 2024 at 14:57
  • If let's say we have at block 10 and if this block is finalised then i need to find the list of validators who approve this 10th block. Commented Feb 1, 2024 at 16:23

2 Answers 2

2

In polkadot the author index should be found in the digest like you can see this code in BABE:

impl<T: Config> FindAuthor<u32> for Pallet<T> { fn find_author<'a, I>(digests: I) -> Option<u32> where I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>, { for (id, mut data) in digests.into_iter() { if id == BABE_ENGINE_ID { let pre_digest: PreDigest = PreDigest::decode(&mut data).ok()?; return Some(pre_digest.authority_index()) } } None } } 

Then authority index is the index of the author in the validator set. The validator set can be found in the storage of the session pallet. The storage is Validators in the pallet session.

For inspiration you can this code in session:

impl<T: Config, Inner: FindAuthor<u32>> FindAuthor<T::ValidatorId> for FindAccountFromAuthorIndex<T, Inner> { fn find_author<'a, I>(digests: I) -> Option<T::ValidatorId> where I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>, { let i = Inner::find_author(digests)?; let validators = <Pallet<T>>::validators(); validators.get(i as usize).cloned() } } 

That said maybe tools have function implemented already to get it more easily.

2
  • How to get these validators data in a pallet? Commented Feb 2, 2024 at 7:36
  • One solution is to add a new associated type in the config trait of the pallet and bound the trait FindAuthor. The trait FindAuthor is implemented inside the pallet session onto some structure. When user will configure its runtime he will put the correct type in the configuration of the pallet. Commented Feb 3, 2024 at 8:43
0

If you want to know the list of active validators, I can see this on Polkadot.js under developer -> chain state -> storage -> session -> validators(). It also looks like you can provide a block hash to query the chain as of a specific block.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.