mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 22:41:06 +00:00
consensus-slots: cleanup SlotDuration config (#10878)
* consensus-slots: cleanup the SlotDuration config * fix tests * address review comments
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user