Skip to content
Snippets Groups Projects
Unverified Commit 2b1c606a authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

parachain-inherent: Make `para_id` more prominent (#4555)

This should make it more obvious that at instantiation of the
`MockValidationDataInherentDataProvider` the `para_id` needs to be
passed.
parent ad22fa6e
No related merge requests found
Pipeline #478799 waiting for manual action with stages
in 1 hour, 15 minutes, and 10 seconds
......@@ -46,12 +46,14 @@ 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.
......@@ -59,19 +61,21 @@ pub struct MockValidationDataInherentDataProvider<R = ()> {
/// 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;
}
......@@ -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
......@@ -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
......@@ -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 }
}
}
......@@ -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 =
......
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% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment