diff --git a/node/src/consensus/aura_consensus.rs b/node/src/consensus/aura_consensus.rs index 57b5559fd3..16bdae6c01 100644 --- a/node/src/consensus/aura_consensus.rs +++ b/node/src/consensus/aura_consensus.rs @@ -101,6 +101,18 @@ impl ConsensusMechanism for AuraConsensus { fn create_inherent_data_providers( slot_duration: SlotDuration, + ) -> Result> { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + } + + fn pending_create_inherent_data_providers( + slot_duration: SlotDuration, ) -> Result> { let current = sp_timestamp::InherentDataProvider::from_system_time(); let next_slot = current diff --git a/node/src/consensus/babe_consensus.rs b/node/src/consensus/babe_consensus.rs index 42d3022512..490a505f4d 100644 --- a/node/src/consensus/babe_consensus.rs +++ b/node/src/consensus/babe_consensus.rs @@ -121,6 +121,23 @@ impl ConsensusMechanism for BabeConsensus { Ok((slot, timestamp)) } + fn pending_create_inherent_data_providers( + slot_duration: SlotDuration, + ) -> Result> { + let current = sp_timestamp::InherentDataProvider::from_system_time(); + let next_slot = current + .timestamp() + .as_millis() + .saturating_add(slot_duration.as_millis()); + let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into()); + let slot = + sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + } + fn new() -> Self { Self { babe_link: None, diff --git a/node/src/consensus/consensus_mechanism.rs b/node/src/consensus/consensus_mechanism.rs index a500f5efe0..b88e2d0462 100644 --- a/node/src/consensus/consensus_mechanism.rs +++ b/node/src/consensus/consensus_mechanism.rs @@ -87,6 +87,11 @@ pub trait ConsensusMechanism { slot_duration: SlotDuration, ) -> Result>; + /// Creates IDPs for the consensus mechanism for pending blocks. + fn pending_create_inherent_data_providers( + slot_duration: SlotDuration, + ) -> Result>; + /// Creates the frontier consensus data provider with this mechanism. fn frontier_consensus_data_provider( client: Arc, diff --git a/node/src/service.rs b/node/src/service.rs index 9e1c241f34..7b2ee0e75f 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -454,7 +454,7 @@ where let slot_duration = consensus_mechanism.slot_duration(&client)?; let pending_create_inherent_data_providers = - move |_, ()| async move { CM::create_inherent_data_providers(slot_duration) }; + move |_, ()| async move { CM::pending_create_inherent_data_providers(slot_duration) }; let rpc_methods = consensus_mechanism.rpc_methods( client.clone(),