Skip to content

Commit ebddfc7

Browse files
Reintroduce pending_create_inherent_data_providers
1 parent f07ec06 commit ebddfc7

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

node/src/consensus/aura_consensus.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ impl ConsensusMechanism for AuraConsensus {
101101

102102
fn create_inherent_data_providers(
103103
slot_duration: SlotDuration,
104+
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
105+
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
106+
let slot =
107+
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
108+
*timestamp,
109+
slot_duration,
110+
);
111+
Ok((slot, timestamp))
112+
}
113+
114+
fn pending_create_inherent_data_providers(
115+
slot_duration: SlotDuration,
104116
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
105117
let current = sp_timestamp::InherentDataProvider::from_system_time();
106118
let next_slot = current

node/src/consensus/babe_consensus.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ impl ConsensusMechanism for BabeConsensus {
121121
Ok((slot, timestamp))
122122
}
123123

124+
fn pending_create_inherent_data_providers(
125+
slot_duration: SlotDuration,
126+
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
127+
let current = sp_timestamp::InherentDataProvider::from_system_time();
128+
let next_slot = current
129+
.timestamp()
130+
.as_millis()
131+
.saturating_add(slot_duration.as_millis());
132+
let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into());
133+
let slot =
134+
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
135+
*timestamp,
136+
slot_duration,
137+
);
138+
Ok((slot, timestamp))
139+
}
140+
124141
fn new() -> Self {
125142
Self {
126143
babe_link: None,

node/src/consensus/consensus_mechanism.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ pub trait ConsensusMechanism {
8787
slot_duration: SlotDuration,
8888
) -> Result<Self::InherentDataProviders, Box<dyn std::error::Error + Send + Sync>>;
8989

90+
/// Creates IDPs for the consensus mechanism for pending blocks.
91+
fn pending_create_inherent_data_providers(
92+
slot_duration: SlotDuration,
93+
) -> Result<Self::InherentDataProviders, Box<dyn std::error::Error + Send + Sync>>;
94+
9095
/// Creates the frontier consensus data provider with this mechanism.
9196
fn frontier_consensus_data_provider(
9297
client: Arc<FullClient>,

node/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ where
454454

455455
let slot_duration = consensus_mechanism.slot_duration(&client)?;
456456
let pending_create_inherent_data_providers =
457-
move |_, ()| async move { CM::create_inherent_data_providers(slot_duration) };
457+
move |_, ()| async move { CM::pending_create_inherent_data_providers(slot_duration) };
458458

459459
let rpc_methods = consensus_mechanism.rpc_methods(
460460
client.clone(),

0 commit comments

Comments
 (0)