@@ -4,35 +4,22 @@ use crate::{
44} ;
55use anvil:: eth:: backend:: time:: TimeManager ;
66use polkadot_sdk:: {
7- sc_basic_authorship, sc_consensus, sc_consensus_manual_seal,
8- sc_executor:: WasmExecutor ,
9- sc_network_types:: { self , multiaddr:: Multiaddr } ,
10- sc_rpc_api:: DenyUnsafe ,
11- sc_service:: {
12- self , Configuration , RpcHandlers , SpawnTaskHandle , TaskManager ,
13- error:: Error as ServiceError ,
7+ cumulus_client_parachain_inherent:: MockValidationDataInherentDataProvider ,
8+ cumulus_client_service:: ParachainHostFunctions ,
9+ cumulus_primitives_parachain_inherent:: ParachainInherentData ,
10+ cumulus_test_relay_sproof_builder:: RelayStateSproofBuilder , polkadot_primitives:: { self , Id , PersistedValidationData } , sc_basic_authorship, sc_chain_spec, sc_consensus, sc_consensus_aura, sc_consensus_manual_seal:: { self , consensus:: aura:: AuraConsensusDataProvider } , sc_executor:: WasmExecutor , sc_network_types:: { self , multiaddr:: Multiaddr } , sc_rpc_api:: DenyUnsafe , sc_service:: {
11+ self , error:: Error as ServiceError , Configuration , RpcHandlers , SpawnTaskHandle , TaskManager
1412 } ,
15- sc_transaction_pool:: { self , TransactionPoolWrapper } ,
16- sc_utils:: mpsc:: tracing_unbounded,
17- sc_chain_spec,
18- sp_keystore:: KeystorePtr ,
19- sp_timestamp,
20- substrate_frame_rpc_system:: SystemApiServer ,
21- cumulus_client_service:: ParachainHostFunctions ,
22- cumulus_primitives_parachain_inherent:: ParachainInherentData ,
23- polkadot_primitives:: PersistedValidationData ,
24- cumulus_test_relay_sproof_builder:: RelayStateSproofBuilder ,
13+ sc_transaction_pool:: { self , TransactionPoolWrapper } ,
14+ sp_runtime:: traits:: { Block as BlockT , Header as HeaderT , UniqueSaturatedInto } ,
15+ sc_utils:: mpsc:: tracing_unbounded, sp_keystore:: KeystorePtr , sp_timestamp, substrate_frame_rpc_system:: SystemApiServer
2516} ;
2617use std:: sync:: Arc ;
27- use substrate_runtime:: { OpaqueBlock as Block , RuntimeApi } ;
18+ use substrate_runtime:: { OpaqueBlock as Block , RuntimeApi , Hash } ;
2819use tokio_stream:: wrappers:: ReceiverStream ;
2920use tokio:: runtime:: Builder as TokioRtBuilder ;
30-
31- //use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
32- //use polkadot_primitives::PersistedValidationData;
33- //use cumulus_primitives_parachain_inherent::ParachainInherentData;
34- //use cumulus_primitives_parachain_inherent::v0::ParachainInherentData;
35- //use sp_inherents::{InherentIdentifier, InherentData};
21+ //use substrate_runtime::Hash;
22+ //use crate::substrate_node::service::sc_consensus_manual_seal::consensus::aura::AuraConsensusDataProvider;
3623
3724use serde_json:: { json, Map , Value } ;
3825
@@ -162,6 +149,56 @@ fn build_forked_chainspec_from_raw_top(
162149 Ok ( Box :: new ( new_spec) )
163150}
164151
152+ fn create_manual_seal_inherent_data_providers (
153+ client : Arc < FullClient > ,
154+ para_id : Id ,
155+ slot_duration : sc_consensus_aura:: SlotDuration ,
156+ ) -> impl Fn (
157+ Hash ,
158+ ( ) ,
159+ ) ->
160+ futures:: future:: Ready <
161+ Result <
162+ ( sp_timestamp:: InherentDataProvider , MockValidationDataInherentDataProvider < ( ) > ) ,
163+ Box < dyn std:: error:: Error + Send + Sync > ,
164+ > ,
165+ > + Send
166+ + Sync {
167+ move |block : Hash , ( ) | {
168+ let current_para_head = client
169+ . header ( block)
170+ . expect ( "Header lookup should succeed" )
171+ . expect ( "Header passed in as parent should be present in backend." ) ;
172+
173+ let current_para_block_head =
174+ Some ( polkadot_primitives:: HeadData ( current_para_head. hash ( ) . as_bytes ( ) . to_vec ( ) ) ) ;
175+
176+ let current_block_number =
177+ UniqueSaturatedInto :: < u32 > :: unique_saturated_into ( * current_para_head. number ( ) ) + 1 ;
178+
179+ let mocked_parachain = MockValidationDataInherentDataProvider :: < ( ) > {
180+ current_para_block : current_block_number,
181+ para_id : para_id,
182+ current_para_block_head,
183+ relay_blocks_per_para_block : 1 ,
184+ para_blocks_per_relay_epoch : 10 ,
185+ // upgrade_go_ahead: should_send_go_ahead.then(|| {
186+ // log::info!("Detected pending validation code, sending go-ahead signal.");
187+ // UpgradeGoAhead::GoAhead
188+ // }),
189+ ..Default :: default ( )
190+ } ;
191+
192+ let timestamp_provider = sp_timestamp:: InherentDataProvider :: new (
193+ ( slot_duration. as_millis ( ) * current_block_number as u64 ) . into ( ) ,
194+ ) ;
195+
196+
197+ futures:: future:: ready ( Ok ( ( timestamp_provider, mocked_parachain) ) )
198+ //Ok((timestamp_provider, mocked_parachain))
199+ }
200+ }
201+
165202/// Builds a new service for a full client.
166203pub fn new (
167204 anvil_config : & AnvilNodeConfig ,
@@ -279,38 +316,61 @@ pub fn new(
279316 // }
280317 // };
281318
319+ // Note: Changing slot durations are currently not supported
320+ // let slot_duration = sc_consensus_aura::slot_duration(&*client)
321+ // .expect("slot_duration is always present; qed.");
322+
323+ let slot_duration= sc_consensus_aura:: SlotDuration :: from_millis ( 6000 ) ;
324+
325+ // The aura digest provider will provide digests that match the provided timestamp data.
326+ // Without this, the AURA parachain runtimes complain about slot mismatches.
327+ // let aura_digest_provider = AuraConsensusDataProvider::new(client);
328+
329+ let para_id = Id :: new ( 0 ) ;
330+
331+ let create_inherent_data_providers = create_manual_seal_inherent_data_providers (
332+ client. clone ( ) ,
333+ para_id,
334+ slot_duration,
335+ ) ;
336+
337+ // let create_inherent_data_providers = move |block: Hash, ()| async move {
338+ // let current_para_head = client
339+ // .header(block)
340+ // .expect("Header lookup should succeed")
341+ // .expect("Header passed in as parent should be present in backend.");
342+
343+ // let current_para_block_head =
344+ // Some(polkadot_primitives::HeadData(current_para_head.hash().as_bytes().to_vec()));
282345
283- let create_inherent_data_providers = move |_, _| async move {
284- let time = sp_timestamp:: InherentDataProvider :: from_system_time ( ) ;
285- // Create a dummy parachain inherent data provider which is required to pass
286- // the checks by the para chain system. We use dummy values because in the 'pending context'
287- // neither do we have access to the real values nor do we need them.
288- let ( relay_parent_storage_root, relay_chain_state) =
289- RelayStateSproofBuilder :: default ( ) . into_state_root_and_proof ( ) ;
290- let vfp = PersistedValidationData {
291- // This is a hack to make `cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases`
292- // happy. Relay parent number can't be bigger than u32::MAX.
293- relay_parent_number : u32:: MAX ,
294- relay_parent_storage_root,
295- ..Default :: default ( )
296- } ;
297-
298- // parachain_inherent::BasicParachainInherentData::
299-
300- let parachain_inherent_data = ParachainInherentData {
301- validation_data : vfp,
302- relay_chain_state,
303- downward_messages : Default :: default ( ) ,
304- horizontal_messages : Default :: default ( ) ,
305- relay_parent_descendants : Vec :: new ( ) ,
306- collator_peer_id : None ,
307- } ;
308- Ok ( ( time, parachain_inherent_data) )
309- } ;
310-
311-
312- // let create_inherent_data_providers = move |_, _| async move {
313- // let time = sp_timestamp::InherentDataProvider::from_system_time();
346+ // let current_block_number =
347+ // UniqueSaturatedInto::<u32>::unique_saturated_into(*current_para_head.number()) + 1;
348+
349+ // let mocked_parachain = MockValidationDataInherentDataProvider::<()> {
350+ // current_para_block: 0,
351+ // para_id: para_id,
352+ // current_para_block_head,
353+ // relay_blocks_per_para_block: 1,
354+ // para_blocks_per_relay_epoch: 10,
355+ // // upgrade_go_ahead: should_send_go_ahead.then(|| {
356+ // // log::info!("Detected pending validation code, sending go-ahead signal.");
357+ // // UpgradeGoAhead::GoAhead
358+ // // }),
359+ // ..Default::default()
360+ // };
361+
362+ // let timestamp_provider = sp_timestamp::InherentDataProvider::new(
363+ // (slot_duration.as_millis() * current_block_number as u64).into(),
364+ // );
365+
366+
367+ // Ok((timestamp_provider, mocked_parachain))
368+ // };
369+
370+
371+ // let create_inherent_data_providers = move |_, _| async move {
372+ // //let time = sp_timestamp::InherentDataProvider::from_system_time();
373+ // let time = sp_timestamp::InherentDataProvider::new(sp_timestamp::Timestamp::new(0));
314374 // // Create a dummy parachain inherent data provider which is required to pass
315375 // // the checks by the para chain system. We use dummy values because in the 'pending context'
316376 // // neither do we have access to the real values nor do we need them.
@@ -323,11 +383,14 @@ pub fn new(
323383 // relay_parent_storage_root,
324384 // ..Default::default()
325385 // };
386+
326387 // let parachain_inherent_data = ParachainInherentData {
327388 // validation_data: vfp,
328389 // relay_chain_state,
329390 // downward_messages: Default::default(),
330391 // horizontal_messages: Default::default(),
392+ // relay_parent_descendants: Vec::new(),
393+ // collator_peer_id: None,
331394 // };
332395 // Ok((time, parachain_inherent_data))
333396 // };
0 commit comments