1

I'm working on pow consensus chain and want to fetch block author in a pallet. I'm following Academy-PoW repo for adding block author through InherentDataProvider. But here default is passed in-place of actual author:

https://github.com/Polkadot-Blockchain-Academy/Academy-PoW/blob/b522da48f928101c1b05060af7efbbe0c71ccc76/node/src/service.rs#L105C1-L107C1

How to add actual author instead of default?

I have tried this process also:

let author = frame_system::Pallet::<T>::digest()
                .logs
                .iter()
                .filter_map(|s| s.as_pre_runtime())
                .filter_map(|(id, mut data)|
                    // if id == POW_ENGINE_ID {
                    T::AccountId::decode(&mut data).ok()
                // } else {
                //  None
                // }
                )
                .next();

But I get author as None.

Can anyone please help to fetch the block author in a pallet?

2 Answers 2

2

Personally I don't understand why they used inherents here instead of using digest.

That said, the code you are pointing to is for generating the inherents for the block to import. Those inherents are usually used for checking the inherents that are inside the block to import, in the implementations of check_inherent.

But the author doesn't have any check_inherent implementation so what the node pass there is not significant as it won't be used to check anything.

In the runtime if you want to get the block author you can use the storage Author in the block_author pallet, it contains the author once the inherent is processed.

Outside the runtime, when generating inherents for a block to import, you can find the block author by inspecting the block and get the first inherent with the call set_author, but the API doesn't let you do this easily.

I might miss something but personally I wouldn't worry to give a default inherent data for the author as it is not used to check anything. And if this looks not good I would try to refactor the code without the use inherents and instead only use digest to pass the block author.

2
  • Thank you so much for your response. What you said, totally make sense. Can you please confirm when you tried to pass the block author from digest? Feb 6 at 14:28
  • To pass the block author from digest you could take inspiration from chains with Babe consensus. in Babe pallet the author index is passed through digest: github.com/paritytech/polkadot-sdk/blob/…
    – gui
    Feb 7 at 1:45
0

Please take a look of this implementation: https://github.com/kulupu/kulupu/blob/d9428305d1155514574df79a4692a48711c2bcb2/src/service.rs#L323C1-L324C1

Here in the service.rs we have passed the author by generating miner id in decode_author function: https://github.com/kulupu/kulupu/blob/d9428305d1155514574df79a4692a48711c2bcb2/src/service.rs#L61C1-L107C1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.