Refactoring Checkpoint: (WIP)

This commit is contained in:
2025-12-14 10:29:31 +03:00
parent 09735eb97a
commit c89d7cac55
1424 changed files with 6415 additions and 6064 deletions
@@ -1,5 +1,5 @@
[package]
name = "mmr-gadget"
name = "pezmmr-gadget"
version = "29.0.0"
authors.workspace = true
edition.workspace = true
@@ -7,7 +7,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
repository.workspace = true
description = "MMR Client gadget for bizinikiwi"
homepage.workspace = true
documentation = "https://docs.rs/mmr-gadget"
documentation = "https://docs.rs/pezmmr-gadget"
[lints]
workspace = true
@@ -1,5 +1,5 @@
[package]
name = "mmr-rpc"
name = "pezmmr-rpc"
version = "28.0.0"
authors.workspace = true
edition.workspace = true
@@ -7,7 +7,7 @@ license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "Node-specific RPC methods for interaction with Merkle Mountain Range pallet."
documentation = "https://docs.rs/mmr-rpc"
documentation = "https://docs.rs/pezmmr-rpc"
[lints]
workspace = true
@@ -26,7 +26,7 @@ use pezsp_blockchain::{Error as ClientError, Result as ClientResult};
use pezsp_runtime::traits::{Block, NumberFor};
const VERSION_KEY: &[u8] = b"mmr_auxschema_version";
const GADGET_STATE: &[u8] = b"mmr_gadget_state";
const GADGET_STATE: &[u8] = b"pezmmr_gadget_state";
const CURRENT_VERSION: u32 = 1;
pub(crate) type PersistedState<B> = NumberFor<B>;
@@ -101,7 +101,7 @@ where
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::test_utils::{run_test_with_mmr_gadget_pre_post_using_client, MmrBlock, MockClient};
use crate::test_utils::{run_test_with_pezmmr_gadget_pre_post_using_client, MmrBlock, MockClient};
use parking_lot::Mutex;
use pezsp_runtime::generic::BlockId;
use std::{sync::Arc, time::Duration};
@@ -136,7 +136,7 @@ pub(crate) mod tests {
// state not available in db -> None
assert_eq!(load_state::<Block, Backend>(&*backend).unwrap(), None);
// run the gadget while importing and finalizing 3 blocks
run_test_with_mmr_gadget_pre_post_using_client(
run_test_with_pezmmr_gadget_pre_post_using_client(
client.clone(),
|_| async {},
|client| async move {
@@ -151,7 +151,7 @@ pub(crate) mod tests {
);
// verify previous progress was persisted and run the gadget again
run_test_with_mmr_gadget_pre_post_using_client(
run_test_with_pezmmr_gadget_pre_post_using_client(
client.clone(),
|client| async move {
let backend = &*client.backend;
@@ -183,7 +183,7 @@ pub(crate) mod tests {
let blocks_clone = blocks.clone();
// run the gadget while importing and finalizing 3 blocks
run_test_with_mmr_gadget_pre_post_using_client(
run_test_with_pezmmr_gadget_pre_post_using_client(
client.clone(),
|_| async {},
|client| async move {
@@ -206,7 +206,7 @@ pub(crate) mod tests {
let blocks_clone = blocks.clone();
// verify new gadget continues from block 4 and ignores 1, 2, 3 based on persisted state
run_test_with_mmr_gadget_pre_post_using_client(
run_test_with_pezmmr_gadget_pre_post_using_client(
client.clone(),
|client| async move {
let blocks = blocks_clone.lock();
@@ -201,12 +201,12 @@ where
},
};
let mmr_gadget = MmrGadget::<B, BE, C> {
let pezmmr_gadget = MmrGadget::<B, BE, C> {
finality_notifications: client.finality_notification_stream(),
_phantom: Default::default(),
};
mmr_gadget
pezmmr_gadget
.run(OffchainMmrBuilder {
backend,
client,
@@ -220,14 +220,14 @@ where
#[cfg(test)]
mod tests {
use crate::test_utils::run_test_with_mmr_gadget;
use crate::test_utils::run_test_with_pezmmr_gadget;
use pezsp_runtime::generic::BlockId;
use std::time::Duration;
#[test]
fn mmr_first_block_is_computed_correctly() {
// Check the case where the first block is also the first block with MMR.
run_test_with_mmr_gadget(|client| async move {
run_test_with_pezmmr_gadget(|client| async move {
// G -> A1 -> A2
// |
// | -> first mmr block
@@ -243,7 +243,7 @@ mod tests {
});
// Check the case where the first block with MMR comes later.
run_test_with_mmr_gadget(|client| async move {
run_test_with_pezmmr_gadget(|client| async move {
// G -> A1 -> A2 -> A3 -> A4 -> A5 -> A6
// |
// | -> first mmr block
@@ -265,7 +265,7 @@ mod tests {
#[test]
fn does_not_panic_on_invalid_num_mmr_blocks() {
run_test_with_mmr_gadget(|client| async move {
run_test_with_pezmmr_gadget(|client| async move {
// G -> A1
// |
// | -> first mmr block
@@ -279,14 +279,14 @@ where
#[cfg(test)]
mod tests {
use crate::test_utils::{run_test_with_mmr_gadget, run_test_with_mmr_gadget_pre_post};
use crate::test_utils::{run_test_with_pezmmr_gadget, run_test_with_pezmmr_gadget_pre_post};
use parking_lot::Mutex;
use pezsp_runtime::generic::BlockId;
use std::{sync::Arc, time::Duration};
#[test]
fn canonicalize_and_prune_works_correctly() {
run_test_with_mmr_gadget(|client| async move {
run_test_with_pezmmr_gadget(|client| async move {
// -> D4 -> D5
// G -> A1 -> A2 -> A3 -> A4
// -> B1 -> B2 -> B3
@@ -325,7 +325,7 @@ mod tests {
#[test]
fn canonicalize_and_prune_handles_pallet_reset() {
run_test_with_mmr_gadget(|client| async move {
run_test_with_pezmmr_gadget(|client| async move {
// G -> A1 -> A2 -> A3 -> A4 -> A5
// | |
// | | -> pallet reset
@@ -357,7 +357,7 @@ mod tests {
fn canonicalize_catchup_works_correctly() {
let mmr_blocks = Arc::new(Mutex::new(vec![]));
let mmr_blocks_ref = mmr_blocks.clone();
run_test_with_mmr_gadget_pre_post(
run_test_with_pezmmr_gadget_pre_post(
|client| async move {
// G -> A1 -> A2
// | |
@@ -402,7 +402,7 @@ mod tests {
fn canonicalize_catchup_works_correctly_with_pallet_reset() {
let mmr_blocks = Arc::new(Mutex::new(vec![]));
let mmr_blocks_ref = mmr_blocks.clone();
run_test_with_mmr_gadget_pre_post(
run_test_with_pezmmr_gadget_pre_post(
|client| async move {
// G -> A1 -> A2
// | |
@@ -334,15 +334,15 @@ pezsp_api::mock_impl_runtime_apis! {
}
}
pub(crate) fn run_test_with_mmr_gadget<F, Fut>(post_gadget: F)
pub(crate) fn run_test_with_pezmmr_gadget<F, Fut>(post_gadget: F)
where
F: FnOnce(Arc<MockClient>) -> Fut + 'static,
Fut: Future<Output = ()>,
{
run_test_with_mmr_gadget_pre_post(|_| async {}, post_gadget);
run_test_with_pezmmr_gadget_pre_post(|_| async {}, post_gadget);
}
pub(crate) fn run_test_with_mmr_gadget_pre_post<F, G, RetF, RetG>(pre_gadget: F, post_gadget: G)
pub(crate) fn run_test_with_pezmmr_gadget_pre_post<F, G, RetF, RetG>(pre_gadget: F, post_gadget: G)
where
F: FnOnce(Arc<MockClient>) -> RetF + 'static,
G: FnOnce(Arc<MockClient>) -> RetG + 'static,
@@ -350,10 +350,10 @@ where
RetG: Future<Output = ()>,
{
let client = Arc::new(MockClient::new());
run_test_with_mmr_gadget_pre_post_using_client(client, pre_gadget, post_gadget)
run_test_with_pezmmr_gadget_pre_post_using_client(client, pre_gadget, post_gadget)
}
pub(crate) fn run_test_with_mmr_gadget_pre_post_using_client<F, G, RetF, RetG>(
pub(crate) fn run_test_with_pezmmr_gadget_pre_post_using_client<F, G, RetF, RetG>(
client: Arc<MockClient>,
pre_gadget: F,
post_gadget: G,