diff --git a/node/e2e-tests/test-service/src/service.rs b/node/e2e-tests/test-service/src/service.rs index fe7a4b065..f09aad3c8 100644 --- a/node/e2e-tests/test-service/src/service.rs +++ b/node/e2e-tests/test-service/src/service.rs @@ -20,6 +20,7 @@ #![allow(clippy::too_many_arguments)] use super::*; +use cumulus_primitives_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig}; /// Starts a `ServiceBuilder` for a full service. /// @@ -75,6 +76,7 @@ pub fn new_partial( SealMode::DevAuraSeal => { // aura import queue let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); + let client_for_cidp = client.clone(); ( sc_consensus_aura::import_queue::( @@ -82,19 +84,38 @@ pub fn new_partial( block_import: client.clone(), justification_import: None, client: client.clone(), - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - slot_duration, - ); - - Ok(( - timestamp, - slot, - node_service::default_mock_parachain_inherent_data_provider(), - )) + create_inherent_data_providers: move |block: Hash, ()| { + let current_para_block = client_for_cidp + .number(block) + .expect("Header lookup should succeed") + .expect("Header passed in as parent should be present in backend."); + let client_for_xcm = client_for_cidp.clone(); + + async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); + + let mocked_parachain = MockValidationDataInherentDataProvider { + current_para_block, + relay_offset: 1000, + relay_blocks_per_para_block: 2, + xcm_config: MockXcmConfig::new( + &*client_for_xcm, + block, + Default::default(), + Default::default(), + ), + raw_downward_messages: vec![], + raw_horizontal_messages: vec![], + }; + + Ok((timestamp, slot, mocked_parachain)) + } }, spawner: &task_manager.spawn_essential_handle(), registry, @@ -244,6 +265,8 @@ pub async fn start_dev_node( // aura let can_author_with = sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()); let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); + let client_for_cidp = client.clone(); + let aura = sc_consensus_aura::start_aura::< sp_consensus_aura::sr25519::AuthorityPair, _, @@ -264,19 +287,37 @@ pub async fn start_dev_node( // block_import: instant_finalize::InstantFinalizeBlockImport::new(client.clone()), block_import: client.clone(), proposer_factory, - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - slot_duration, - ); - - Ok(( - timestamp, - slot, - node_service::default_mock_parachain_inherent_data_provider(), - )) + create_inherent_data_providers: move |block: Hash, ()| { + let current_para_block = client_for_cidp + .number(block) + .expect("Header lookup should succeed") + .expect("Header passed in as parent should be present in backend."); + let client_for_xcm = client_for_cidp.clone(); + + async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); + + let mocked_parachain = MockValidationDataInherentDataProvider { + current_para_block, + relay_offset: 1000, + relay_blocks_per_para_block: 2, + xcm_config: MockXcmConfig::new( + &*client_for_xcm, + block, + Default::default(), + Default::default(), + ), + raw_downward_messages: vec![], + raw_horizontal_messages: vec![], + }; + + Ok((timestamp, slot, mocked_parachain)) + } }, force_authoring, backoff_authoring_blocks, diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 49e1c20bc..9b94378e8 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -32,7 +32,7 @@ use cumulus_relay_chain_interface::RelayChainInterface; use cumulus_relay_chain_local::build_relay_chain_interface; use acala_primitives::{Block, Hash}; -use cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider; +use cumulus_primitives_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig}; use sc_client_api::ExecutorProvider; use sc_consensus::LongestChain; use sc_consensus_aura::ImportQueueParams; @@ -56,6 +56,7 @@ pub use sc_service::{ ChainSpec, }; pub use sp_api::ConstructRuntimeApi; +use sp_blockchain::HeaderBackend; pub mod chain_spec; mod client; @@ -268,20 +269,43 @@ where } else { // aura import queue let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); + let client_for_cidp = client.clone(); sc_consensus_aura::import_queue::(ImportQueueParams { block_import: client.clone(), justification_import: None, client: client.clone(), - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + create_inherent_data_providers: move |block: Hash, ()| { + let current_para_block = client_for_cidp + .number(block) + .expect("Header lookup should succeed") + .expect("Header passed in as parent should be present in backend."); + let client_for_xcm = client_for_cidp.clone(); - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - slot_duration, - ); + async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); - Ok((timestamp, slot, default_mock_parachain_inherent_data_provider())) + let mocked_parachain = MockValidationDataInherentDataProvider { + current_para_block, + relay_offset: 1000, + relay_blocks_per_para_block: 2, + xcm_config: MockXcmConfig::new( + &*client_for_xcm, + block, + Default::default(), + Default::default(), + ), + raw_downward_messages: vec![], + raw_horizontal_messages: vec![], + }; + + Ok((timestamp, slot, mocked_parachain)) + } }, spawner: &task_manager.spawn_essential_handle(), registry, @@ -724,6 +748,8 @@ fn inner_mandala_dev(config: Configuration, instant_sealing: bool) -> Result Result Result(StartAuraParams { slot_duration: sc_consensus_aura::slot_duration(&*client)?, client: client.clone(), select_chain, block_import: instant_finalize::InstantFinalizeBlockImport::new(client.clone()), proposer_factory, - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + create_inherent_data_providers: move |block: Hash, ()| { + let current_para_block = client_for_cidp + .number(block) + .expect("Header lookup should succeed") + .expect("Header passed in as parent should be present in backend."); + let client_for_xcm = client_for_cidp.clone(); - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - slot_duration, - ); + async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - Ok((timestamp, slot, default_mock_parachain_inherent_data_provider())) + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); + + let mocked_parachain = MockValidationDataInherentDataProvider { + current_para_block, + relay_offset: 1000, + relay_blocks_per_para_block: 2, + xcm_config: MockXcmConfig::new( + &*client_for_xcm, + block, + Default::default(), + Default::default(), + ), + raw_downward_messages: vec![], + raw_horizontal_messages: vec![], + }; + + Ok((timestamp, slot, mocked_parachain)) + } }, force_authoring, backoff_authoring_blocks,