Skip to main content

jam_std_common/
finality.rs

1use codec::{Decode, Encode, MaxEncodedLen};
2use core::fmt;
3use jam_types::{HeaderHash, Slot, StateRootHash};
4
5/// Target for GRANDPA votes and hence what is finalized. Header hash together with the posterior
6/// state root hash.
7#[derive(
8	Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode, MaxEncodedLen,
9)]
10pub struct GrandpaTarget {
11	/// Hash of the block header.
12	pub hash: HeaderHash,
13	/// Posterior state root hash of the block.
14	pub state_root: StateRootHash,
15}
16
17impl GrandpaTarget {
18	pub fn new(hash: HeaderHash, state_root: StateRootHash) -> Self {
19		GrandpaTarget { hash, state_root }
20	}
21}
22
23impl fmt::Display for GrandpaTarget {
24	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25		write!(f, "{} (state root {})", self.hash, self.state_root)
26	}
27}
28
29/// Identifier of a GRANDPA set of authorities. Although it is similar to EpochIndex it is not
30/// the same. GrandpaSetId starts at 0 at genesis and increments for every set change. This will
31/// normally happen at epoch changes but is not quaranteed to. EpochIndex is a function of time
32/// since JAM common era, hence they might be skipped (eg, after genesis or if the network is down)
33/// but GRANDPA sets are never skipped. They are always incremental from the previous set.
34pub type GrandpaSetId = u32;
35
36/// The round indicator.
37pub type GrandpaRoundNumber = u64;
38
39#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)]
40pub enum GrandpaMessage {
41	#[codec(index = 0)]
42	Prevote(GrandpaTarget, Slot),
43	#[codec(index = 1)]
44	Precommit(GrandpaTarget, Slot),
45	#[codec(index = 2)]
46	PrimaryPropose(GrandpaTarget, Slot),
47}