mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
pallet-beefy-mmr: add API for BEEFY Authority Sets (#11406)
* pallet-beefy: add Config::OnNewValidatorSet type Add a hook to pallet-beefy for doing specific work when BEEFY validator set changes. For example, this can be used by pallet-beefy-mmr to cache a lightweight MMR root over validators and make it available to light clients. * pallet-beefy-mmr: implement OnNewValidatorSet Implement pallet-beefy::OnNewValidatorSet to be notified of BEEFY validator set changes. Use the notifications to compute and cache a light weight 'BEEFY authority set' which is an MMR root over BEEFY validator set plus some extra info. Previously, pallet-beefy-mmr was interogating pallet-beefy about validator set id on every block to find out when it needs to recompute the authority set. By using the event-driven approach in this commit, we also save one extra state interogation per block. * pallet-beefy-mmr: add new authority_set() API Expose current and next BEEFY authority sets through runtime API. These can be directly used by light clients to avoid having them compute them themselves based on BEEFY validator sets. Signed-off-by: acatangiu <adrian@parity.io> * rename BeefyMmr exposed runtime api
This commit is contained in:
@@ -154,6 +154,20 @@ pub struct VoteMessage<Number, Id, Signature> {
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
/// New BEEFY validator set notification hook.
|
||||
pub trait OnNewValidatorSet<AuthorityId> {
|
||||
/// Function called by the pallet when BEEFY validator set changes.
|
||||
fn on_new_validator_set(
|
||||
validator_set: &ValidatorSet<AuthorityId>,
|
||||
next_validator_set: &ValidatorSet<AuthorityId>,
|
||||
);
|
||||
}
|
||||
|
||||
/// No-op implementation of [OnNewValidatorSet].
|
||||
impl<AuthorityId> OnNewValidatorSet<AuthorityId> for () {
|
||||
fn on_new_validator_set(_: &ValidatorSet<AuthorityId>, _: &ValidatorSet<AuthorityId>) {}
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// API necessary for BEEFY voters.
|
||||
pub trait BeefyApi
|
||||
|
||||
@@ -95,10 +95,10 @@ impl MmrLeafVersion {
|
||||
}
|
||||
}
|
||||
|
||||
/// Details of the next BEEFY authority set.
|
||||
/// Details of a BEEFY authority set.
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
pub struct BeefyNextAuthoritySet<MerkleRoot> {
|
||||
/// Id of the next set.
|
||||
pub struct BeefyAuthoritySet<MerkleRoot> {
|
||||
/// Id of the set.
|
||||
///
|
||||
/// Id is required to correlate BEEFY signed commitments with the validator set.
|
||||
/// Light Client can easily verify that the commitment witness it is getting is
|
||||
@@ -106,11 +106,11 @@ pub struct BeefyNextAuthoritySet<MerkleRoot> {
|
||||
pub id: crate::ValidatorSetId,
|
||||
/// Number of validators in the set.
|
||||
///
|
||||
/// Some BEEFY Light Clients may use an interactive protocol to verify only subset
|
||||
/// Some BEEFY Light Clients may use an interactive protocol to verify only a subset
|
||||
/// of signatures. We put set length here, so that these clients can verify the minimal
|
||||
/// number of required signatures.
|
||||
pub len: u32,
|
||||
/// Merkle Root Hash build from BEEFY AuthorityIds.
|
||||
/// Merkle Root Hash built from BEEFY AuthorityIds.
|
||||
///
|
||||
/// This is used by Light Clients to confirm that the commitments are signed by the correct
|
||||
/// validator set. Light Clients using interactive protocol, might verify only subset of
|
||||
@@ -118,6 +118,9 @@ pub struct BeefyNextAuthoritySet<MerkleRoot> {
|
||||
pub root: MerkleRoot,
|
||||
}
|
||||
|
||||
/// Details of the next BEEFY authority set.
|
||||
pub type BeefyNextAuthoritySet<MerkleRoot> = BeefyAuthoritySet<MerkleRoot>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user