Skip to content

Commit 648a1bf

Browse files
committed
setup mmr pruning tests
1 parent e0c8e43 commit 648a1bf

File tree

9 files changed

+151
-37
lines changed

9 files changed

+151
-37
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ tesseract = { path = "tesseract/relayer" }
302302
transaction-fees = { path = "tesseract/fees" }
303303
telemetry-server = { path = "tesseract/telemetry" }
304304
tesseract-config = { path = "tesseract/config" }
305+
tesseract-integration-test = { path = "tesseract/integration-test"}
305306

306307
[workspace.dependencies.cumulus-pallet-parachain-system]
307308
version = "0.7.0"

evm/abi/src/generated/evm_host.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -2759,8 +2759,7 @@ pub mod evm_host {
27592759
///Gets the contract's `GetRequestHandled` event
27602760
pub fn get_request_handled_filter(
27612761
&self,
2762-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, GetRequestHandledFilter>
2763-
{
2762+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, GetRequestHandledFilter> {
27642763
self.0.event()
27652764
}
27662765
///Gets the contract's `GetRequestTimeoutHandled` event
@@ -2782,8 +2781,7 @@ pub mod evm_host {
27822781
///Gets the contract's `HostParamsUpdated` event
27832782
pub fn host_params_updated_filter(
27842783
&self,
2785-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, HostParamsUpdatedFilter>
2786-
{
2784+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, HostParamsUpdatedFilter> {
27872785
self.0.event()
27882786
}
27892787
///Gets the contract's `HostWithdrawal` event
@@ -2801,8 +2799,7 @@ pub mod evm_host {
28012799
///Gets the contract's `PostRequestHandled` event
28022800
pub fn post_request_handled_filter(
28032801
&self,
2804-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostRequestHandledFilter>
2805-
{
2802+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostRequestHandledFilter> {
28062803
self.0.event()
28072804
}
28082805
///Gets the contract's `PostRequestTimeoutHandled` event
@@ -2818,15 +2815,13 @@ pub mod evm_host {
28182815
///Gets the contract's `PostResponseEvent` event
28192816
pub fn post_response_event_filter(
28202817
&self,
2821-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostResponseEventFilter>
2822-
{
2818+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostResponseEventFilter> {
28232819
self.0.event()
28242820
}
28252821
///Gets the contract's `PostResponseFunded` event
28262822
pub fn post_response_funded_filter(
28272823
&self,
2828-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostResponseFundedFilter>
2829-
{
2824+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, PostResponseFundedFilter> {
28302825
self.0.event()
28312826
}
28322827
///Gets the contract's `PostResponseHandled` event

evm/abi/src/generated/ping_module.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,13 @@ pub mod ping_module {
699699
///Gets the contract's `GetTimeoutReceived` event
700700
pub fn get_timeout_received_filter(
701701
&self,
702-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, GetTimeoutReceivedFilter>
703-
{
702+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, GetTimeoutReceivedFilter> {
704703
self.0.event()
705704
}
706705
///Gets the contract's `MessageDispatched` event
707706
pub fn message_dispatched_filter(
708707
&self,
709-
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, MessageDispatchedFilter>
710-
{
708+
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, MessageDispatchedFilter> {
711709
self.0.event()
712710
}
713711
///Gets the contract's `PostReceived` event

modules/consensus/beefy/prover/src/runtime/paseo.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ pub mod api {
526526
pub fn pending_rewards(
527527
&self,
528528
who: ::subxt::utils::AccountId32,
529-
) -> ::subxt::runtime_api::Payload<types::PendingRewards, ::core::primitive::u128>
530-
{
529+
) -> ::subxt::runtime_api::Payload<types::PendingRewards, ::core::primitive::u128> {
531530
::subxt::runtime_api::Payload::new_static(
532531
"NominationPoolsApi",
533532
"pending_rewards",
@@ -2247,8 +2246,7 @@ pub mod api {
22472246
#[doc = " Get current GRANDPA authority set id."]
22482247
pub fn current_set_id(
22492248
&self,
2250-
) -> ::subxt::runtime_api::Payload<types::CurrentSetId, ::core::primitive::u64>
2251-
{
2249+
) -> ::subxt::runtime_api::Payload<types::CurrentSetId, ::core::primitive::u64> {
22522250
::subxt::runtime_api::Payload::new_static(
22532251
"GrandpaApi",
22542252
"current_set_id",
@@ -2685,8 +2683,7 @@ pub mod api {
26852683
pub fn account_nonce(
26862684
&self,
26872685
account: ::subxt::utils::AccountId32,
2688-
) -> ::subxt::runtime_api::Payload<types::AccountNonce, ::core::primitive::u32>
2689-
{
2686+
) -> ::subxt::runtime_api::Payload<types::AccountNonce, ::core::primitive::u32> {
26902687
::subxt::runtime_api::Payload::new_static(
26912688
"AccountNonceApi",
26922689
"account_nonce",
@@ -4398,8 +4395,7 @@ pub mod api {
43984395
#[doc = " The maximum length of a block (in bytes)."]
43994396
pub fn block_length(
44004397
&self,
4401-
) -> ::subxt::constants::Address<runtime_types::frame_system::limits::BlockLength>
4402-
{
4398+
) -> ::subxt::constants::Address<runtime_types::frame_system::limits::BlockLength> {
44034399
::subxt::constants::Address::new_static(
44044400
"System",
44054401
"BlockLength",
@@ -12689,8 +12685,7 @@ pub mod api {
1268912685
#[doc = " Maximum amount of funds that should be placed in a deposit for making a proposal."]
1269012686
pub fn proposal_bond_maximum(
1269112687
&self,
12692-
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>>
12693-
{
12688+
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>> {
1269412689
::subxt::constants::Address::new_static(
1269512690
"Treasury",
1269612691
"ProposalBondMaximum",
@@ -18654,8 +18649,7 @@ pub mod api {
1865418649
#[doc = " Maximum amount of funds that should be placed in a deposit for making a proposal."]
1865518650
pub fn curator_deposit_max(
1865618651
&self,
18657-
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>>
18658-
{
18652+
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>> {
1865918653
::subxt::constants::Address::new_static(
1866018654
"Bounties",
1866118655
"CuratorDepositMax",
@@ -18670,8 +18664,7 @@ pub mod api {
1867018664
#[doc = " Minimum amount of funds that should be placed in a deposit for making a proposal."]
1867118665
pub fn curator_deposit_min(
1867218666
&self,
18673-
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>>
18674-
{
18667+
) -> ::subxt::constants::Address<::core::option::Option<::core::primitive::u128>> {
1867518668
::subxt::constants::Address::new_static(
1867618669
"Bounties",
1867718670
"CuratorDepositMin",

modules/utils/subxt/src/gargantua.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ pub mod api {
245245
&self,
246246
included_hash: ::subxt::utils::H256,
247247
slot: runtime_types::sp_consensus_slots::Slot,
248-
) -> ::subxt::runtime_api::Payload<types::CanBuildUpon, ::core::primitive::bool>
249-
{
248+
) -> ::subxt::runtime_api::Payload<types::CanBuildUpon, ::core::primitive::bool> {
250249
::subxt::runtime_api::Payload::new_static(
251250
"AuraUnincludedSegmentApi",
252251
"can_build_upon",
@@ -854,8 +853,7 @@ pub mod api {
854853
pub fn account_nonce(
855854
&self,
856855
account: ::subxt::utils::AccountId32,
857-
) -> ::subxt::runtime_api::Payload<types::AccountNonce, ::core::primitive::u32>
858-
{
856+
) -> ::subxt::runtime_api::Payload<types::AccountNonce, ::core::primitive::u32> {
859857
::subxt::runtime_api::Payload::new_static(
860858
"AccountNonceApi",
861859
"account_nonce",
@@ -3254,8 +3252,7 @@ pub mod api {
32543252
#[doc = " The maximum length of a block (in bytes)."]
32553253
pub fn block_length(
32563254
&self,
3257-
) -> ::subxt::constants::Address<runtime_types::frame_system::limits::BlockLength>
3258-
{
3255+
) -> ::subxt::constants::Address<runtime_types::frame_system::limits::BlockLength> {
32593256
::subxt::constants::Address::new_static(
32603257
"System",
32613258
"BlockLength",

parachain/simtests/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jsonrpsee-core = { version = "0.22.4", features = ["client"] }
3434
trie-db = { workspace = true }
3535
hash-db = { workspace = true }
3636
sp-trie = { workspace = true }
37+
subxt-signer = "0.30.1"
38+
tesseract-substrate = { workspace = true }
39+
tesseract-integration-test = { workspace = true}
40+
hex = "0.4.3"
3741

3842
[features]
3943
stress-test = []

parachain/simtests/src/pallet_mmr.rs

+124-2
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,30 @@ use sp_mmr_primitives::{
1313
INDEXING_PREFIX,
1414
};
1515
use sp_runtime::traits::Keccak256;
16-
use subxt::{rpc_params, tx::SubmittableExtrinsic, utils::H160};
16+
use subxt::{
17+
rpc_params,
18+
tx::SubmittableExtrinsic,
19+
utils::{AccountId32, H160},
20+
OnlineClient,
21+
};
1722

23+
use ismp::host::StateMachine;
1824
use mmr_primitives::{DataOrHash, FullLeaf};
1925
use pallet_ismp::mmr::{Leaf, ProofKeys};
2026
use pallet_mmr::mmr::Hasher as MmrHasher;
27+
use subxt_signer::sr25519::dev::{self};
2128
use subxt_utils::{
2229
gargantua,
23-
gargantua::api::runtime_types::{ismp::host::Ethereum, pallet_ismp_demo::pallet::EvmParams},
30+
gargantua::api::runtime_types::{
31+
ismp::host::Ethereum,
32+
pallet_ismp_demo::pallet::{EvmParams, GetRequest, TransferParams},
33+
},
2434
Hyperbridge,
2535
};
36+
use tesseract_integration_test;
37+
use tesseract_substrate::{self, SubstrateClient};
38+
39+
const PRUNNING_DEPTH: u32 = 630_0000; // leaves = approx 1Gb
2640

2741
#[tokio::test]
2842
#[ignore]
@@ -448,3 +462,111 @@ async fn dispatch_requests() -> Result<(), anyhow::Error> {
448462
assert!(res);
449463
Ok(())
450464
}
465+
466+
/// offchainDB mmr prunning for timedout request and processed requests that knowledge of their
467+
/// internal nodes is of no use for relayers and users.
468+
/// Prunning should be triggered iff a certain depth has been reached,
469+
/// depth = current_number_of_leaves - last_number_of_leaves
470+
/// This logic should make/enforce somehow maximum storage of requests
471+
///
472+
/// Pruning should not consume any useful blockweight hence should be done during on-idle.
473+
//#[cfg(feature = "offchainDb-pruning")]
474+
#[tokio::test(flavor = "multi_thread")]
475+
#[ignore]
476+
async fn offchainDb_mmr_pruning_requests_work() -> Result<(), anyhow::Error> {
477+
let (chain_a_sub_client, chain_b_sub_client) = tesseract_integration_test::create_clients()?;
478+
// produce some initial blocks on both chains ( A and B )
479+
for _ in 0..=10 {
480+
let block = chain_a_sub_client
481+
.client
482+
.rpc()
483+
.request::<CreatedBlock<H256>>("engine_createBlock", rpc_params![true, false])
484+
.await?;
485+
486+
let finalized = chain_a_sub_client
487+
.client
488+
.rpc()
489+
.request::<bool>("engine_finalizeBlock", rpc_params![block.hash])
490+
.await?;
491+
assert!(finalized);
492+
493+
let block = chain_b_sub_client
494+
.client
495+
.rpc()
496+
.request::<CreatedBlock<H256>>("engine_createBlock", rpc_params![true, false])
497+
.await?;
498+
499+
let finalized = chain_b_sub_client
500+
.client
501+
.rpc()
502+
.request::<bool>("engine_finalizeBlock", rpc_params![block.hash])
503+
.await?;
504+
assert!(finalized);
505+
}
506+
tokio::time::sleep(Duration::from_secs(10)).await;
507+
508+
// dispatch and process 600_000 request
509+
dispatch_and_process_requests(chain_a_sub_client.clone(), chain_b_sub_client.clone(), 600_000)
510+
.await?;
511+
// assert number of leaves
512+
let leaves_count = chain_a_sub_client
513+
.client
514+
.storage()
515+
.at_latest()
516+
.await?
517+
.fetch(&gargantua::api::storage().mmr().number_of_leaves())
518+
.await?
519+
.ok_or("Failed to fetch")
520+
.unwrap();
521+
522+
assert_eq!(leaves_count, 600_000);
523+
// perform random lookup in the offchain Db
524+
525+
// dispatch and process additional 30_000 request to trigger prunning
526+
dispatch_and_process_requests(chain_a_sub_client.clone(), chain_b_sub_client.clone(), 30_000)
527+
.await?;
528+
529+
// assert the number of leaves are not 630_000
530+
531+
// get the number of leaves remaining (A)
532+
533+
dispatch_and_process_requests(chain_a_sub_client, chain_b_sub_client, 100_000).await?;
534+
535+
// assert the number of leaves are A + 100_000 indicating not pruned as the depth not reached
536+
537+
Ok(())
538+
}
539+
540+
/// dispatch get and post requests and timeout post request and process get_requests
541+
/// this function should return no of timedout and pruned requests
542+
async fn dispatch_and_process_requests(
543+
client_a_sub: SubstrateClient<Hyperbridge>,
544+
client_b_sub: SubstrateClient<Hyperbridge>,
545+
count: u64,
546+
) -> Result<u64, anyhow::Error> {
547+
// post request
548+
let amount: u128 = 100 * 1000000000000;
549+
let transfer_params = TransferParams {
550+
to: AccountId32(dev::alice().public_key().0),
551+
amount,
552+
para_id: 2001,
553+
timeout: 5,
554+
};
555+
556+
// get request
557+
let encoded_chain_b_id_storage_key =
558+
"0x0d715f2646c8f85767b5d2764bb2782604a74d81251e398fd8a0a4d55023bb3f";
559+
560+
let latest_height_b =
561+
client_a_sub.query_latest_height(client_b_sub.state_machine_id()).await? - 1;
562+
let get_params = GetRequest {
563+
para_id: 2001,
564+
height: latest_height_b,
565+
timeout: 0,
566+
keys: vec![hex::decode(encoded_chain_b_id_storage_key.strip_prefix("0x").unwrap()).unwrap()],
567+
};
568+
569+
// batch submit the requests based on number of counts
570+
todo!();
571+
Ok(0)
572+
}

tesseract/integration-test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async fn relay_get_response_message(
163163
}
164164

165165
/// Configure the state machines and spawn the messaging relayer
166-
async fn create_clients(
166+
pub async fn create_clients(
167167
) -> Result<(SubstrateClient<Hyperbridge>, SubstrateClient<Hyperbridge>), anyhow::Error> {
168168
let chain_a_config = SubstrateConfig {
169169
state_machine: StateMachine::Kusama(2000),

0 commit comments

Comments
 (0)