consensus-slots: cleanup SlotDuration config (#10878)

* consensus-slots: cleanup the SlotDuration config

* fix tests

* address review comments
This commit is contained in:
André Silva
2022-02-22 19:39:16 +00:00
committed by GitHub
parent f00404bfd6
commit 2561e11ed7
19 changed files with 161 additions and 191 deletions
+8 -13
View File
@@ -77,14 +77,11 @@ pub use sp_consensus::SyncOracle;
pub use sp_consensus_aura::{
digests::CompatibleDigestItem,
inherents::{InherentDataProvider, InherentType as AuraInherent, INHERENT_IDENTIFIER},
AuraApi, ConsensusLog, AURA_ENGINE_ID,
AuraApi, ConsensusLog, SlotDuration, AURA_ENGINE_ID,
};
type AuthorityId<P> = <P as Pair>::Public;
/// Slot duration type for Aura.
pub type SlotDuration = sc_consensus_slots::SlotDuration<sp_consensus_aura::SlotDuration>;
/// Get the slot duration for Aura.
pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration>
where
@@ -94,9 +91,7 @@ where
C::Api: AuraApi<B, A>,
{
let best_block_id = BlockId::Hash(client.usage_info().chain.best_hash);
let slot_duration = client.runtime_api().slot_duration(&best_block_id)?;
Ok(SlotDuration::new(slot_duration))
client.runtime_api().slot_duration(&best_block_id).map_err(|err| err.into())
}
/// Get slot author for given block along with authorities.
@@ -574,7 +569,7 @@ mod tests {
use sc_network_test::{Block as TestBlock, *};
use sp_application_crypto::key_types::AURA;
use sp_consensus::{
AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal, SlotData,
AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal,
};
use sp_consensus_aura::sr25519::AuthorityPair;
use sp_inherents::InherentData;
@@ -672,14 +667,14 @@ mod tests {
let client = client.as_client();
let slot_duration = slot_duration(&*client).expect("slot duration available");
assert_eq!(slot_duration.slot_duration().as_millis() as u64, SLOT_DURATION);
assert_eq!(slot_duration.as_millis() as u64, SLOT_DURATION);
import_queue::AuraVerifier::new(
client,
Box::new(|_, _| async {
let timestamp = TimestampInherentDataProvider::from_system_time();
let slot = InherentDataProvider::from_timestamp_and_duration(
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
Duration::from_secs(6),
SlotDuration::from_millis(6000),
);
Ok((timestamp, slot))
@@ -762,9 +757,9 @@ mod tests {
justification_sync_link: (),
create_inherent_data_providers: |_, _| async {
let timestamp = TimestampInherentDataProvider::from_system_time();
let slot = InherentDataProvider::from_timestamp_and_duration(
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
Duration::from_secs(6),
SlotDuration::from_millis(6000),
);
Ok((timestamp, slot))