Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pallet relay storage roots #370

Merged
merged 11 commits into from
Jan 17, 2024
321 changes: 173 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pallet-evm-precompile-call-permit = { git = "https://github.com/moondance-labs/m
pallet-evm-precompile-xcm-utils = { git = "https://github.com/moondance-labs/moonkit", branch = "tanssi-polkadot-v1.3.0", default-features = false }
pallet-maintenance-mode = { git = "https://github.com/moondance-labs/moonkit", branch = "tanssi-polkadot-v1.3.0", default-features = false }
pallet-migrations = { git = "https://github.com/moondance-labs/moonkit", branch = "tanssi-polkadot-v1.3.0", default-features = false }
pallet-relay-storage-roots = { git = "https://github.com/moondance-labs/moonkit", branch = "tanssi-polkadot-v1.3.0", default-features = false }
xcm-primitives = { git = "https://github.com/moondance-labs/moonkit", branch = "tanssi-polkadot-v1.3.0", default-features = false }

# Substrate (wasm)
Expand Down
4 changes: 4 additions & 0 deletions runtime/dancebox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pallet-pooled-staking = { workspace = true }
pallet-proxy = { workspace = true }
pallet-registrar = { workspace = true }
pallet-registrar-runtime-api = { workspace = true }
pallet-relay-storage-roots = { workspace = true }
pallet-services-payment = { workspace = true }

# Moonkit
Expand Down Expand Up @@ -176,6 +177,7 @@ std = [
"pallet-proxy/std",
"pallet-registrar-runtime-api/std",
"pallet-registrar/std",
"pallet-relay-storage-roots/std",
"pallet-root-testing/std",
"pallet-services-payment/std",
"pallet-session/std",
Expand Down Expand Up @@ -258,6 +260,7 @@ runtime-benchmarks = [
"pallet-pooled-staking/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-registrar/runtime-benchmarks",
"pallet-relay-storage-roots/runtime-benchmarks",
"pallet-services-payment/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
Expand Down Expand Up @@ -309,6 +312,7 @@ try-runtime = [
"pallet-pooled-staking/try-runtime",
"pallet-proxy/try-runtime",
"pallet-registrar/try-runtime",
"pallet-relay-storage-roots/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-services-payment/try-runtime",
"pallet-session/try-runtime",
Expand Down
14 changes: 14 additions & 0 deletions runtime/dancebox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,16 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceExecutiveHooks = MaintenanceHooks;
}

parameter_types! {
pub const MaxStorageRoots: u32 = 10; // 1 minute of relay blocks
}

impl pallet_relay_storage_roots::Config for Runtime {
type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider<Self>;
type MaxStorageRoots = MaxStorageRoots;
type WeightInfo = ();
}

impl pallet_root_testing::Config for Runtime {}

parameter_types! {
Expand Down Expand Up @@ -1414,6 +1424,9 @@ construct_runtime!(
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 52,
PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>} = 53,

// More system support stuff
RelayStorageRoots: pallet_relay_storage_roots = 60,

RootTesting: pallet_root_testing = 100,
AsyncBacking: pallet_async_backing::{Pallet, Storage} = 110,
}
Expand All @@ -1432,6 +1445,7 @@ mod benches {
[pallet_services_payment, ServicesPayment]
[pallet_data_preservers, DataPreservers]
[pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::<Runtime>]
[pallet_relay_storage_roots, RelayStorageRoots]
);
}

Expand Down
4 changes: 4 additions & 0 deletions runtime/flashbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pallet-initializer = { workspace = true }
pallet-proxy = { workspace = true }
pallet-registrar = { workspace = true }
pallet-registrar-runtime-api = { workspace = true }
pallet-relay-storage-roots = { workspace = true }
pallet-services-payment = { workspace = true }

# Moonkit
Expand Down Expand Up @@ -151,6 +152,7 @@ std = [
"pallet-proxy/std",
"pallet-registrar-runtime-api/std",
"pallet-registrar/std",
"pallet-relay-storage-roots/std",
"pallet-root-testing/std",
"pallet-services-payment/std",
"pallet-session/std",
Expand Down Expand Up @@ -219,6 +221,7 @@ runtime-benchmarks = [
"pallet-migrations/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-registrar/runtime-benchmarks",
"pallet-relay-storage-roots/runtime-benchmarks",
"pallet-services-payment/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand Down Expand Up @@ -255,6 +258,7 @@ try-runtime = [
"pallet-migrations/try-runtime",
"pallet-proxy/try-runtime",
"pallet-registrar/try-runtime",
"pallet-relay-storage-roots/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-services-payment/try-runtime",
"pallet-session/try-runtime",
Expand Down
14 changes: 14 additions & 0 deletions runtime/flashbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,16 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceExecutiveHooks = MaintenanceHooks;
}

parameter_types! {
pub const MaxStorageRoots: u32 = 10; // 1 minute of relay blocks
}

impl pallet_relay_storage_roots::Config for Runtime {
type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider<Self>;
type MaxStorageRoots = MaxStorageRoots;
type WeightInfo = ();
}

impl pallet_root_testing::Config for Runtime {}

parameter_types! {
Expand Down Expand Up @@ -1159,6 +1169,9 @@ construct_runtime!(
// InflationRewards must be after Session and AuthorInherent
InflationRewards: pallet_inflation_rewards = 35,

// More system support stuff
RelayStorageRoots: pallet_relay_storage_roots = 60,

RootTesting: pallet_root_testing = 100,
AsyncBacking: pallet_async_backing::{Pallet, Storage} = 110,
}
Expand All @@ -1175,6 +1188,7 @@ mod benches {
[pallet_invulnerables, Invulnerables]
[pallet_services_payment, ServicesPayment]
[pallet_data_preservers, DataPreservers]
[pallet_relay_storage_roots, RelayStorageRoots]
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "@tanssi/api-augment";
import { describeSuite, expect, beforeAll } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";

describeSuite({
id: "CT0801",
title: "RelayStorageRoots pallet test suite",
foundationMethods: "dev",

testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;

beforeAll(async () => {
polkadotJs = context.polkadotJs();
});

it({
id: "E01",
title: "Only 10 latest blocks are stored",
test: async function () {
// Relay block list starts empty
const relayBlocksEmpty = (await polkadotJs.query.relayStorageRoots.relayStorageRootKeys()).toJSON();
expect(relayBlocksEmpty).to.deep.equal([]);

// Create 30 blocks
for (let i = 0; i < 20; i++) {
await context.createBlock();
}

// Only latest 10 will be stored
// relay_block_number = tanssi_block_number * 2 + 1000
const relayBlocks = (await polkadotJs.query.relayStorageRoots.relayStorageRootKeys()).toJSON();
expect(relayBlocks).to.deep.equal([1020, 1022, 1024, 1026, 1028, 1030, 1032, 1034, 1036, 1038]);

// The mapping only contains the keys that are in `relayStorageRootKeys`
const mappingKeys = (await polkadotJs.query.relayStorageRoots.relayStorageRoot.keys()).map((key) => {
// Convert "1,020" into 1020
return parseInt(key.toHuman().toString().replace(",", ""));
});
mappingKeys.sort();
expect(relayBlocks).to.deep.equal(mappingKeys);
},
});
},
});
10 changes: 10 additions & 0 deletions typescript-api/src/dancebox/interfaces/augment-api-consts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions typescript-api/src/dancebox/interfaces/augment-api-query.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions typescript-api/src/dancebox/interfaces/lookup.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions typescript-api/src/dancebox/interfaces/types-lookup.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions typescript-api/src/flashbox/interfaces/augment-api-consts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions typescript-api/src/flashbox/interfaces/augment-api-query.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading