[][src]Crate srml_consensus

Consensus Module

Overview

The consensus module manages the authority set for the native code. It provides support for reporting offline behavior among validators and logging changes in the validator authority set.

Interface

Dispatchable Functions

Public Functions

Usage

Simple Code Snippet

Set authorities:

<consensus::Module<T>>::set_authorities(&[authority1, authority2])

Log changes in the authorities set:

<consensus::Module<T>>::on_finalize(T::BlockNumber::zero());

Example from SRML

In the staking module, the consensus::OnOfflineReport is implemented to monitor offline reporting among validators:

impl<T: Trait> consensus::OnOfflineReport<Vec<u32>> for Module<T> {
    fn handle_report(reported_indices: Vec<u32>) {
        for validator_index in reported_indices {
            // Get validator from session module
            // Process validator
        }
    }
}

In the GRANDPA module, we use srml-consensus to get the set of next_authorities before changing this set according to the consensus algorithm (which does not rotate sessions in the normal way):

let next_authorities = <consensus::Module<T>>::authorities()
            .into_iter()
            .map(|key| (key, 1)) // evenly-weighted.
            .collect::<Vec<(<T as Trait>::SessionKey, u64)>>();

References

If you're interested in hacking on this module, it is useful to understand the interaction with substrate/core/inherents/src/lib.rs and, specifically, the required implementation of ProvideInherent to create and check inherents.

Structs

GenesisConfig
InstantFinalityReportVec

A variant of the OfflineReport that is useful for instant-finality blocks.

Module

Enums

Call
RawLog

Logs in this module.

Constants

INHERENT_IDENTIFIER

The identifier for consensus inherents.

Traits

InherentOfflineReport

Describes the offline-reporting extrinsic.

OnOfflineReport

Handling offline validator reports in a generic way.

Trait

Type Definitions

InherentError

The error type used by this inherent.

Key
KeyValue
Log