-
Notifications
You must be signed in to change notification settings - Fork 2.7k
PreRuntime Digests: Extract authorship information on the runtime side #2918
Description
cc @demimarie-parity @thiolliere
In #2466 we introduced the concept of inherent or PreRuntime digests that are set by the authorship pipeline and include more data in the block header. These are passed to the runtime but is currently ignored. Typically, these will contain consensus-engine specific information that can be used to identify the block author.
We want to extract this information in the runtime for 3 reasons:
- rewarding of block authors and uncle authors
- noting block/uncle authors online
- making authorship information available to other runtime modules.
The format of these digests is PreRuntime(ConsensusEngineId, Vec<u8>).
The simplest way to get this information into the runtime modules is to have on_initialize take a new parameter impl Iterator<Item=&(ConsensusEngineId, Vec<u8>)> which will contain all the pre-runtime digests.
BABE for instance will take the first item with engine_id == BABE_ID and attempt to decode as its own digest type. Then invoke some Authorship::note_author(the_author_from_the_digest) trait.
For uncles, we'll probably want to have a trait for something like FindAuthor (which the on_initialize implementation can share code with).
trait FindAuthor { fn find_author(impl Iterator<Item=(...)>) -> Option<SessionKey> }BABE, Aura, PoW, etc. can all implement this function and it will be invoked using the PreRuntime digests of any uncles.
One alternative is to also use FindAuthor to have the authorship module pull the current block's author from the consensus engine, rather than have consensus engines push it themselves in on_initialize. Then the on_initialize function doesn't need the extra parameter. FindAuthor would probably live in srml-support.