Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit c622bc8

Browse files
Seun Lanlegenazar-pc
authored andcommitted
Use correct CreateInherentDataProviders impl for manual seal (paritytech#8852)
* use correct CreateInherentDataProviders impl for manual seal * add babe inherent provider * move client into factory fn
1 parent 554486d commit c622bc8

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

bin/node/test-runner-example/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use sc_consensus_babe::BabeBlockImport;
2727
use sp_keystore::SyncCryptoStorePtr;
2828
use sp_keyring::sr25519::Keyring::Alice;
2929
use sp_consensus_babe::AuthorityId;
30-
use sc_consensus_manual_seal::{ConsensusDataProvider, consensus::babe::BabeConsensusDataProvider};
30+
use sc_consensus_manual_seal::{
31+
ConsensusDataProvider, consensus::babe::{BabeConsensusDataProvider, SlotTimestampProvider},
32+
};
3133
use sp_runtime::{traits::IdentifyAccount, MultiSigner, generic::Era};
3234
use node_cli::chain_spec::development_config;
3335

@@ -59,10 +61,7 @@ impl ChainInfo for NodeTemplateChainInfo {
5961
Self::SelectChain,
6062
>;
6163
type SignedExtras = node_runtime::SignedExtra;
62-
type InherentDataProviders = (
63-
sp_timestamp::InherentDataProvider,
64-
sp_consensus_babe::inherents::InherentDataProvider,
65-
);
64+
type InherentDataProviders = (SlotTimestampProvider, sp_consensus_babe::inherents::InherentDataProvider);
6665

6766
fn signed_extras(from: <Self::Runtime as frame_system::Config>::AccountId) -> Self::SignedExtras {
6867
(
@@ -139,20 +138,16 @@ impl ChainInfo for NodeTemplateChainInfo {
139138
.expect("failed to create ConsensusDataProvider");
140139

141140
Ok((
142-
client,
141+
client.clone(),
143142
backend,
144143
keystore.sync_keystore(),
145144
task_manager,
146145
Box::new(move |_, _| {
147-
let slot_duration = slot_duration.clone();
146+
let client = client.clone();
148147
async move {
149-
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
150-
let slot = sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_duration(
151-
*timestamp,
152-
slot_duration.slot_duration(),
153-
);
154-
155-
Ok((timestamp, slot))
148+
let timestamp = SlotTimestampProvider::new(client.clone()).map_err(|err| format!("{:?}", err))?;
149+
let babe = sp_consensus_babe::inherents::InherentDataProvider::new(timestamp.slot().into());
150+
Ok((timestamp, babe))
156151
}
157152
}),
158153
Some(Box::new(consensus_data_provider)),

client/consensus/manual-seal/src/consensus/babe.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl SlotTimestampProvider {
268268

269269
// looks like this isn't the first block, rehydrate the fake time.
270270
// otherwise we'd be producing blocks for older slots.
271-
let duration = if info.best_number != Zero::zero() {
271+
let time = if info.best_number != Zero::zero() {
272272
let header = client.header(BlockId::Hash(info.best_hash))?.unwrap();
273273
let slot = find_pre_digest::<B>(&header).unwrap().slot();
274274
// add the slot duration so there's no collision of slots
@@ -282,10 +282,15 @@ impl SlotTimestampProvider {
282282
};
283283

284284
Ok(Self {
285-
time: atomic::AtomicU64::new(duration),
285+
time: atomic::AtomicU64::new(time),
286286
slot_duration,
287287
})
288288
}
289+
290+
/// Get the current slot number
291+
pub fn slot(&self) -> u64 {
292+
self.time.load(atomic::Ordering::SeqCst) / self.slot_duration
293+
}
289294
}
290295

291296
#[async_trait::async_trait]

client/consensus/manual-seal/src/seal_block.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ pub async fn seal_block<B, BI, SC, C, E, P, CIDP>(
111111

112112
let inherent_data_providers =
113113
create_inherent_data_providers
114-
.create_inherent_data_providers(
115-
parent.hash(),
116-
(),
117-
)
114+
.create_inherent_data_providers(parent.hash(), ())
118115
.await
119116
.map_err(|e| Error::Other(e))?;
120117

0 commit comments

Comments
 (0)