diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 69030e5357..6d255ea2f4 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -6103,9 +6103,9 @@ version = "2.0.0" dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-application-crypto 2.0.0", - "sc-consensus-slots 2.0.0", "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", + "sp-consensus 2.0.0", "sp-inherents 2.0.0", "sp-runtime 2.0.0", "sp-std 2.0.0", diff --git a/substrate/client/consensus/aura/src/lib.rs b/substrate/client/consensus/aura/src/lib.rs index e07ab5f99a..745c0bebe2 100644 --- a/substrate/client/consensus/aura/src/lib.rs +++ b/substrate/client/consensus/aura/src/lib.rs @@ -33,7 +33,7 @@ use std::{sync::Arc, time::Duration, thread, marker::PhantomData, hash::Hash, fm use codec::{Encode, Decode, Codec}; use consensus_common::{ self, BlockImport, Environment, Proposer, CanAuthorWith, ForkChoiceStrategy, BlockImportParams, - BlockOrigin, Error as ConsensusError, SelectChain, + BlockOrigin, Error as ConsensusError, SelectChain, SlotData, }; use consensus_common::import_queue::{ Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport, @@ -65,7 +65,7 @@ use sp_timestamp::{ use sc_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_INFO}; -use slots::{CheckedHeader, SlotData, SlotWorker, SlotInfo, SlotCompatible}; +use slots::{CheckedHeader, SlotWorker, SlotInfo, SlotCompatible}; use slots::check_equivocation; use keystore::KeyStorePtr; diff --git a/substrate/client/consensus/babe/src/lib.rs b/substrate/client/consensus/babe/src/lib.rs index de0efbbcc8..9bdc08b883 100644 --- a/substrate/client/consensus/babe/src/lib.rs +++ b/substrate/client/consensus/babe/src/lib.rs @@ -82,10 +82,10 @@ use sc_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG}; use consensus_common::{ self, BlockImport, Environment, Proposer, BlockCheckParams, ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError, + SelectChain, SlotData, }; use babe_primitives::inherents::BabeInherentData; use sp_timestamp::{TimestampInherentData, InherentType as TimestampInherent}; -use consensus_common::SelectChain; use consensus_common::import_queue::{Verifier, BasicQueue, CacheKeyId}; use client_api::{ backend::{AuxStore, Backend}, @@ -99,7 +99,7 @@ use block_builder_api::BlockBuilder as BlockBuilderApi; use slots::{CheckedHeader, check_equivocation}; use futures::prelude::*; use log::{warn, debug, info, trace}; -use slots::{SlotWorker, SlotData, SlotInfo, SlotCompatible}; +use slots::{SlotWorker, SlotInfo, SlotCompatible}; use epoch_changes::descendent_query; use sp_blockchain::{ Result as ClientResult, Error as ClientError, diff --git a/substrate/client/consensus/slots/src/lib.rs b/substrate/client/consensus/slots/src/lib.rs index e6a5361c2f..e95974fb92 100644 --- a/substrate/client/consensus/slots/src/lib.rs +++ b/substrate/client/consensus/slots/src/lib.rs @@ -31,7 +31,7 @@ use slots::Slots; pub use aux_schema::{check_equivocation, MAX_SLOT_CAPACITY, PRUNING_BOUND}; use codec::{Decode, Encode}; -use consensus_common::{BlockImport, Proposer, SyncOracle, SelectChain, CanAuthorWith}; +use consensus_common::{BlockImport, Proposer, SyncOracle, SelectChain, CanAuthorWith, SlotData}; use futures::{prelude::*, future::{self, Either}}; use futures_timer::Delay; use inherents::{InherentData, InherentDataProviders}; @@ -386,23 +386,6 @@ pub enum CheckedHeader { Checked(H, S), } -/// A type from which a slot duration can be obtained. -pub trait SlotData { - /// Gets the slot duration. - fn slot_duration(&self) -> u64; - - /// The static slot key - const SLOT_KEY: &'static [u8]; -} - -impl SlotData for u64 { - fn slot_duration(&self) -> u64 { - *self - } - - const SLOT_KEY: &'static [u8] = b"aura_slot_duration"; -} - /// A slot duration. Create with `get_or_compute`. // The internal member should stay private here to maintain invariants of // `get_or_compute`. diff --git a/substrate/primitives/consensus/babe/Cargo.toml b/substrate/primitives/consensus/babe/Cargo.toml index 645ea5b44e..d4d867c373 100644 --- a/substrate/primitives/consensus/babe/Cargo.toml +++ b/substrate/primitives/consensus/babe/Cargo.toml @@ -10,10 +10,10 @@ app-crypto = { package = "sc-application-crypto", path = "../../application-cryp codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } rstd = { package = "sp-std", path = "../../sr-std", default-features = false } schnorrkel = { version = "0.8.5", features = ["preaudit_deprecated"], optional = true } -slots = { package = "sc-consensus-slots", path = "../../../client/consensus/slots", optional = true } sp-api = { path = "../../sr-api", default-features = false } -sp-runtime = { path = "../../runtime", default-features = false } +sp-consensus = { path = "../common", optional = true } sp-inherents = { package = "sp-inherents", path = "../../inherents", default-features = false } +sp-runtime = { path = "../../runtime", default-features = false } sp-timestamp = { path = "../../timestamp", default-features = false } [features] @@ -23,9 +23,9 @@ std = [ "codec/std", "rstd/std", "schnorrkel", - "slots", "sp-api/std", - "sp-runtime/std", + "sp-consensus", "sp-inherents/std", + "sp-runtime/std", "sp-timestamp/std", ] diff --git a/substrate/primitives/consensus/babe/src/lib.rs b/substrate/primitives/consensus/babe/src/lib.rs index cf4bfd1e98..552b841733 100644 --- a/substrate/primitives/consensus/babe/src/lib.rs +++ b/substrate/primitives/consensus/babe/src/lib.rs @@ -157,7 +157,7 @@ pub struct BabeConfiguration { } #[cfg(feature = "std")] -impl slots::SlotData for BabeConfiguration { +impl sp_consensus::SlotData for BabeConfiguration { fn slot_duration(&self) -> u64 { self.slot_duration } diff --git a/substrate/primitives/consensus/common/src/lib.rs b/substrate/primitives/consensus/common/src/lib.rs index 3545083a42..cc5d0105ad 100644 --- a/substrate/primitives/consensus/common/src/lib.rs +++ b/substrate/primitives/consensus/common/src/lib.rs @@ -181,3 +181,20 @@ impl CanAuthorWith for AlwaysCanAuthor { Ok(()) } } + +/// A type from which a slot duration can be obtained. +pub trait SlotData { + /// Gets the slot duration. + fn slot_duration(&self) -> u64; + + /// The static slot key + const SLOT_KEY: &'static [u8]; +} + +impl SlotData for u64 { + fn slot_duration(&self) -> u64 { + *self + } + + const SLOT_KEY: &'static [u8] = b"aura_slot_duration"; +}