Skip to content

Commit ceed7ce

Browse files
committed
feat: imp KeyToIncludeInRelayProof for test pallet
1 parent 397087b commit ceed7ce

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/test/runtime/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ sp-session = { workspace = true }
4141
sp-transaction-pool = { workspace = true }
4242
sp-version = { workspace = true }
4343

44+
# Polkadot
45+
polkadot-primitives = { workspace = true }
46+
4447
# Cumulus
4548
cumulus-pallet-aura-ext = { workspace = true }
4649
cumulus-pallet-parachain-system = { workspace = true }
@@ -75,6 +78,7 @@ std = [
7578
"pallet-timestamp/std",
7679
"pallet-transaction-payment/std",
7780
"parachain-info/std",
81+
"polkadot-primitives/std",
7882
"scale-info/std",
7983
"serde_json/std",
8084
"sp-api/std",

cumulus/test/runtime/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
374374
type WeightInfo = ();
375375
type SelfParaId = parachain_info::Pallet<Runtime>;
376376
type RuntimeEvent = RuntimeEvent;
377-
type OnSystemEvent = ();
377+
type OnSystemEvent = TestPallet;
378378
type OutboundXcmpMessageSource = ();
379379
// Ignore all DMP messages by enqueueing them into `()`:
380380
type DmpQueue = frame_support::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
@@ -643,8 +643,15 @@ impl_runtime_apis! {
643643
}
644644

645645
impl cumulus_primitives_core::KeyToIncludeInRelayProof<Block> for Runtime {
646-
fn keys_to_prove() -> RelayProofRequest {
647-
Default::default()
646+
fn keys_to_prove() -> cumulus_primitives_core::RelayProofRequest {
647+
use cumulus_primitives_core::RelayStorageKey;
648+
649+
RelayProofRequest {
650+
keys: vec![
651+
// Request a well-known key to verify its inclusion in the relay proof.
652+
RelayStorageKey::Top(test_pallet::RELAY_EPOCH_INDEX_KEY.to_vec()),
653+
],
654+
}
648655
}
649656
}
650657
}

cumulus/test/runtime/src/test_pallet.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
/// A special pallet that exposes dispatchables that are only useful for testing.
1818
pub use pallet::*;
1919

20+
use polkadot_primitives::well_known_keys;
21+
2022
/// Some key that we set in genesis and only read in [`TestOnRuntimeUpgrade`] to ensure that
2123
/// [`OnRuntimeUpgrade`] works as expected.
2224
pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+";
2325

26+
/// A well-known key to request for inclusion in the proof.
27+
pub use well_known_keys::EPOCH_INDEX as RELAY_EPOCH_INDEX_KEY;
28+
2429
#[frame_support::pallet(dev_mode)]
2530
pub mod pallet {
2631
use crate::test_pallet::TEST_RUNTIME_UPGRADE_KEY;
@@ -121,3 +126,27 @@ pub mod pallet {
121126
}
122127
}
123128
}
129+
130+
impl<T: Config> cumulus_pallet_parachain_system::OnSystemEvent for Pallet<T> {
131+
fn on_validation_data(_data: &cumulus_primitives_core::PersistedValidationData) {
132+
// Nothing to do here for tests
133+
}
134+
135+
fn on_validation_code_applied() {
136+
// Nothing to do here for tests
137+
}
138+
139+
fn on_relay_state_proof(
140+
relay_state_proof: &cumulus_pallet_parachain_system::relay_state_snapshot::RelayChainStateProof,
141+
) -> frame_support::weights::Weight {
142+
use crate::test_pallet::RELAY_EPOCH_INDEX_KEY;
143+
144+
// Expect the requested key to be part of the proof.
145+
relay_state_proof
146+
.read_optional_entry::<u64>(RELAY_EPOCH_INDEX_KEY)
147+
.expect("Invalid relay chain state proof")
148+
.expect("EPOCH_INDEX must be present");
149+
150+
frame_support::weights::Weight::zero()
151+
}
152+
}

0 commit comments

Comments
 (0)