mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 20:45:40 +00:00
Removed pallet::getter usage from Beefy and MMR pallets (#3740)
Part of #3326 cc @kianenigma @ggwpez @liamaharon polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: Matteo Muraca <mmuraca247@gmail.com>
This commit is contained in:
@@ -1991,7 +1991,7 @@ sp_api::impl_runtime_apis! {
|
|||||||
#[api_version(3)]
|
#[api_version(3)]
|
||||||
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
|
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
|
||||||
fn beefy_genesis() -> Option<BlockNumber> {
|
fn beefy_genesis() -> Option<BlockNumber> {
|
||||||
Beefy::genesis_block()
|
pallet_beefy::GenesisBlock::<Runtime>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validator_set() -> Option<beefy_primitives::ValidatorSet<BeefyId>> {
|
fn validator_set() -> Option<beefy_primitives::ValidatorSet<BeefyId>> {
|
||||||
@@ -2029,11 +2029,11 @@ sp_api::impl_runtime_apis! {
|
|||||||
#[api_version(2)]
|
#[api_version(2)]
|
||||||
impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
|
impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
|
||||||
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
||||||
Ok(Mmr::mmr_root())
|
Ok(pallet_mmr::RootHash::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
||||||
Ok(Mmr::mmr_leaves())
|
Ok(pallet_mmr::NumberOfLeaves::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_proof(
|
fn generate_proof(
|
||||||
|
|||||||
@@ -2015,7 +2015,7 @@ sp_api::impl_runtime_apis! {
|
|||||||
|
|
||||||
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
|
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
|
||||||
fn beefy_genesis() -> Option<BlockNumber> {
|
fn beefy_genesis() -> Option<BlockNumber> {
|
||||||
Beefy::genesis_block()
|
pallet_beefy::GenesisBlock::<Runtime>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validator_set() -> Option<beefy_primitives::ValidatorSet<BeefyId>> {
|
fn validator_set() -> Option<beefy_primitives::ValidatorSet<BeefyId>> {
|
||||||
@@ -2052,11 +2052,11 @@ sp_api::impl_runtime_apis! {
|
|||||||
|
|
||||||
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||||
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
||||||
Ok(Mmr::mmr_root())
|
Ok(pallet_mmr::RootHash::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
||||||
Ok(Mmr::mmr_leaves())
|
Ok(pallet_mmr::NumberOfLeaves::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_proof(
|
fn generate_proof(
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
|
||||||
|
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
|
||||||
|
|
||||||
|
title: Removed `pallet::getter` usage from Beefy and MMR pallets
|
||||||
|
|
||||||
|
doc:
|
||||||
|
- audience: Runtime Dev
|
||||||
|
description: |
|
||||||
|
This PR removes `pallet::getter` usage from `pallet-beefy`, `pallet-beefy-mmr` and `pallet-mmr`, and updates dependant code and runtimes accordingly.
|
||||||
|
The syntax `StorageItem::<T, I>::get()` should be used instead.
|
||||||
|
|
||||||
|
crates:
|
||||||
|
- name: pallet-beefy
|
||||||
|
- name: pallet-beefy-mmr
|
||||||
|
- name: pallet-mmr
|
||||||
|
- name: kitchensink-runtime
|
||||||
|
- name: rococo-runtime
|
||||||
|
- name: westend-runtime
|
||||||
@@ -2979,7 +2979,7 @@ impl_runtime_apis! {
|
|||||||
#[api_version(3)]
|
#[api_version(3)]
|
||||||
impl sp_consensus_beefy::BeefyApi<Block, BeefyId> for Runtime {
|
impl sp_consensus_beefy::BeefyApi<Block, BeefyId> for Runtime {
|
||||||
fn beefy_genesis() -> Option<BlockNumber> {
|
fn beefy_genesis() -> Option<BlockNumber> {
|
||||||
Beefy::genesis_block()
|
pallet_beefy::GenesisBlock::<Runtime>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validator_set() -> Option<sp_consensus_beefy::ValidatorSet<BeefyId>> {
|
fn validator_set() -> Option<sp_consensus_beefy::ValidatorSet<BeefyId>> {
|
||||||
@@ -3018,11 +3018,11 @@ impl_runtime_apis! {
|
|||||||
BlockNumber,
|
BlockNumber,
|
||||||
> for Runtime {
|
> for Runtime {
|
||||||
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
||||||
Ok(Mmr::mmr_root())
|
Ok(pallet_mmr::RootHash::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
||||||
Ok(Mmr::mmr_leaves())
|
Ok(pallet_mmr::NumberOfLeaves::<Runtime>::get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_proof(
|
fn generate_proof(
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ where
|
|||||||
<T as pallet_beefy::Config>::BeefyId,
|
<T as pallet_beefy::Config>::BeefyId,
|
||||||
>::MmrRoot(*root)),
|
>::MmrRoot(*root)),
|
||||||
);
|
);
|
||||||
<frame_system::Pallet<T>>::deposit_log(digest);
|
frame_system::Pallet::<T>::deposit_log(digest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,6 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// Details of current BEEFY authority set.
|
/// Details of current BEEFY authority set.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn beefy_authorities)]
|
|
||||||
pub type BeefyAuthorities<T: Config> =
|
pub type BeefyAuthorities<T: Config> =
|
||||||
StorageValue<_, BeefyAuthoritySet<MerkleRootOf<T>>, ValueQuery>;
|
StorageValue<_, BeefyAuthoritySet<MerkleRootOf<T>>, ValueQuery>;
|
||||||
|
|
||||||
@@ -134,7 +133,6 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// This storage entry is used as cache for calls to `update_beefy_next_authority_set`.
|
/// This storage entry is used as cache for calls to `update_beefy_next_authority_set`.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn beefy_next_authorities)]
|
|
||||||
pub type BeefyNextAuthorities<T: Config> =
|
pub type BeefyNextAuthorities<T: Config> =
|
||||||
StorageValue<_, BeefyNextAuthoritySet<MerkleRootOf<T>>, ValueQuery>;
|
StorageValue<_, BeefyNextAuthoritySet<MerkleRootOf<T>>, ValueQuery>;
|
||||||
}
|
}
|
||||||
@@ -152,7 +150,7 @@ impl<T: Config> LeafDataProvider for Pallet<T> {
|
|||||||
version: T::LeafVersion::get(),
|
version: T::LeafVersion::get(),
|
||||||
parent_number_and_hash: ParentNumberAndHash::<T>::leaf_data(),
|
parent_number_and_hash: ParentNumberAndHash::<T>::leaf_data(),
|
||||||
leaf_extra: T::BeefyDataProvider::extra_data(),
|
leaf_extra: T::BeefyDataProvider::extra_data(),
|
||||||
beefy_next_authority_set: Pallet::<T>::beefy_next_authorities(),
|
beefy_next_authority_set: BeefyNextAuthorities::<T>::get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,12 +175,12 @@ where
|
|||||||
impl<T: Config> Pallet<T> {
|
impl<T: Config> Pallet<T> {
|
||||||
/// Return the currently active BEEFY authority set proof.
|
/// Return the currently active BEEFY authority set proof.
|
||||||
pub fn authority_set_proof() -> BeefyAuthoritySet<MerkleRootOf<T>> {
|
pub fn authority_set_proof() -> BeefyAuthoritySet<MerkleRootOf<T>> {
|
||||||
Pallet::<T>::beefy_authorities()
|
BeefyAuthorities::<T>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the next/queued BEEFY authority set proof.
|
/// Return the next/queued BEEFY authority set proof.
|
||||||
pub fn next_authority_set_proof() -> BeefyNextAuthoritySet<MerkleRootOf<T>> {
|
pub fn next_authority_set_proof() -> BeefyNextAuthoritySet<MerkleRootOf<T>> {
|
||||||
Pallet::<T>::beefy_next_authorities()
|
BeefyNextAuthorities::<T>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns details of a BEEFY authority set.
|
/// Returns details of a BEEFY authority set.
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ fn should_contain_valid_leaf_data() {
|
|||||||
let mut ext = new_test_ext(vec![1, 2, 3, 4]);
|
let mut ext = new_test_ext(vec![1, 2, 3, 4]);
|
||||||
let parent_hash = ext.execute_with(|| {
|
let parent_hash = ext.execute_with(|| {
|
||||||
init_block(1);
|
init_block(1);
|
||||||
<frame_system::Pallet<Test>>::parent_hash()
|
frame_system::Pallet::<Test>::parent_hash()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(0, parent_hash));
|
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(0, parent_hash));
|
||||||
@@ -132,7 +132,7 @@ fn should_contain_valid_leaf_data() {
|
|||||||
// build second block on top
|
// build second block on top
|
||||||
let parent_hash = ext.execute_with(|| {
|
let parent_hash = ext.execute_with(|| {
|
||||||
init_block(2);
|
init_block(2);
|
||||||
<frame_system::Pallet<Test>>::parent_hash()
|
frame_system::Pallet::<Test>::parent_hash()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(1, parent_hash));
|
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(1, parent_hash));
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ where
|
|||||||
evidence: EquivocationEvidenceFor<T>,
|
evidence: EquivocationEvidenceFor<T>,
|
||||||
) -> Result<(), DispatchError> {
|
) -> Result<(), DispatchError> {
|
||||||
let (equivocation_proof, key_owner_proof) = evidence;
|
let (equivocation_proof, key_owner_proof) = evidence;
|
||||||
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());
|
let reporter = reporter.or_else(|| pallet_authorship::Pallet::<T>::author());
|
||||||
let offender = equivocation_proof.offender_id().clone();
|
let offender = equivocation_proof.offender_id().clone();
|
||||||
|
|
||||||
// We check the equivocation within the context of its set id (and
|
// We check the equivocation within the context of its set id (and
|
||||||
|
|||||||
@@ -120,20 +120,17 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// The current authorities set
|
/// The current authorities set
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn authorities)]
|
pub type Authorities<T: Config> =
|
||||||
pub(super) type Authorities<T: Config> =
|
|
||||||
StorageValue<_, BoundedVec<T::BeefyId, T::MaxAuthorities>, ValueQuery>;
|
StorageValue<_, BoundedVec<T::BeefyId, T::MaxAuthorities>, ValueQuery>;
|
||||||
|
|
||||||
/// The current validator set id
|
/// The current validator set id
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn validator_set_id)]
|
pub type ValidatorSetId<T: Config> =
|
||||||
pub(super) type ValidatorSetId<T: Config> =
|
|
||||||
StorageValue<_, sp_consensus_beefy::ValidatorSetId, ValueQuery>;
|
StorageValue<_, sp_consensus_beefy::ValidatorSetId, ValueQuery>;
|
||||||
|
|
||||||
/// Authorities set scheduled to be used with the next session
|
/// Authorities set scheduled to be used with the next session
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn next_authorities)]
|
pub type NextAuthorities<T: Config> =
|
||||||
pub(super) type NextAuthorities<T: Config> =
|
|
||||||
StorageValue<_, BoundedVec<T::BeefyId, T::MaxAuthorities>, ValueQuery>;
|
StorageValue<_, BoundedVec<T::BeefyId, T::MaxAuthorities>, ValueQuery>;
|
||||||
|
|
||||||
/// A mapping from BEEFY set ID to the index of the *most recent* session for which its
|
/// A mapping from BEEFY set ID to the index of the *most recent* session for which its
|
||||||
@@ -147,17 +144,14 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// TWOX-NOTE: `ValidatorSetId` is not under user control.
|
/// TWOX-NOTE: `ValidatorSetId` is not under user control.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn session_for_set)]
|
pub type SetIdSession<T: Config> =
|
||||||
pub(super) type SetIdSession<T: Config> =
|
|
||||||
StorageMap<_, Twox64Concat, sp_consensus_beefy::ValidatorSetId, SessionIndex>;
|
StorageMap<_, Twox64Concat, sp_consensus_beefy::ValidatorSetId, SessionIndex>;
|
||||||
|
|
||||||
/// Block number where BEEFY consensus is enabled/started.
|
/// Block number where BEEFY consensus is enabled/started.
|
||||||
/// By changing this (through privileged `set_new_genesis()`), BEEFY consensus is effectively
|
/// By changing this (through privileged `set_new_genesis()`), BEEFY consensus is effectively
|
||||||
/// restarted from the newly set block number.
|
/// restarted from the newly set block number.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn genesis_block)]
|
pub type GenesisBlock<T: Config> = StorageValue<_, Option<BlockNumberFor<T>>, ValueQuery>;
|
||||||
pub(super) type GenesisBlock<T: Config> =
|
|
||||||
StorageValue<_, Option<BlockNumberFor<T>>, ValueQuery>;
|
|
||||||
|
|
||||||
#[pallet::genesis_config]
|
#[pallet::genesis_config]
|
||||||
pub struct GenesisConfig<T: Config> {
|
pub struct GenesisConfig<T: Config> {
|
||||||
@@ -186,7 +180,7 @@ pub mod pallet {
|
|||||||
// we panic here as runtime maintainers can simply reconfigure genesis and restart
|
// we panic here as runtime maintainers can simply reconfigure genesis and restart
|
||||||
// the chain easily
|
// the chain easily
|
||||||
.expect("Authorities vec too big");
|
.expect("Authorities vec too big");
|
||||||
<GenesisBlock<T>>::put(&self.genesis_block);
|
GenesisBlock::<T>::put(&self.genesis_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,8 +297,8 @@ pub mod pallet {
|
|||||||
impl<T: Config> Pallet<T> {
|
impl<T: Config> Pallet<T> {
|
||||||
/// Return the current active BEEFY validator set.
|
/// Return the current active BEEFY validator set.
|
||||||
pub fn validator_set() -> Option<ValidatorSet<T::BeefyId>> {
|
pub fn validator_set() -> Option<ValidatorSet<T::BeefyId>> {
|
||||||
let validators: BoundedVec<T::BeefyId, T::MaxAuthorities> = Self::authorities();
|
let validators: BoundedVec<T::BeefyId, T::MaxAuthorities> = Authorities::<T>::get();
|
||||||
let id: sp_consensus_beefy::ValidatorSetId = Self::validator_set_id();
|
let id: sp_consensus_beefy::ValidatorSetId = ValidatorSetId::<T>::get();
|
||||||
ValidatorSet::<T::BeefyId>::new(validators, id)
|
ValidatorSet::<T::BeefyId>::new(validators, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,19 +320,19 @@ impl<T: Config> Pallet<T> {
|
|||||||
new: BoundedVec<T::BeefyId, T::MaxAuthorities>,
|
new: BoundedVec<T::BeefyId, T::MaxAuthorities>,
|
||||||
queued: BoundedVec<T::BeefyId, T::MaxAuthorities>,
|
queued: BoundedVec<T::BeefyId, T::MaxAuthorities>,
|
||||||
) {
|
) {
|
||||||
<Authorities<T>>::put(&new);
|
Authorities::<T>::put(&new);
|
||||||
|
|
||||||
let new_id = Self::validator_set_id() + 1u64;
|
let new_id = ValidatorSetId::<T>::get() + 1u64;
|
||||||
<ValidatorSetId<T>>::put(new_id);
|
ValidatorSetId::<T>::put(new_id);
|
||||||
|
|
||||||
<NextAuthorities<T>>::put(&queued);
|
NextAuthorities::<T>::put(&queued);
|
||||||
|
|
||||||
if let Some(validator_set) = ValidatorSet::<T::BeefyId>::new(new, new_id) {
|
if let Some(validator_set) = ValidatorSet::<T::BeefyId>::new(new, new_id) {
|
||||||
let log = DigestItem::Consensus(
|
let log = DigestItem::Consensus(
|
||||||
BEEFY_ENGINE_ID,
|
BEEFY_ENGINE_ID,
|
||||||
ConsensusLog::AuthoritiesChange(validator_set.clone()).encode(),
|
ConsensusLog::AuthoritiesChange(validator_set.clone()).encode(),
|
||||||
);
|
);
|
||||||
<frame_system::Pallet<T>>::deposit_log(log);
|
frame_system::Pallet::<T>::deposit_log(log);
|
||||||
|
|
||||||
let next_id = new_id + 1;
|
let next_id = new_id + 1;
|
||||||
if let Some(next_validator_set) = ValidatorSet::<T::BeefyId>::new(queued, next_id) {
|
if let Some(next_validator_set) = ValidatorSet::<T::BeefyId>::new(queued, next_id) {
|
||||||
@@ -355,7 +349,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !<Authorities<T>>::get().is_empty() {
|
if !Authorities::<T>::get().is_empty() {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,10 +358,10 @@ impl<T: Config> Pallet<T> {
|
|||||||
.map_err(|_| ())?;
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
let id = GENESIS_AUTHORITY_SET_ID;
|
let id = GENESIS_AUTHORITY_SET_ID;
|
||||||
<Authorities<T>>::put(bounded_authorities);
|
Authorities::<T>::put(bounded_authorities);
|
||||||
<ValidatorSetId<T>>::put(id);
|
ValidatorSetId::<T>::put(id);
|
||||||
// Like `pallet_session`, initialize the next validator set as well.
|
// Like `pallet_session`, initialize the next validator set as well.
|
||||||
<NextAuthorities<T>>::put(bounded_authorities);
|
NextAuthorities::<T>::put(bounded_authorities);
|
||||||
|
|
||||||
if let Some(validator_set) = ValidatorSet::<T::BeefyId>::new(authorities.clone(), id) {
|
if let Some(validator_set) = ValidatorSet::<T::BeefyId>::new(authorities.clone(), id) {
|
||||||
let next_id = id + 1;
|
let next_id = id + 1;
|
||||||
@@ -442,9 +436,9 @@ where
|
|||||||
// We want to have at least one BEEFY mandatory block per session.
|
// We want to have at least one BEEFY mandatory block per session.
|
||||||
Self::change_authorities(bounded_next_authorities, bounded_next_queued_authorities);
|
Self::change_authorities(bounded_next_authorities, bounded_next_queued_authorities);
|
||||||
|
|
||||||
let validator_set_id = Self::validator_set_id();
|
let validator_set_id = ValidatorSetId::<T>::get();
|
||||||
// Update the mapping for the new set id that corresponds to the latest session (i.e. now).
|
// Update the mapping for the new set id that corresponds to the latest session (i.e. now).
|
||||||
let session_index = <pallet_session::Pallet<T>>::current_index();
|
let session_index = pallet_session::Pallet::<T>::current_index();
|
||||||
SetIdSession::<T>::insert(validator_set_id, &session_index);
|
SetIdSession::<T>::insert(validator_set_id, &session_index);
|
||||||
// Prune old entry if limit reached.
|
// Prune old entry if limit reached.
|
||||||
let max_set_id_session_entries = T::MaxSetIdSessionEntries::get().max(1);
|
let max_set_id_session_entries = T::MaxSetIdSessionEntries::get().max(1);
|
||||||
@@ -459,13 +453,13 @@ where
|
|||||||
ConsensusLog::<T::BeefyId>::OnDisabled(i as AuthorityIndex).encode(),
|
ConsensusLog::<T::BeefyId>::OnDisabled(i as AuthorityIndex).encode(),
|
||||||
);
|
);
|
||||||
|
|
||||||
<frame_system::Pallet<T>>::deposit_log(log);
|
frame_system::Pallet::<T>::deposit_log(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Config> IsMember<T::BeefyId> for Pallet<T> {
|
impl<T: Config> IsMember<T::BeefyId> for Pallet<T> {
|
||||||
fn is_member(authority_id: &T::BeefyId) -> bool {
|
fn is_member(authority_id: &T::BeefyId) -> bool {
|
||||||
Self::authorities().iter().any(|id| id == authority_id)
|
Authorities::<T>::get().iter().any(|id| id == authority_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use sp_consensus_beefy::{
|
|||||||
};
|
};
|
||||||
use sp_runtime::DigestItem;
|
use sp_runtime::DigestItem;
|
||||||
|
|
||||||
use crate::{mock::*, Call, Config, Error, Weight, WeightInfo};
|
use crate::{self as beefy, mock::*, Call, Config, Error, Weight, WeightInfo};
|
||||||
|
|
||||||
fn init_block(block: u64) {
|
fn init_block(block: u64) {
|
||||||
System::set_block_number(block);
|
System::set_block_number(block);
|
||||||
@@ -48,15 +48,15 @@ fn genesis_session_initializes_authorities() {
|
|||||||
let want = authorities.clone();
|
let want = authorities.clone();
|
||||||
|
|
||||||
new_test_ext_raw_authorities(authorities).execute_with(|| {
|
new_test_ext_raw_authorities(authorities).execute_with(|| {
|
||||||
let authorities = Beefy::authorities();
|
let authorities = beefy::Authorities::<Test>::get();
|
||||||
|
|
||||||
assert_eq!(authorities.len(), 4);
|
assert_eq!(authorities.len(), 4);
|
||||||
assert_eq!(want[0], authorities[0]);
|
assert_eq!(want[0], authorities[0]);
|
||||||
assert_eq!(want[1], authorities[1]);
|
assert_eq!(want[1], authorities[1]);
|
||||||
|
|
||||||
assert!(Beefy::validator_set_id() == 0);
|
assert!(beefy::ValidatorSetId::<Test>::get() == 0);
|
||||||
|
|
||||||
let next_authorities = Beefy::next_authorities();
|
let next_authorities = beefy::NextAuthorities::<Test>::get();
|
||||||
|
|
||||||
assert_eq!(next_authorities.len(), 4);
|
assert_eq!(next_authorities.len(), 4);
|
||||||
assert_eq!(want[0], next_authorities[0]);
|
assert_eq!(want[0], next_authorities[0]);
|
||||||
@@ -70,11 +70,11 @@ fn session_change_updates_authorities() {
|
|||||||
let want_validators = authorities.clone();
|
let want_validators = authorities.clone();
|
||||||
|
|
||||||
new_test_ext(vec![1, 2, 3, 4]).execute_with(|| {
|
new_test_ext(vec![1, 2, 3, 4]).execute_with(|| {
|
||||||
assert!(0 == Beefy::validator_set_id());
|
assert!(0 == beefy::ValidatorSetId::<Test>::get());
|
||||||
|
|
||||||
init_block(1);
|
init_block(1);
|
||||||
|
|
||||||
assert!(1 == Beefy::validator_set_id());
|
assert!(1 == beefy::ValidatorSetId::<Test>::get());
|
||||||
|
|
||||||
let want = beefy_log(ConsensusLog::AuthoritiesChange(
|
let want = beefy_log(ConsensusLog::AuthoritiesChange(
|
||||||
ValidatorSet::new(want_validators, 1).unwrap(),
|
ValidatorSet::new(want_validators, 1).unwrap(),
|
||||||
@@ -85,7 +85,7 @@ fn session_change_updates_authorities() {
|
|||||||
|
|
||||||
init_block(2);
|
init_block(2);
|
||||||
|
|
||||||
assert!(2 == Beefy::validator_set_id());
|
assert!(2 == beefy::ValidatorSetId::<Test>::get());
|
||||||
|
|
||||||
let want = beefy_log(ConsensusLog::AuthoritiesChange(
|
let want = beefy_log(ConsensusLog::AuthoritiesChange(
|
||||||
ValidatorSet::new(vec![mock_beefy_id(2), mock_beefy_id(4)], 2).unwrap(),
|
ValidatorSet::new(vec![mock_beefy_id(2), mock_beefy_id(4)], 2).unwrap(),
|
||||||
@@ -101,7 +101,7 @@ fn session_change_updates_next_authorities() {
|
|||||||
let want = vec![mock_beefy_id(1), mock_beefy_id(2), mock_beefy_id(3), mock_beefy_id(4)];
|
let want = vec![mock_beefy_id(1), mock_beefy_id(2), mock_beefy_id(3), mock_beefy_id(4)];
|
||||||
|
|
||||||
new_test_ext(vec![1, 2, 3, 4]).execute_with(|| {
|
new_test_ext(vec![1, 2, 3, 4]).execute_with(|| {
|
||||||
let next_authorities = Beefy::next_authorities();
|
let next_authorities = beefy::NextAuthorities::<Test>::get();
|
||||||
|
|
||||||
assert_eq!(next_authorities.len(), 4);
|
assert_eq!(next_authorities.len(), 4);
|
||||||
assert_eq!(want[0], next_authorities[0]);
|
assert_eq!(want[0], next_authorities[0]);
|
||||||
@@ -111,7 +111,7 @@ fn session_change_updates_next_authorities() {
|
|||||||
|
|
||||||
init_block(1);
|
init_block(1);
|
||||||
|
|
||||||
let next_authorities = Beefy::next_authorities();
|
let next_authorities = beefy::NextAuthorities::<Test>::get();
|
||||||
|
|
||||||
assert_eq!(next_authorities.len(), 2);
|
assert_eq!(next_authorities.len(), 2);
|
||||||
assert_eq!(want[1], next_authorities[0]);
|
assert_eq!(want[1], next_authorities[0]);
|
||||||
@@ -177,7 +177,7 @@ fn cleans_up_old_set_id_session_mappings() {
|
|||||||
// we should have a session id mapping for all the set ids from
|
// we should have a session id mapping for all the set ids from
|
||||||
// `max_set_id_session_entries` eras we have observed
|
// `max_set_id_session_entries` eras we have observed
|
||||||
for i in 1..=max_set_id_session_entries {
|
for i in 1..=max_set_id_session_entries {
|
||||||
assert!(Beefy::session_for_set(i as u64).is_some());
|
assert!(beefy::SetIdSession::<Test>::get(i as u64).is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
// go through another `max_set_id_session_entries` sessions
|
// go through another `max_set_id_session_entries` sessions
|
||||||
@@ -185,12 +185,12 @@ fn cleans_up_old_set_id_session_mappings() {
|
|||||||
|
|
||||||
// we should keep tracking the new mappings for new sessions
|
// we should keep tracking the new mappings for new sessions
|
||||||
for i in max_set_id_session_entries + 1..=max_set_id_session_entries * 2 {
|
for i in max_set_id_session_entries + 1..=max_set_id_session_entries * 2 {
|
||||||
assert!(Beefy::session_for_set(i as u64).is_some());
|
assert!(beefy::SetIdSession::<Test>::get(i as u64).is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
// but the old ones should have been pruned by now
|
// but the old ones should have been pruned by now
|
||||||
for i in 1..=max_set_id_session_entries {
|
for i in 1..=max_set_id_session_entries {
|
||||||
assert!(Beefy::session_for_set(i as u64).is_none());
|
assert!(beefy::SetIdSession::<Test>::get(i as u64).is_none());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -804,7 +804,7 @@ fn set_new_genesis_works() {
|
|||||||
assert_ok!(Beefy::set_new_genesis(RuntimeOrigin::root(), new_genesis_delay,));
|
assert_ok!(Beefy::set_new_genesis(RuntimeOrigin::root(), new_genesis_delay,));
|
||||||
let expected = System::block_number() + new_genesis_delay;
|
let expected = System::block_number() + new_genesis_delay;
|
||||||
// verify new genesis was set
|
// verify new genesis was set
|
||||||
assert_eq!(Beefy::genesis_block(), Some(expected));
|
assert_eq!(beefy::GenesisBlock::<Test>::get(), Some(expected));
|
||||||
|
|
||||||
// setting delay < 1 should fail
|
// setting delay < 1 should fail
|
||||||
assert_err!(
|
assert_err!(
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// Latest MMR Root hash.
|
/// Latest MMR Root hash.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn mmr_root_hash)]
|
|
||||||
pub type RootHash<T: Config<I>, I: 'static = ()> = StorageValue<_, HashOf<T, I>, ValueQuery>;
|
pub type RootHash<T: Config<I>, I: 'static = ()> = StorageValue<_, HashOf<T, I>, ValueQuery>;
|
||||||
|
|
||||||
/// Current size of the MMR (number of leaves).
|
/// Current size of the MMR (number of leaves).
|
||||||
@@ -204,7 +203,7 @@ pub mod pallet {
|
|||||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
||||||
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
||||||
use primitives::LeafDataProvider;
|
use primitives::LeafDataProvider;
|
||||||
let leaves = Self::mmr_leaves();
|
let leaves = NumberOfLeaves::<T, I>::get();
|
||||||
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
||||||
let data = T::LeafData::leaf_data();
|
let data = T::LeafData::leaf_data();
|
||||||
|
|
||||||
@@ -225,8 +224,8 @@ pub mod pallet {
|
|||||||
};
|
};
|
||||||
<T::OnNewRoot as primitives::OnNewRoot<_>>::on_new_root(&root);
|
<T::OnNewRoot as primitives::OnNewRoot<_>>::on_new_root(&root);
|
||||||
|
|
||||||
<NumberOfLeaves<T, I>>::put(leaves);
|
NumberOfLeaves::<T, I>::put(leaves);
|
||||||
<RootHash<T, I>>::put(root);
|
RootHash::<T, I>::put(root);
|
||||||
|
|
||||||
let peaks_after = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
let peaks_after = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
||||||
|
|
||||||
@@ -301,7 +300,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
|||||||
{
|
{
|
||||||
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
|
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
|
||||||
<frame_system::Pallet<T>>::block_number(),
|
<frame_system::Pallet<T>>::block_number(),
|
||||||
Self::mmr_leaves(),
|
NumberOfLeaves::<T, I>::get(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
utils::block_num_to_leaf_index::<HeaderFor<T>>(block_num, first_mmr_block)
|
utils::block_num_to_leaf_index::<HeaderFor<T>>(block_num, first_mmr_block)
|
||||||
@@ -341,7 +340,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
|||||||
|
|
||||||
/// Return the on-chain MMR root hash.
|
/// Return the on-chain MMR root hash.
|
||||||
pub fn mmr_root() -> HashOf<T, I> {
|
pub fn mmr_root() -> HashOf<T, I> {
|
||||||
Self::mmr_root_hash()
|
RootHash::<T, I>::get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify MMR proof for given `leaves`.
|
/// Verify MMR proof for given `leaves`.
|
||||||
@@ -354,7 +353,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
|||||||
leaves: Vec<LeafOf<T, I>>,
|
leaves: Vec<LeafOf<T, I>>,
|
||||||
proof: primitives::Proof<HashOf<T, I>>,
|
proof: primitives::Proof<HashOf<T, I>>,
|
||||||
) -> Result<(), primitives::Error> {
|
) -> Result<(), primitives::Error> {
|
||||||
if proof.leaf_count > Self::mmr_leaves() ||
|
if proof.leaf_count > NumberOfLeaves::<T, I>::get() ||
|
||||||
proof.leaf_count == 0 ||
|
proof.leaf_count == 0 ||
|
||||||
(proof.items.len().saturating_add(leaves.len())) as u64 > proof.leaf_count
|
(proof.items.len().saturating_add(leaves.len())) as u64 > proof.leaf_count
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ where
|
|||||||
L: primitives::FullLeaf,
|
L: primitives::FullLeaf,
|
||||||
{
|
{
|
||||||
fn get_elem(&self, pos: NodeIndex) -> mmr_lib::Result<Option<NodeOf<T, I, L>>> {
|
fn get_elem(&self, pos: NodeIndex) -> mmr_lib::Result<Option<NodeOf<T, I, L>>> {
|
||||||
Ok(<Nodes<T, I>>::get(pos).map(Node::Hash))
|
Ok(Nodes::<T, I>::get(pos).map(Node::Hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(&mut self, pos: NodeIndex, elems: Vec<NodeOf<T, I, L>>) -> mmr_lib::Result<()> {
|
fn append(&mut self, pos: NodeIndex, elems: Vec<NodeOf<T, I, L>>) -> mmr_lib::Result<()> {
|
||||||
@@ -147,7 +147,7 @@ where
|
|||||||
for elem in elems {
|
for elem in elems {
|
||||||
// On-chain we are going to only store new peaks.
|
// On-chain we are going to only store new peaks.
|
||||||
if peaks_to_store.next_if_eq(&node_index).is_some() {
|
if peaks_to_store.next_if_eq(&node_index).is_some() {
|
||||||
<Nodes<T, I>>::insert(node_index, elem.hash());
|
Nodes::<T, I>::insert(node_index, elem.hash());
|
||||||
}
|
}
|
||||||
// We are storing full node off-chain (using indexing API).
|
// We are storing full node off-chain (using indexing API).
|
||||||
Self::store_to_offchain(node_index, parent_hash, &elem);
|
Self::store_to_offchain(node_index, parent_hash, &elem);
|
||||||
@@ -164,7 +164,7 @@ where
|
|||||||
|
|
||||||
// And remove all remaining items from `peaks_before` collection.
|
// And remove all remaining items from `peaks_before` collection.
|
||||||
for pos in peaks_to_prune {
|
for pos in peaks_to_prune {
|
||||||
<Nodes<T, I>>::remove(pos);
|
Nodes::<T, I>::remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -608,9 +608,9 @@ fn verification_should_be_stateless() {
|
|||||||
let mut ext = new_test_ext();
|
let mut ext = new_test_ext();
|
||||||
let (root_6, root_7) = ext.execute_with(|| {
|
let (root_6, root_7) = ext.execute_with(|| {
|
||||||
add_blocks(6);
|
add_blocks(6);
|
||||||
let root_6 = crate::Pallet::<Test>::mmr_root_hash();
|
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||||
add_blocks(1);
|
add_blocks(1);
|
||||||
let root_7 = crate::Pallet::<Test>::mmr_root_hash();
|
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||||
(root_6, root_7)
|
(root_6, root_7)
|
||||||
});
|
});
|
||||||
ext.persist_offchain_overlay();
|
ext.persist_offchain_overlay();
|
||||||
@@ -656,9 +656,9 @@ fn should_verify_batch_proof_statelessly() {
|
|||||||
let mut ext = new_test_ext();
|
let mut ext = new_test_ext();
|
||||||
let (root_6, root_7) = ext.execute_with(|| {
|
let (root_6, root_7) = ext.execute_with(|| {
|
||||||
add_blocks(6);
|
add_blocks(6);
|
||||||
let root_6 = crate::Pallet::<Test>::mmr_root_hash();
|
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||||
add_blocks(1);
|
add_blocks(1);
|
||||||
let root_7 = crate::Pallet::<Test>::mmr_root_hash();
|
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||||
(root_6, root_7)
|
(root_6, root_7)
|
||||||
});
|
});
|
||||||
ext.persist_offchain_overlay();
|
ext.persist_offchain_overlay();
|
||||||
|
|||||||
Reference in New Issue
Block a user