Skip to content

Commit

Permalink
parachain-inherent: Make para_id more prominent (paritytech#4555)
Browse files Browse the repository at this point in the history
This should make it more obvious that at instantiation of the
`MockValidationDataInherentDataProvider` the `para_id` needs to be
passed.
  • Loading branch information
bkchr authored and AurevoirXavier committed Jun 26, 2024
1 parent df7f0a1 commit 5811785
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cumulus/client/parachain-inherent/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,36 @@ pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
/// your parachain's configuration in order to mock the MQC heads properly.
/// See [`MockXcmConfig`] for more information
pub struct MockValidationDataInherentDataProvider<R = ()> {
/// The current block number of the local block chain (the parachain)
/// The current block number of the local block chain (the parachain).
pub current_para_block: u32,
/// The current block head data of the local block chain (the parachain)
/// The parachain ID of the parachain for that the inherent data is created.
pub para_id: ParaId,
/// The current block head data of the local block chain (the parachain).
pub current_para_block_head: Option<cumulus_primitives_core::relay_chain::HeadData>,
/// The relay block in which this parachain appeared to start. This will be the relay block
/// number in para block #P1
/// number in para block #P1.
pub relay_offset: u32,
/// The number of relay blocks that elapses between each parablock. Probably set this to 1 or 2
/// to simulate optimistic or realistic relay chain behavior.
pub relay_blocks_per_para_block: u32,
/// Number of parachain blocks per relay chain epoch
/// Mock epoch is computed by dividing `current_para_block` by this value.
pub para_blocks_per_relay_epoch: u32,
/// Function to mock BABE one epoch ago randomness
/// Function to mock BABE one epoch ago randomness.
pub relay_randomness_config: R,
/// XCM messages and associated configuration information.
pub xcm_config: MockXcmConfig,
/// Inbound downward XCM messages to be injected into the block.
pub raw_downward_messages: Vec<Vec<u8>>,
// Inbound Horizontal messages sorted by channel
// Inbound Horizontal messages sorted by channel.
pub raw_horizontal_messages: Vec<(ParaId, Vec<u8>)>,
// Additional key-value pairs that should be injected.
pub additional_key_values: Option<Vec<(Vec<u8>, Vec<u8>)>>,
}

/// Something that can generate randomness.
pub trait GenerateRandomness<I> {
/// Generate the randomness using the given `input`.
fn generate_randomness(&self, input: I) -> relay_chain::Hash;
}

Expand All @@ -91,8 +95,6 @@ impl GenerateRandomness<u64> for () {
/// parachain's storage, and the corresponding relay data mocked.
#[derive(Default)]
pub struct MockXcmConfig {
/// The parachain id of the parachain being mocked.
pub para_id: ParaId,
/// The starting state of the dmq_mqc_head.
pub starting_dmq_mqc_head: relay_chain::Hash,
/// The starting state of each parachain's mqc head
Expand All @@ -119,7 +121,6 @@ impl MockXcmConfig {
pub fn new<B: Block, BE: Backend<B>, C: StorageProvider<B, BE>>(
client: &C,
parent_block: B::Hash,
para_id: ParaId,
parachain_system_name: ParachainSystemName,
) -> Self {
let starting_dmq_mqc_head = client
Expand Down Expand Up @@ -152,7 +153,7 @@ impl MockXcmConfig {
})
.unwrap_or_default();

Self { para_id, starting_dmq_mqc_head, starting_hrmp_mqc_heads }
Self { starting_dmq_mqc_head, starting_hrmp_mqc_heads }
}
}

Expand All @@ -166,7 +167,7 @@ impl<R: Send + Sync + GenerateRandomness<u64>> InherentDataProvider
) -> Result<(), sp_inherents::Error> {
// Use the "sproof" (spoof proof) builder to build valid mock state root and proof.
let mut sproof_builder =
RelayStateSproofBuilder { para_id: self.xcm_config.para_id, ..Default::default() };
RelayStateSproofBuilder { para_id: self.para_id, ..Default::default() };

// Calculate the mocked relay block based on the current para block
let relay_parent_number =
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_4555.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: Move `para_id` to `MockValidationDataInherentDataProvider`

doc:
- audience: Node Dev
description: |
This moves the `para_id` from `MockXcmConfig` to `MockValidationDataInherentDataProvider` to make it more prominent. The `para_id` should
be set to the parachain id of the parachain that gets mocked to ensure that the relay chain storage proof is setup correctly etc.

crates:
- name: cumulus-client-parachain-inherent
bump: major

0 comments on commit 5811785

Please sign in to comment.