[][src]Crate sc_finality_grandpa

Integration of the GRANDPA finality gadget into substrate.

This crate is unstable and the API and usage may change.

This crate provides a long-running future that produces finality notifications.


First, create a block-import wrapper with the block_import function. The GRANDPA worker needs to be linked together with this block import object, so a LinkHalf is returned as well. All blocks imported (from network or consensus or otherwise) must pass through this wrapper, otherwise consensus is likely to break in unexpected ways.

Next, use the LinkHalf and a local configuration to run_grandpa_voter. This requires a Network implementation. The returned future should be driven to completion and will finalize blocks in the background.

Changing authority sets

The rough idea behind changing authority sets in GRANDPA is that at some point, we obtain agreement for some maximum block height that the current set can finalize, and once a block with that height is finalized the next set will pick up finalization from there.

Technically speaking, this would be implemented as a voting rule which says, "if there is a signal for a change in N blocks in block B, only vote on chains with length NUM(B) + N if they contain B". This conditional-inclusion logic is complex to compute because it requires looking arbitrarily far back in the chain.

Instead, we keep track of a list of all signals we've seen so far (across all forks), sorted ascending by the block number they would be applied at. We never vote on chains with number higher than the earliest handoff block number (this is num(signal) + N). When finalizing a block, we either apply or prune any signaled changes based on whether the signaling block is included in the newly-finalized chain.



A custom voting rule that guarantees that our vote is always behind the best block, in the best case exactly one block behind it.


Configuration for the GRANDPA service.


Finality proof provider for serving network requests.


A GRANDPA justification for block finality, it includes a commit message and an ancestry proof including all headers routing all precommit target blocks to the commit target block. Due to the current voting strategy the precommit targets should be the same as the commit target, since honest voters don't vote past authority set change blocks.


Parameters used to run Grandpa.


A scheduled change of authority set.


A custom voting rule that limits votes towards 3/4 of the unfinalized chain, using the given base and best_target to figure where the 3/4 target should fall.


A builder of a composite voting rule that applies a set of rules to progressively restrict the vote.



Errors that can occur while voting in GRANDPA.



A trait that includes all the client functionalities grandpa requires. Ideally this would be a trait alias, we're not there yet. tracking issue https://github.com/rust-lang/rust/issues/41517


Provider for the Grandpa authority set configured on the genesis block.


Trait that combines StorageProvider and ProofProvider


A trait for custom voting rules in GRANDPA.



Make block importer and link half necessary to tie the background voter to it.


Make block importer and link half necessary to tie the background voter to it. A vector of authority set hard forks can be passed, any authority set change signaled at the given block (either already signalled or in a further block when importing it) will be replaced by a standard change with the given static authorities.


Create light block importer.


Run a GRANDPA voter as a task. Provide configuration and a link to a block import worker that has already been instantiated with block_import.


When GRANDPA is not initialized we still need to register the finality tracker inherent provider which might be expected by the runtime for block authoring. Additionally, we register a gossip message validator that discards all GRANDPA messages (otherwise, we end up banning nodes that send us a Neighbor message, since there is no registered gossip validator for the engine id defined in the message.)

Type Definitions


Identity of a Grandpa authority.


A catch up message for this chain's block type.


A commit message for this chain's block type.


A compact commit message for this chain's block type.


A GRANDPA message for a substrate chain.


A precommit message for this chain's block type.


A prevote message for this chain's block type.


A primary propose message for this chain's block type.


A signed message.