Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions node/src/consensus/aura_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ impl ConsensusMechanism for AuraConsensus {

fn create_inherent_data_providers(
slot_duration: SlotDuration,
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
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<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
let current = sp_timestamp::InherentDataProvider::from_system_time();
let next_slot = current
Expand Down
17 changes: 17 additions & 0 deletions node/src/consensus/babe_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ impl ConsensusMechanism for BabeConsensus {
Ok((slot, timestamp))
}

fn pending_create_inherent_data_providers(
slot_duration: SlotDuration,
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
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,
Expand Down
5 changes: 5 additions & 0 deletions node/src/consensus/consensus_mechanism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ pub trait ConsensusMechanism {
slot_duration: SlotDuration,
) -> Result<Self::InherentDataProviders, Box<dyn std::error::Error + Send + Sync>>;

/// Creates IDPs for the consensus mechanism for pending blocks.
fn pending_create_inherent_data_providers(
slot_duration: SlotDuration,
) -> Result<Self::InherentDataProviders, Box<dyn std::error::Error + Send + Sync>>;

/// Creates the frontier consensus data provider with this mechanism.
fn frontier_consensus_data_provider(
client: Arc<FullClient>,
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading