fix: Complete snowbridge pezpallet rebrand and critical bug fixes
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs) - pallet/ directories → pezpallet/ (4 locations) - Fixed pezpallet.rs self-include recursion bug - Fixed sc-chain-spec hardcoded crate name in derive macro - Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API) - Added BizinikiwiConfig type alias for zombienet tests - Deleted obsolete session state files Verified: pezsnowbridge-pezpallet-*, pezpallet-staking, pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Benchmarks for the MMR pallet.
|
||||
//! Benchmarks for the MMR pezpallet.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
@@ -31,15 +31,15 @@ benchmarks_instance_pallet! {
|
||||
|
||||
let leaves = x as NodeIndex;
|
||||
|
||||
<<T as pallet::Config::<I>>::BenchmarkHelper as BenchmarkHelper>::setup();
|
||||
<<T as pezpallet::Config::<I>>::BenchmarkHelper as BenchmarkHelper>::setup();
|
||||
for leaf in 0..(leaves - 1) {
|
||||
<Pallet::<T, I> as OnInitialize<BlockNumberFor<T>>>::on_initialize((leaf as u32).into());
|
||||
<Pezpallet::<T, I> as OnInitialize<BlockNumberFor<T>>>::on_initialize((leaf as u32).into());
|
||||
}
|
||||
}: {
|
||||
<Pallet::<T, I> as OnInitialize<BlockNumberFor<T>>>::on_initialize((leaves as u32 - 1).into());
|
||||
<Pezpallet::<T, I> as OnInitialize<BlockNumberFor<T>>>::on_initialize((leaves as u32 - 1).into());
|
||||
} verify {
|
||||
assert_eq!(crate::NumberOfLeaves::<T, I>::get(), leaves);
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::mock::Test);
|
||||
impl_benchmark_test_suite!(Pezpallet, crate::tests::new_test_ext(), crate::mock::Test);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Default weights for the MMR Pallet
|
||||
//! Default weights for the MMR Pezpallet
|
||||
//! This file was not auto-generated.
|
||||
|
||||
use frame::{deps::pezframe_support::weights::constants::*, weights_prelude::*};
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
//! Details on Merkle Mountain Ranges (MMRs) can be found here:
|
||||
//! <https://github.com/mimblewimble/grin/blob/master/doc/mmr.md>
|
||||
//!
|
||||
//! The MMR pallet constructs an MMR from leaf data obtained on every block from
|
||||
//! The MMR pezpallet constructs an MMR from leaf data obtained on every block from
|
||||
//! `LeafDataProvider`. MMR nodes are stored both in:
|
||||
//! - on-chain storage - hashes only; not full leaf content;
|
||||
//! - off-chain storage - via Indexing API we push full leaf content (and all internal nodes as
|
||||
@@ -31,7 +31,7 @@
|
||||
//! `pezframe_system::Hashing`) so something compatible with external chains can be used (like
|
||||
//! Keccak256 for Ethereum compatibility).
|
||||
//!
|
||||
//! Depending on the usage context (off-chain vs on-chain) the pallet is able to:
|
||||
//! Depending on the usage context (off-chain vs on-chain) the pezpallet is able to:
|
||||
//! - verify MMR leaf proofs (on-chain)
|
||||
//! - generate leaf proofs (off-chain)
|
||||
//!
|
||||
@@ -40,12 +40,12 @@
|
||||
//!
|
||||
//! ## What for?
|
||||
//!
|
||||
//! Primary use case for this pallet is to generate MMR root hashes, that can latter on be used by
|
||||
//! Primary use case for this pezpallet is to generate MMR root hashes, that can latter on be used by
|
||||
//! BEEFY protocol (see <https://github.com/paritytech/grandpa-bridge-gadget>).
|
||||
//! MMR root hashes along with BEEFY will make it possible to build Super Light Clients (SLC) of
|
||||
//! Bizinikiwi-based chains. The SLC will be able to follow finality and can be shown proofs of more
|
||||
//! details that happened on the source chain.
|
||||
//! In that case the chain which contains the pallet generates the Root Hashes and Proofs, which
|
||||
//! In that case the chain which contains the pezpallet generates the Root Hashes and Proofs, which
|
||||
//! are then presented to another chain acting as a light client which can verify them.
|
||||
//!
|
||||
//! Secondary use case is to archive historical data, but still be able to retrieve them on-demand
|
||||
@@ -53,7 +53,7 @@
|
||||
//! in time to provide an MMR proof about some past block hash, while this data can be safely pruned
|
||||
//! from on-chain storage.
|
||||
//!
|
||||
//! NOTE This pallet is experimental and not proven to work in production.
|
||||
//! NOTE This pezpallet is experimental and not proven to work in production.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
@@ -68,7 +68,7 @@ pub use pezsp_mmr_primitives::{
|
||||
LeafIndex, LeafProof, NodeIndex, OnNewRoot,
|
||||
};
|
||||
|
||||
pub use pallet::*;
|
||||
pub use pezpallet::*;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
@@ -84,7 +84,7 @@ mod tests;
|
||||
/// blocks without using excessive on-chain storage.
|
||||
///
|
||||
/// Hence we implement the [LeafDataProvider] for [ParentNumberAndHash] which is a
|
||||
/// crate-local wrapper over [pezframe_system::Pallet]. Since the current block hash
|
||||
/// crate-local wrapper over [pezframe_system::Pezpallet]. Since the current block hash
|
||||
/// is not available (since the block is not finished yet),
|
||||
/// we use the `parent_hash` here along with parent block number.
|
||||
pub struct ParentNumberAndHash<T: Config> {
|
||||
@@ -96,8 +96,8 @@ impl<T: Config> LeafDataProvider for ParentNumberAndHash<T> {
|
||||
|
||||
fn leaf_data() -> Self::LeafData {
|
||||
(
|
||||
pezframe_system::Pallet::<T>::block_number().saturating_sub(One::one()),
|
||||
pezframe_system::Pallet::<T>::parent_hash(),
|
||||
pezframe_system::Pezpallet::<T>::block_number().saturating_sub(One::one()),
|
||||
pezframe_system::Pezpallet::<T>::parent_hash(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ pub struct DefaultBlockHashProvider<T: Config> {
|
||||
|
||||
impl<T: Config> BlockHashProvider<BlockNumberFor<T>, T::Hash> for DefaultBlockHashProvider<T> {
|
||||
fn block_hash(block_number: BlockNumberFor<T>) -> T::Hash {
|
||||
pezframe_system::Pallet::<T>::block_hash(block_number)
|
||||
pezframe_system::Pezpallet::<T>::block_hash(block_number)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,26 +133,26 @@ impl BenchmarkHelper for () {
|
||||
fn setup() {}
|
||||
}
|
||||
|
||||
/// An MMR specific to the pallet.
|
||||
/// An MMR specific to the pezpallet.
|
||||
type ModuleMmr<StorageType, T, I> = mmr::Mmr<StorageType, T, I, LeafOf<T, I>>;
|
||||
|
||||
/// Leaf data.
|
||||
type LeafOf<T, I> = <<T as Config<I>>::LeafData as LeafDataProvider>::LeafData;
|
||||
|
||||
/// Hashing used for the pallet.
|
||||
/// Hashing used for the pezpallet.
|
||||
pub(crate) type HashingOf<T, I> = <T as Config<I>>::Hashing;
|
||||
/// Hash type used for the pallet.
|
||||
/// Hash type used for the pezpallet.
|
||||
pub(crate) type HashOf<T, I> = <<T as Config<I>>::Hashing as Hash>::Output;
|
||||
|
||||
#[frame::pallet]
|
||||
pub mod pallet {
|
||||
#[frame::pezpallet]
|
||||
pub mod pezpallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T, I = ()>(PhantomData<(T, I)>);
|
||||
|
||||
/// This pallet's configuration trait
|
||||
#[pallet::config]
|
||||
/// This pezpallet's configuration trait
|
||||
#[pezpallet::config]
|
||||
pub trait Config<I: 'static = ()>: pezframe_system::Config {
|
||||
/// Prefix for elements stored in the Off-chain DB via Indexing API.
|
||||
///
|
||||
@@ -198,7 +198,7 @@ pub mod pallet {
|
||||
///
|
||||
/// For some applications it might be beneficial to make the MMR root available externally
|
||||
/// apart from having it in the storage. For instance you might output it in the header
|
||||
/// digest (see [`pezframe_system::Pallet::deposit_log`]) to make it available for Light
|
||||
/// digest (see [`pezframe_system::Pezpallet::deposit_log`]) to make it available for Light
|
||||
/// Clients. Hook complexity should be `O(1)`.
|
||||
type OnNewRoot: OnNewRoot<HashOf<Self, I>>;
|
||||
|
||||
@@ -208,7 +208,7 @@ pub mod pallet {
|
||||
<Self as pezframe_system::Config>::Hash,
|
||||
>;
|
||||
|
||||
/// Weights for this pallet.
|
||||
/// Weights for this pezpallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
/// Benchmarking setup helper trait.
|
||||
@@ -217,30 +217,30 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Latest MMR Root hash.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type RootHash<T: Config<I>, I: 'static = ()> = StorageValue<_, HashOf<T, I>, ValueQuery>;
|
||||
|
||||
/// Current size of the MMR (number of leaves).
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn mmr_leaves)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn mmr_leaves)]
|
||||
pub type NumberOfLeaves<T, I = ()> = StorageValue<_, LeafIndex, ValueQuery>;
|
||||
|
||||
/// Hashes of the nodes in the MMR.
|
||||
///
|
||||
/// Note this collection only contains MMR peaks, the inner nodes (and leaves)
|
||||
/// are pruned and only stored in the Offchain DB.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn mmr_peak)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn mmr_peak)]
|
||||
pub type Nodes<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Identity, NodeIndex, HashOf<T, I>, OptionQuery>;
|
||||
|
||||
/// Helper flag used in the runtime benchmarks for the initial setup.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type UseLocalStorage<T, I = ()> = StorageValue<_, bool, ValueQuery>;
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pezpallet<T, I> {
|
||||
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
||||
let leaves = NumberOfLeaves::<T, I>::get();
|
||||
let peaks_before = NodesUtils::new(leaves).number_of_peaks();
|
||||
@@ -310,7 +310,7 @@ where
|
||||
.map_err(|_| Error::Verify.log_debug(("The ancestry proof is incorrect.", root)))
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
impl<T: Config<I>, I: 'static> Pezpallet<T, I> {
|
||||
/// Build offchain key from `parent_hash` of block that originally added node `pos` to MMR.
|
||||
///
|
||||
/// This combination makes the offchain (key,value) entry resilient to chain forks.
|
||||
@@ -332,12 +332,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
|
||||
/// Provide the parent number for the block that added `leaf_index` to the MMR.
|
||||
fn leaf_index_to_parent_block_num(leaf_index: LeafIndex) -> BlockNumberFor<T> {
|
||||
// leaves are zero-indexed and were added one per block since pallet activation,
|
||||
// leaves are zero-indexed and were added one per block since pezpallet activation,
|
||||
// while block numbers are one-indexed, so block number that added `leaf_idx` is:
|
||||
// `block_num = block_num_when_pallet_activated + leaf_idx + 1`
|
||||
// `block_num = (current_block_num - leaves_count) + leaf_idx + 1`
|
||||
// `parent_block_num = current_block_num - leaves_count + leaf_idx`.
|
||||
<pezframe_system::Pallet<T>>::block_number()
|
||||
<pezframe_system::Pezpallet<T>>::block_number()
|
||||
.saturating_sub(Self::mmr_leaves().saturated_into())
|
||||
.saturating_add(leaf_index.saturated_into())
|
||||
}
|
||||
@@ -348,7 +348,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
T: pezframe_system::Config,
|
||||
{
|
||||
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
|
||||
<pezframe_system::Pallet<T>>::block_number(),
|
||||
<pezframe_system::Pezpallet<T>>::block_number(),
|
||||
NumberOfLeaves::<T, I>::get(),
|
||||
)?;
|
||||
|
||||
@@ -379,7 +379,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
) -> Result<(Vec<LeafOf<T, I>>, LeafProof<HashOf<T, I>>), Error> {
|
||||
// check whether best_known_block_number provided, else use current best block
|
||||
let best_known_block_number =
|
||||
best_known_block_number.unwrap_or_else(|| <pezframe_system::Pallet<T>>::block_number());
|
||||
best_known_block_number.unwrap_or_else(|| <pezframe_system::Pezpallet<T>>::block_number());
|
||||
|
||||
let leaf_count = Self::block_num_to_leaf_count(best_known_block_number)?;
|
||||
|
||||
@@ -429,7 +429,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
) -> Result<AncestryProof<HashOf<T, I>>, Error> {
|
||||
// check whether best_known_block_number provided, else use current best block
|
||||
let best_known_block_number =
|
||||
best_known_block_number.unwrap_or_else(|| <pezframe_system::Pallet<T>>::block_number());
|
||||
best_known_block_number.unwrap_or_else(|| <pezframe_system::Pezpallet<T>>::block_number());
|
||||
|
||||
let leaf_count = Self::block_num_to_leaf_count(best_known_block_number)?;
|
||||
let prev_leaf_count = Self::block_num_to_leaf_count(prev_block_number)?;
|
||||
@@ -440,7 +440,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub fn generate_mock_ancestry_proof() -> Result<AncestryProof<HashOf<T, I>>, Error> {
|
||||
let leaf_count = Self::block_num_to_leaf_count(<pezframe_system::Pallet<T>>::block_number())?;
|
||||
let leaf_count = Self::block_num_to_leaf_count(<pezframe_system::Pezpallet<T>>::block_number())?;
|
||||
let mmr: ModuleMmr<mmr::storage::OffchainStorage, T, I> = mmr::Mmr::new(leaf_count);
|
||||
mmr.generate_mock_ancestry_proof()
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use crate::{
|
||||
mmr::{Node, NodeOf},
|
||||
primitives::{mmr_lib, mmr_lib::helper, utils::NodesUtils, FullLeaf, NodeIndex},
|
||||
BlockHashProvider, Config, Nodes, NumberOfLeaves, Pallet,
|
||||
BlockHashProvider, Config, Nodes, NumberOfLeaves, Pezpallet,
|
||||
};
|
||||
use alloc::{vec, vec::Vec};
|
||||
use codec::Encode;
|
||||
@@ -62,7 +62,7 @@ impl OffchainStorage {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn set<T: Config<I>, I: 'static>(key: &[u8], value: &[u8]) {
|
||||
if crate::pallet::UseLocalStorage::<T, I>::get() {
|
||||
if crate::pezpallet::UseLocalStorage::<T, I>::get() {
|
||||
offchain::local_storage_set(StorageKind::PERSISTENT, key, value);
|
||||
} else {
|
||||
offchain_index::set(key, value);
|
||||
@@ -95,7 +95,7 @@ where
|
||||
// We should only get here when trying to generate proofs. The client requests
|
||||
// for proofs for finalized blocks, which should usually be already canonicalized,
|
||||
// unless the MMR client gadget has a delay.
|
||||
let key = Pallet::<T, I>::node_canon_offchain_key(pos);
|
||||
let key = Pezpallet::<T, I>::node_canon_offchain_key(pos);
|
||||
debug!(
|
||||
target: "runtime::mmr::offchain", "offchain db get {}: leaf idx {:?}, canon key {:?}",
|
||||
pos, ancestor_leaf_idx, key
|
||||
@@ -107,9 +107,9 @@ where
|
||||
|
||||
// Fall through to searching node using fork-specific key.
|
||||
let ancestor_parent_block_num =
|
||||
Pallet::<T, I>::leaf_index_to_parent_block_num(ancestor_leaf_idx);
|
||||
Pezpallet::<T, I>::leaf_index_to_parent_block_num(ancestor_leaf_idx);
|
||||
let ancestor_parent_hash = T::BlockHashProvider::block_hash(ancestor_parent_block_num);
|
||||
let temp_key = Pallet::<T, I>::node_temp_offchain_key(pos, ancestor_parent_hash);
|
||||
let temp_key = Pezpallet::<T, I>::node_temp_offchain_key(pos, ancestor_parent_hash);
|
||||
debug!(
|
||||
target: "runtime::mmr::offchain",
|
||||
"offchain db get {}: leaf idx {:?}, hash {:?}, temp key {:?}",
|
||||
@@ -177,7 +177,7 @@ where
|
||||
|
||||
// Use parent hash of block adding new nodes (this block) as extra identifier
|
||||
// in offchain DB to avoid DB collisions and overwrites in case of forks.
|
||||
let parent_hash = <pezframe_system::Pallet<T>>::parent_hash();
|
||||
let parent_hash = <pezframe_system::Pezpallet<T>>::parent_hash();
|
||||
for elem in elems {
|
||||
// On-chain we are going to only store new peaks.
|
||||
if peaks_to_store.next_if_eq(&node_index).is_some() {
|
||||
@@ -220,7 +220,7 @@ where
|
||||
// We store this leaf offchain keyed by `(parent_hash, node_index)` to make it
|
||||
// fork-resistant. The MMR client gadget task will "canonicalize" it on the first
|
||||
// finality notification that follows, when we are not worried about forks anymore.
|
||||
let temp_key = Pallet::<T, I>::node_temp_offchain_key(pos, parent_hash);
|
||||
let temp_key = Pezpallet::<T, I>::node_temp_offchain_key(pos, parent_hash);
|
||||
debug!(
|
||||
target: "runtime::mmr::offchain", "offchain db set: pos {} parent_hash {:?} key {:?}",
|
||||
pos, parent_hash, temp_key
|
||||
|
||||
@@ -38,12 +38,12 @@ fn register_offchain_ext(ext: &mut TestState) {
|
||||
}
|
||||
|
||||
fn new_block() -> Weight {
|
||||
let number = pezframe_system::Pallet::<Test>::block_number() + 1;
|
||||
let number = pezframe_system::Pezpallet::<Test>::block_number() + 1;
|
||||
let hash = H256::repeat_byte(number as u8);
|
||||
LeafDataTestValue::mutate(|r| r.a = number);
|
||||
|
||||
pezframe_system::Pallet::<Test>::reset_events();
|
||||
pezframe_system::Pallet::<Test>::initialize(&number, &hash, &Default::default());
|
||||
pezframe_system::Pezpallet::<Test>::reset_events();
|
||||
pezframe_system::Pezpallet::<Test>::initialize(&number, &hash, &Default::default());
|
||||
MMR::on_initialize(number)
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ fn should_append_to_mmr_when_on_initialize_is_called() {
|
||||
let (parent_b1, parent_b2) = ext.execute_with(|| {
|
||||
// when
|
||||
new_block();
|
||||
let parent_b1 = <pezframe_system::Pallet<Test>>::parent_hash();
|
||||
let parent_b1 = <pezframe_system::Pezpallet<Test>>::parent_hash();
|
||||
|
||||
// then
|
||||
assert_eq!(crate::NumberOfLeaves::<Test>::get(), 1);
|
||||
@@ -138,7 +138,7 @@ fn should_append_to_mmr_when_on_initialize_is_called() {
|
||||
|
||||
// when
|
||||
new_block();
|
||||
let parent_b2 = <pezframe_system::Pallet<Test>>::parent_hash();
|
||||
let parent_b2 = <pezframe_system::Pezpallet<Test>>::parent_hash();
|
||||
|
||||
// then
|
||||
assert_eq!(crate::NumberOfLeaves::<Test>::get(), 2);
|
||||
@@ -256,11 +256,11 @@ fn should_generate_proofs_correctly() {
|
||||
// to retrieve full leaf data.
|
||||
register_offchain_ext(&mut ext);
|
||||
ext.execute_with(|| {
|
||||
let best_block_number = pezframe_system::Pallet::<Test>::block_number();
|
||||
let best_block_number = pezframe_system::Pezpallet::<Test>::block_number();
|
||||
// when generate proofs for all leaves.
|
||||
let proofs = (1_u64..=best_block_number)
|
||||
.into_iter()
|
||||
.map(|block_num| crate::Pallet::<Test>::generate_proof(vec![block_num], None).unwrap())
|
||||
.map(|block_num| crate::Pezpallet::<Test>::generate_proof(vec![block_num], None).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
// when generate historical proofs for all leaves
|
||||
let historical_proofs = (1_u64..best_block_number)
|
||||
@@ -269,7 +269,7 @@ fn should_generate_proofs_correctly() {
|
||||
let mut proofs = vec![];
|
||||
for historical_best_block in block_num..=num_blocks {
|
||||
proofs.push(
|
||||
crate::Pallet::<Test>::generate_proof(
|
||||
crate::Pezpallet::<Test>::generate_proof(
|
||||
vec![block_num],
|
||||
Some(historical_best_block),
|
||||
)
|
||||
@@ -431,7 +431,7 @@ fn should_generate_batch_proof_correctly() {
|
||||
register_offchain_ext(&mut ext);
|
||||
ext.execute_with(|| {
|
||||
// when generate proofs for a batch of leaves
|
||||
let (.., proof) = crate::Pallet::<Test>::generate_proof(vec![1, 5, 6], None).unwrap();
|
||||
let (.., proof) = crate::Pezpallet::<Test>::generate_proof(vec![1, 5, 6], None).unwrap();
|
||||
// then
|
||||
assert_eq!(
|
||||
proof,
|
||||
@@ -449,7 +449,7 @@ fn should_generate_batch_proof_correctly() {
|
||||
|
||||
// when generate historical proofs for a batch of leaves
|
||||
let (.., historical_proof) =
|
||||
crate::Pallet::<Test>::generate_proof(vec![1, 5, 6], Some(6)).unwrap();
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![1, 5, 6], Some(6)).unwrap();
|
||||
// then
|
||||
assert_eq!(
|
||||
historical_proof,
|
||||
@@ -465,7 +465,7 @@ fn should_generate_batch_proof_correctly() {
|
||||
|
||||
// when generate historical proofs for a batch of leaves
|
||||
let (.., historical_proof) =
|
||||
crate::Pallet::<Test>::generate_proof(vec![1, 5, 6], None).unwrap();
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![1, 5, 6], None).unwrap();
|
||||
// then
|
||||
assert_eq!(historical_proof, proof);
|
||||
});
|
||||
@@ -486,30 +486,30 @@ fn should_verify() {
|
||||
register_offchain_ext(&mut ext);
|
||||
let (leaves, proof5) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![5], None).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![5], None).unwrap()
|
||||
});
|
||||
let (simple_historical_leaves, simple_historical_proof5) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![5], Some(6)).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![5], Some(6)).unwrap()
|
||||
});
|
||||
let (advanced_historical_leaves, advanced_historical_proof5) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![5], Some(7)).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![5], Some(7)).unwrap()
|
||||
});
|
||||
|
||||
ext.execute_with(|| {
|
||||
add_blocks(7);
|
||||
// then
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves, proof5), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves, proof5), Ok(()));
|
||||
assert_eq!(
|
||||
crate::Pallet::<Test>::verify_leaves(
|
||||
crate::Pezpallet::<Test>::verify_leaves(
|
||||
simple_historical_leaves,
|
||||
simple_historical_proof5
|
||||
),
|
||||
Ok(())
|
||||
);
|
||||
assert_eq!(
|
||||
crate::Pallet::<Test>::verify_leaves(
|
||||
crate::Pezpallet::<Test>::verify_leaves(
|
||||
advanced_historical_leaves,
|
||||
advanced_historical_proof5
|
||||
),
|
||||
@@ -524,17 +524,17 @@ fn generate_and_verify_batch_proof(
|
||||
blocks_to_add: usize,
|
||||
) {
|
||||
let (leaves, proof) = ext.execute_with(|| {
|
||||
crate::Pallet::<Test>::generate_proof(block_numbers.to_vec(), None).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(block_numbers.to_vec(), None).unwrap()
|
||||
});
|
||||
|
||||
let max_block_number = ext.execute_with(|| pezframe_system::Pallet::<Test>::block_number());
|
||||
let max_block_number = ext.execute_with(|| pezframe_system::Pezpallet::<Test>::block_number());
|
||||
let min_block_number = block_numbers.iter().max().unwrap();
|
||||
|
||||
// generate all possible historical proofs for the given blocks
|
||||
let historical_proofs = (*min_block_number..=max_block_number)
|
||||
.map(|best_block| {
|
||||
ext.execute_with(|| {
|
||||
crate::Pallet::<Test>::generate_proof(block_numbers.to_vec(), Some(best_block))
|
||||
crate::Pezpallet::<Test>::generate_proof(block_numbers.to_vec(), Some(best_block))
|
||||
.unwrap()
|
||||
})
|
||||
})
|
||||
@@ -543,9 +543,9 @@ fn generate_and_verify_batch_proof(
|
||||
ext.execute_with(|| {
|
||||
add_blocks(blocks_to_add);
|
||||
// then
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves, proof), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves, proof), Ok(()));
|
||||
historical_proofs.iter().for_each(|(leaves, proof)| {
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves.clone(), proof.clone()), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves.clone(), proof.clone()), Ok(()));
|
||||
});
|
||||
})
|
||||
}
|
||||
@@ -607,9 +607,9 @@ fn verification_should_be_stateless() {
|
||||
let mut ext = new_test_ext();
|
||||
let (root_6, root_7) = ext.execute_with(|| {
|
||||
add_blocks(6);
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||
let root_6 = crate::Pezpallet::<Test>::mmr_root();
|
||||
add_blocks(1);
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||
let root_7 = crate::Pezpallet::<Test>::mmr_root();
|
||||
(root_6, root_7)
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
@@ -619,11 +619,11 @@ fn verification_should_be_stateless() {
|
||||
register_offchain_ext(&mut ext);
|
||||
let (leaves, proof5) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![5], None).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![5], None).unwrap()
|
||||
});
|
||||
let (_, historical_proof5) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![5], Some(6)).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![5], Some(6)).unwrap()
|
||||
});
|
||||
|
||||
// Verify proof without relying on any on-chain data.
|
||||
@@ -655,9 +655,9 @@ fn should_verify_batch_proof_statelessly() {
|
||||
let mut ext = new_test_ext();
|
||||
let (root_6, root_7) = ext.execute_with(|| {
|
||||
add_blocks(6);
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||
let root_6 = crate::Pezpallet::<Test>::mmr_root();
|
||||
add_blocks(1);
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||
let root_7 = crate::Pezpallet::<Test>::mmr_root();
|
||||
(root_6, root_7)
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
@@ -667,11 +667,11 @@ fn should_verify_batch_proof_statelessly() {
|
||||
register_offchain_ext(&mut ext);
|
||||
let (leaves, proof) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![1, 4, 5], None).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![1, 4, 5], None).unwrap()
|
||||
});
|
||||
let (historical_leaves, historical_proof) = ext.execute_with(|| {
|
||||
// when
|
||||
crate::Pallet::<Test>::generate_proof(vec![1, 4, 5], Some(6)).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![1, 4, 5], Some(6)).unwrap()
|
||||
});
|
||||
|
||||
// Verify proof without relying on any on-chain data.
|
||||
@@ -711,11 +711,11 @@ fn should_verify_on_the_next_block_since_there_is_no_pruning_yet() {
|
||||
|
||||
ext.execute_with(|| {
|
||||
// when
|
||||
let (leaves, proof5) = crate::Pallet::<Test>::generate_proof(vec![5], None).unwrap();
|
||||
let (leaves, proof5) = crate::Pezpallet::<Test>::generate_proof(vec![5], None).unwrap();
|
||||
new_block();
|
||||
|
||||
// then
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves, proof5), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves, proof5), Ok(()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -735,27 +735,27 @@ fn should_verify_canonicalized() {
|
||||
for blocknum in 0u32..(2 * block_hash_size).try_into().unwrap() {
|
||||
ext.execute_with(|| {
|
||||
new_block();
|
||||
<Pallet<Test> as Hooks<BlockNumber>>::offchain_worker(blocknum.into());
|
||||
<Pezpallet<Test> as Hooks<BlockNumber>>::offchain_worker(blocknum.into());
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
}
|
||||
|
||||
// Generate proofs for some blocks.
|
||||
let (leaves, proofs) =
|
||||
ext.execute_with(|| crate::Pallet::<Test>::generate_proof(vec![1, 4, 5, 7], None).unwrap());
|
||||
ext.execute_with(|| crate::Pezpallet::<Test>::generate_proof(vec![1, 4, 5, 7], None).unwrap());
|
||||
// Verify all previously generated proofs.
|
||||
ext.execute_with(|| {
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves, proofs), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves, proofs), Ok(()));
|
||||
});
|
||||
|
||||
// Generate proofs for some new blocks.
|
||||
let (leaves, proofs) = ext.execute_with(|| {
|
||||
crate::Pallet::<Test>::generate_proof(vec![block_hash_size + 7], None).unwrap()
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![block_hash_size + 7], None).unwrap()
|
||||
});
|
||||
// Add some more blocks then verify all previously generated proofs.
|
||||
ext.execute_with(|| {
|
||||
add_blocks(7);
|
||||
assert_eq!(crate::Pallet::<Test>::verify_leaves(leaves, proofs), Ok(()));
|
||||
assert_eq!(crate::Pezpallet::<Test>::verify_leaves(leaves, proofs), Ok(()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -773,17 +773,17 @@ fn does_not_panic_when_generating_historical_proofs() {
|
||||
register_offchain_ext(&mut ext);
|
||||
ext.execute_with(|| {
|
||||
// when leaf index is invalid
|
||||
assert_eq!(crate::Pallet::<Test>::generate_proof(vec![10], None), Err(Error::LeafNotFound),);
|
||||
assert_eq!(crate::Pezpallet::<Test>::generate_proof(vec![10], None), Err(Error::LeafNotFound),);
|
||||
|
||||
// when leaves count is invalid
|
||||
assert_eq!(
|
||||
crate::Pallet::<Test>::generate_proof(vec![3], Some(100)),
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![3], Some(100)),
|
||||
Err(Error::GenerateProof),
|
||||
);
|
||||
|
||||
// when both leaf index and leaves count are invalid
|
||||
assert_eq!(
|
||||
crate::Pallet::<Test>::generate_proof(vec![10], Some(100)),
|
||||
crate::Pezpallet::<Test>::generate_proof(vec![10], Some(100)),
|
||||
Err(Error::LeafNotFound),
|
||||
);
|
||||
});
|
||||
@@ -798,27 +798,27 @@ fn generating_and_verifying_ancestry_proofs_works_correctly() {
|
||||
ext.execute_with(|| {
|
||||
for _ in 1..=500 {
|
||||
add_blocks(1);
|
||||
prev_roots.push(Pallet::<Test>::mmr_root())
|
||||
prev_roots.push(Pezpallet::<Test>::mmr_root())
|
||||
}
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
register_offchain_ext(&mut ext);
|
||||
|
||||
ext.execute_with(|| {
|
||||
let root = Pallet::<Test>::mmr_root();
|
||||
let root = Pezpallet::<Test>::mmr_root();
|
||||
// Check that generating and verifying ancestry proofs works correctly
|
||||
// for each previous block
|
||||
for prev_block_number in 1usize..=500 {
|
||||
let proof =
|
||||
Pallet::<Test>::generate_ancestry_proof(prev_block_number as u64, None).unwrap();
|
||||
assert!(Pallet::<Test>::is_ancestry_proof_optimal(&proof));
|
||||
Pezpallet::<Test>::generate_ancestry_proof(prev_block_number as u64, None).unwrap();
|
||||
assert!(Pezpallet::<Test>::is_ancestry_proof_optimal(&proof));
|
||||
assert_eq!(
|
||||
Pallet::<Test>::verify_ancestry_proof(root, proof),
|
||||
Pezpallet::<Test>::verify_ancestry_proof(root, proof),
|
||||
Ok(prev_roots[prev_block_number - 1])
|
||||
);
|
||||
}
|
||||
|
||||
// Check that we can't generate ancestry proofs for a future block.
|
||||
assert_eq!(Pallet::<Test>::generate_ancestry_proof(501, None), Err(Error::GenerateProof));
|
||||
assert_eq!(Pezpallet::<Test>::generate_ancestry_proof(501, None), Err(Error::GenerateProof));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// pezpallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/pez-kitchensink-runtime/pez_kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_mmr
|
||||
// --pezpallet=pezpallet_mmr
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/merkle-mountain-range/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
|
||||
Reference in New Issue
Block a user