[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
+14 -14
View File
@@ -6,38 +6,38 @@ description = "Aura consensus algorithm for substrate"
edition = "2018"
[dependencies]
app-crypto = { package = "sp-application-crypto", path = "../../../primitives/application-crypto" }
aura_primitives = { package = "sp-consensus-aura", path = "../../../primitives/consensus/aura" }
block-builder-api = { package = "sp-block-builder", path = "../../../primitives/block-builder" }
client = { package = "sc-client", path = "../../" }
client-api = { package = "sc-client-api", path = "../../api" }
sp-application-crypto = { path = "../../../primitives/application-crypto" }
sp-consensus-aura = { path = "../../../primitives/consensus/aura" }
sp-block-builder = { path = "../../../primitives/block-builder" }
sc-client = { path = "../../" }
sc-client-api = { path = "../../api" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
consensus_common = { package = "sp-consensus", path = "../../../primitives/consensus/common" }
sp-consensus = { path = "../../../primitives/consensus/common" }
derive_more = "0.99.2"
futures = { version = "0.3.1", features = ["compat"] }
futures01 = { package = "futures", version = "0.1" }
futures-timer = "0.4.0"
inherents = { package = "sp-inherents", path = "../../../primitives/inherents" }
keystore = { package = "sc-keystore", path = "../../keystore" }
sp-inherents = { path = "../../../primitives/inherents" }
sc-keystore = { path = "../../keystore" }
log = "0.4.8"
parking_lot = "0.9.0"
primitives = { package = "sp-core", path = "../../../primitives/core" }
sp-core = { path = "../../../primitives/core" }
sp-blockchain = { path = "../../../primitives/blockchain" }
sp-io = { path = "../../../primitives/io" }
runtime_version = { package = "sp-version", path = "../../../primitives/version" }
slots = { package = "sc-consensus-slots", path = "../slots" }
sp-version = { path = "../../../primitives/version" }
sc-consensus-slots = { path = "../slots" }
sp-api = { path = "../../../primitives/api" }
sp-runtime = { path = "../../../primitives/runtime" }
sp-timestamp = { path = "../../../primitives/timestamp" }
sc-telemetry = { path = "../../telemetry" }
[dev-dependencies]
keyring = { package = "sp-keyring", path = "../../../primitives/keyring" }
sp-keyring = { path = "../../../primitives/keyring" }
sc-executor = { path = "../../executor" }
sc-network = { path = "../../network" }
sc-network-test = { path = "../../network/test" }
service = { package = "sc-service", path = "../../service" }
test-client = { package = "substrate-test-runtime-client", path = "../../../test-utils/runtime/client" }
sc-service = { path = "../../service" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" }
tokio = "0.1.22"
env_logger = "0.7.0"
tempfile = "3.1.0"
@@ -19,8 +19,8 @@
//! This implements the digests for AuRa, to allow the private
//! `CompatibleDigestItem` trait to appear in public interfaces.
use primitives::Pair;
use aura_primitives::AURA_ENGINE_ID;
use sp_core::Pair;
use sp_consensus_aura::AURA_ENGINE_ID;
use sp_runtime::generic::{DigestItem, OpaqueDigestItemId};
use codec::{Encode, Codec};
use std::fmt::Debug;
+48 -49
View File
@@ -31,28 +31,28 @@
use std::{sync::Arc, time::Duration, thread, marker::PhantomData, hash::Hash, fmt::Debug, pin::Pin};
use codec::{Encode, Decode, Codec};
use consensus_common::{
use sp_consensus::{
self, BlockImport, Environment, Proposer, CanAuthorWith, ForkChoiceStrategy, BlockImportParams,
BlockOrigin, Error as ConsensusError, SelectChain, SlotData,
};
use consensus_common::import_queue::{
use sp_consensus::import_queue::{
Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
};
use client_api::backend::AuxStore;
use client::{
use sc_client_api::backend::AuxStore;
use sc_client::{
blockchain::ProvideCache, BlockOf
};
use sp_blockchain::{
Result as CResult, well_known_cache_keys::{self, Id as CacheKeyId},
};
use block_builder_api::BlockBuilder as BlockBuilderApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_runtime::{generic::{BlockId, OpaqueDigestItemId}, Justification};
use sp_runtime::traits::{Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, Zero, Member};
use primitives::crypto::Pair;
use inherents::{InherentDataProviders, InherentData};
use sp_core::crypto::Pair;
use sp_inherents::{InherentDataProviders, InherentData};
use futures::prelude::*;
use parking_lot::Mutex;
@@ -65,21 +65,21 @@ use sp_timestamp::{
use sc_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_INFO};
use slots::{CheckedHeader, SlotWorker, SlotInfo, SlotCompatible};
use slots::check_equivocation;
use sc_consensus_slots::{CheckedHeader, SlotWorker, SlotInfo, SlotCompatible};
use sc_consensus_slots::check_equivocation;
use keystore::KeyStorePtr;
use sc_keystore::KeyStorePtr;
use sp_api::ApiExt;
pub use aura_primitives::{
pub use sp_consensus_aura::{
ConsensusLog, AuraApi, AURA_ENGINE_ID,
inherents::{
InherentType as AuraInherent,
AuraInherentData, INHERENT_IDENTIFIER, InherentDataProvider,
},
};
pub use consensus_common::SyncOracle;
pub use sp_consensus::SyncOracle;
pub use digest::CompatibleDigestItem;
mod digest;
@@ -88,7 +88,7 @@ type AuthorityId<P> = <P as Pair>::Public;
/// A slot duration. Create with `get_or_compute`.
#[derive(Clone, Copy, Debug, Encode, Decode, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct SlotDuration(slots::SlotDuration<u64>);
pub struct SlotDuration(sc_consensus_slots::SlotDuration<u64>);
impl SlotDuration {
/// Either fetch the slot duration from disk or compute it from the genesis
@@ -100,7 +100,7 @@ impl SlotDuration {
C: AuxStore + ProvideRuntimeApi,
C::Api: AuraApi<B, A, Error = sp_blockchain::Error>,
{
slots::SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b)).map(Self)
sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b)).map(Self)
}
/// Get the slot duration in milliseconds.
@@ -133,11 +133,11 @@ impl SlotCompatible for AuraSlotCompatible {
fn extract_timestamp_and_slot(
&self,
data: &InherentData
) -> Result<(TimestampInherent, AuraInherent, std::time::Duration), consensus_common::Error> {
) -> Result<(TimestampInherent, AuraInherent, std::time::Duration), sp_consensus::Error> {
data.timestamp_inherent_data()
.and_then(|t| data.aura_inherent_data().map(|a| (t, a)))
.map_err(Into::into)
.map_err(consensus_common::Error::InherentData)
.map_err(sp_consensus::Error::InherentData)
.map(|(x, y)| (x, y, Default::default()))
}
}
@@ -154,7 +154,7 @@ pub fn start_aura<B, C, SC, E, I, P, SO, CAW, Error, H>(
force_authoring: bool,
keystore: KeyStorePtr,
can_author_with: CAW,
) -> Result<impl futures01::Future<Item = (), Error = ()>, consensus_common::Error> where
) -> Result<impl futures01::Future<Item = (), Error = ()>, sp_consensus::Error> where
B: BlockT<Header=H>,
C: ProvideRuntimeApi + BlockOf + ProvideCache<B> + AuxStore + Send + Sync,
C::Api: AuraApi<B, AuthorityId<P>>,
@@ -167,7 +167,7 @@ pub fn start_aura<B, C, SC, E, I, P, SO, CAW, Error, H>(
P::Signature: Hash + Member + Encode + Decode,
H: Header<Hash=B::Hash>,
I: BlockImport<B> + Send + Sync + 'static,
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: ::std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
SO: SyncOracle + Send + Sync + Clone,
CAW: CanAuthorWith<B> + Send,
{
@@ -184,7 +184,7 @@ pub fn start_aura<B, C, SC, E, I, P, SO, CAW, Error, H>(
&inherent_data_providers,
slot_duration.0.slot_duration()
)?;
Ok(slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible, _>(
Ok(sc_consensus_slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible, _>(
slot_duration.0,
select_chain,
worker,
@@ -205,7 +205,7 @@ struct AuraWorker<C, E, I, P, SO> {
_key_type: PhantomData<P>,
}
impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E, I, P, SO> where
impl<H, B, C, E, I, P, Error, SO> sc_consensus_slots::SimpleSlotWorker<B> for AuraWorker<C, E, I, P, SO> where
B: BlockT<Header=H>,
C: ProvideRuntimeApi + BlockOf + ProvideCache<B> + Sync,
C::Api: AuraApi<B, AuthorityId<P>>,
@@ -218,7 +218,7 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
P::Public: Member + Encode + Decode + Hash,
P::Signature: Member + Encode + Decode + Hash + Debug,
SO: SyncOracle + Send + Clone,
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: ::std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
{
type EpochData = Vec<AuthorityId<P>>;
type Claim = P;
@@ -234,7 +234,7 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
self.block_import.clone()
}
fn epoch_data(&self, header: &B::Header, _slot_number: u64) -> Result<Self::EpochData, consensus_common::Error> {
fn epoch_data(&self, header: &B::Header, _slot_number: u64) -> Result<Self::EpochData, sp_consensus::Error> {
authorities(self.client.as_ref(), &BlockId::Hash(header.hash()))
}
@@ -252,7 +252,7 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
expected_author.and_then(|p| {
self.keystore.read()
.key_pair_by_type::<P>(&p, app_crypto::key_types::AURA).ok()
.key_pair_by_type::<P>(&p, sp_application_crypto::key_types::AURA).ok()
})
}
@@ -267,7 +267,7 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
&B::Hash,
Vec<B::Extrinsic>,
Self::Claim,
) -> consensus_common::BlockImportParams<B> + Send> {
) -> sp_consensus::BlockImportParams<B> + Send> {
Box::new(|header, header_hash, body, pair| {
// sign the pre-sealed hash of the block and then
// add it to a digest item.
@@ -297,9 +297,9 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
&mut self.sync_oracle
}
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, consensus_common::Error> {
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, sp_consensus::Error> {
self.env.init(block).map_err(|e| {
consensus_common::Error::ClientImport(format!("{:?}", e)).into()
sp_consensus::Error::ClientImport(format!("{:?}", e)).into()
})
}
@@ -343,12 +343,12 @@ impl<H, B: BlockT, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I,
P::Public: Member + Encode + Decode + Hash,
P::Signature: Member + Encode + Decode + Hash + Debug,
SO: SyncOracle + Send + Sync + Clone,
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: ::std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
{
type OnSlot = Pin<Box<dyn Future<Output = Result<(), consensus_common::Error>> + Send>>;
type OnSlot = Pin<Box<dyn Future<Output = Result<(), sp_consensus::Error>> + Send>>;
fn on_slot(&mut self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot {
<Self as slots::SimpleSlotWorker<B>>::on_slot(self, chain_head, slot_info)
<Self as sc_consensus_slots::SimpleSlotWorker<B>>::on_slot(self, chain_head, slot_info)
}
}
@@ -416,7 +416,7 @@ fn check_header<C, B: BlockT, P: Pair, T>(
) -> Result<CheckedHeader<B::Header, (u64, DigestItemFor<B>)>, Error<B>> where
DigestItemFor<B>: CompatibleDigestItem<P>,
P::Signature: Decode,
C: client_api::backend::AuxStore,
C: sc_client_api::backend::AuxStore,
P::Public: Encode + Decode + PartialEq + Clone,
T: Send + Sync + 'static,
{
@@ -471,7 +471,7 @@ fn check_header<C, B: BlockT, P: Pair, T>(
pub struct AuraVerifier<C, P, T> {
client: Arc<C>,
phantom: PhantomData<P>,
inherent_data_providers: inherents::InherentDataProviders,
inherent_data_providers: sp_inherents::InherentDataProviders,
transaction_pool: Option<Arc<T>>,
}
@@ -531,7 +531,7 @@ impl<C, P, T> AuraVerifier<C, P, T>
#[forbid(deprecated)]
impl<B: BlockT, C, P, T> Verifier<B> for AuraVerifier<C, P, T> where
C: ProvideRuntimeApi + Send + Sync + client_api::backend::AuxStore + ProvideCache<B> + BlockOf,
C: ProvideRuntimeApi + Send + Sync + sc_client_api::backend::AuxStore + ProvideCache<B> + BlockOf,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B, Error = sp_blockchain::Error>,
DigestItemFor<B>: CompatibleDigestItem<P>,
P: Pair + Send + Sync + 'static,
@@ -661,7 +661,7 @@ fn initialize_authorities_cache<A, B, C>(client: &C) -> Result<(), ConsensusErro
return Ok(());
}
let map_err = |error| consensus_common::Error::from(consensus_common::Error::ClientImport(
let map_err = |error| sp_consensus::Error::from(sp_consensus::Error::ClientImport(
format!(
"Error initializing authorities cache: {}",
error,
@@ -687,7 +687,7 @@ fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, Consensus
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok())
)
.or_else(|| AuraApi::authorities(&*client.runtime_api(), at).ok())
.ok_or_else(|| consensus_common::Error::InvalidAuthoritiesSet.into())
.ok_or_else(|| sp_consensus::Error::InvalidAuthoritiesSet.into())
}
/// The Aura import queue type.
@@ -697,12 +697,12 @@ pub type AuraImportQueue<B> = BasicQueue<B>;
fn register_aura_inherent_data_provider(
inherent_data_providers: &InherentDataProviders,
slot_duration: u64,
) -> Result<(), consensus_common::Error> {
) -> Result<(), sp_consensus::Error> {
if !inherent_data_providers.has_provider(&INHERENT_IDENTIFIER) {
inherent_data_providers
.register_provider(InherentDataProvider::new(slot_duration))
.map_err(Into::into)
.map_err(consensus_common::Error::InherentData)
.map_err(sp_consensus::Error::InherentData)
} else {
Ok(())
}
@@ -717,7 +717,7 @@ pub fn import_queue<B, C, P, T>(
client: Arc<C>,
inherent_data_providers: InherentDataProviders,
transaction_pool: Option<Arc<T>>,
) -> Result<AuraImportQueue<B>, consensus_common::Error> where
) -> Result<AuraImportQueue<B>, sp_consensus::Error> where
B: BlockT,
C: 'static + ProvideRuntimeApi + BlockOf + ProvideCache<B> + Send + Sync + AuxStore,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B, Error = sp_blockchain::Error>,
@@ -747,24 +747,23 @@ pub fn import_queue<B, C, P, T>(
#[cfg(test)]
mod tests {
use super::*;
use consensus_common::NoNetwork as DummyOracle;
use sp_consensus::NoNetwork as DummyOracle;
use sc_network_test::{Block as TestBlock, *};
use sp_runtime::traits::{Block as BlockT, DigestFor};
use sc_network::config::ProtocolConfig;
use parking_lot::Mutex;
use tokio::runtime::current_thread;
use keyring::sr25519::Keyring;
use client::BlockchainEvents;
use test_client;
use aura_primitives::sr25519::AuthorityPair;
use sp_keyring::sr25519::Keyring;
use sc_client::BlockchainEvents;
use sp_consensus_aura::sr25519::AuthorityPair;
type Error = sp_blockchain::Error;
type TestClient = client::Client<
test_client::Backend,
test_client::Executor,
type TestClient = sc_client::Client<
substrate_test_runtime_client::Backend,
substrate_test_runtime_client::Executor,
TestBlock,
test_client::runtime::RuntimeApi
substrate_test_runtime_client::runtime::RuntimeApi
>;
struct DummyFactory(Arc<TestClient>);
@@ -875,7 +874,7 @@ mod tests {
let client = peer.client().as_full().expect("full clients are created").clone();
let select_chain = peer.select_chain().expect("full client has a select chain");
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = keystore::Store::open(keystore_path.path(), None).expect("Creates keystore.");
let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore.");
keystore.write().insert_ephemeral_from_seed::<AuthorityPair>(&key.to_seed())
.expect("Creates authority key");
@@ -906,7 +905,7 @@ mod tests {
inherent_data_providers,
false,
keystore,
consensus_common::AlwaysCanAuthor,
sp_consensus::AlwaysCanAuthor,
).expect("Starts aura");
runtime.spawn(aura);
@@ -923,7 +922,7 @@ mod tests {
#[test]
fn authorities_call_works() {
let client = test_client::new();
let client = substrate_test_runtime_client::new();
assert_eq!(client.info().chain.best_number, 0);
assert_eq!(authorities(&client, &BlockId::Number(0)).unwrap(), vec![
+16 -16
View File
@@ -7,26 +7,26 @@ edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
babe_primitives = { package = "sp-consensus-babe", path = "../../../primitives/consensus/babe" }
primitives = { package = "sp-core", path = "../../../primitives/core" }
app-crypto = { package = "sp-application-crypto", path = "../../../primitives/application-crypto" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sp-core = { path = "../../../primitives/core" }
sp-application-crypto = { path = "../../../primitives/application-crypto" }
num-bigint = "0.2.3"
num-rational = "0.2.2"
num-traits = "0.2.8"
runtime-version = { package = "sp-version", path = "../../../primitives/version" }
sp-version = { path = "../../../primitives/version" }
sp-io = { path = "../../../primitives/io" }
inherents = { package = "sp-inherents", path = "../../../primitives/inherents" }
sp-inherents = { path = "../../../primitives/inherents" }
sp-timestamp = { path = "../../../primitives/timestamp" }
sc-telemetry = { path = "../../telemetry" }
keystore = { package = "sc-keystore", path = "../../keystore" }
client-api = { package = "sc-client-api", path = "../../api" }
client = { package = "sc-client", path = "../../" }
sc-keystore = { path = "../../keystore" }
sc-client-api = { path = "../../api" }
sc-client = { path = "../../" }
sp-api = { path = "../../../primitives/api" }
block-builder-api = { package = "sp-block-builder", path = "../../../primitives/block-builder" }
sp-block-builder = { path = "../../../primitives/block-builder" }
sp-blockchain = { path = "../../../primitives/blockchain" }
consensus-common = { package = "sp-consensus", path = "../../../primitives/consensus/common" }
uncles = { package = "sc-consensus-uncles", path = "../uncles" }
slots = { package = "sc-consensus-slots", path = "../slots" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sc-consensus-uncles = { path = "../uncles" }
sc-consensus-slots = { path = "../slots" }
sp-runtime = { path = "../../../primitives/runtime" }
fork-tree = { path = "../../../utils/fork-tree" }
futures = { version = "0.3.1", features = ["compat"] }
@@ -41,13 +41,13 @@ pdqselect = "0.1.0"
derive_more = "0.99.2"
[dev-dependencies]
keyring = { package = "sp-keyring", path = "../../../primitives/keyring" }
sp-keyring = { path = "../../../primitives/keyring" }
sc-executor = { path = "../../executor" }
sc-network = { path = "../../network" }
sc-network-test = { path = "../../network/test" }
service = { package = "sc-service", path = "../../service" }
test-client = { package = "substrate-test-runtime-client", path = "../../../test-utils/runtime/client" }
block-builder = { package = "sc-block-builder", path = "../../block-builder" }
sc-service = { path = "../../service" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" }
sc-block-builder = { path = "../../block-builder" }
tokio = "0.1.22"
env_logger = "0.7.0"
tempfile = "3.1.0"
@@ -17,13 +17,13 @@
//! BABE authority selection and slot claiming.
use merlin::Transcript;
use babe_primitives::{AuthorityId, BabeAuthorityWeight, BABE_ENGINE_ID, BABE_VRF_PREFIX};
use babe_primitives::{Epoch, SlotNumber, AuthorityPair, BabePreDigest, BabeConfiguration};
use primitives::{U256, blake2_256};
use sp_consensus_babe::{AuthorityId, BabeAuthorityWeight, BABE_ENGINE_ID, BABE_VRF_PREFIX};
use sp_consensus_babe::{Epoch, SlotNumber, AuthorityPair, BabePreDigest, BabeConfiguration};
use sp_core::{U256, blake2_256};
use codec::Encode;
use schnorrkel::vrf::VRFInOut;
use primitives::Pair;
use keystore::KeyStorePtr;
use sp_core::Pair;
use sc_keystore::KeyStorePtr;
/// Calculates the primary selection threshold for a given authority, taking
/// into account `c` (`1 - c` represents the probability of a slot being empty).
@@ -162,8 +162,8 @@ pub(super) fn claim_slot(
}
fn get_keypair(q: &AuthorityPair) -> &schnorrkel::Keypair {
use primitives::crypto::IsWrappedBy;
primitives::sr25519::Pair::from_ref(q).as_ref()
use sp_core::crypto::IsWrappedBy;
sp_core::sr25519::Pair::from_ref(q).as_ref()
}
/// Claim a primary slot if it is our turn. Returns `None` if it is not our turn.
@@ -19,10 +19,10 @@
use log::info;
use codec::{Decode, Encode};
use client_api::backend::AuxStore;
use sc_client_api::backend::AuxStore;
use sp_blockchain::{Result as ClientResult, Error as ClientError};
use sp_runtime::traits::Block as BlockT;
use babe_primitives::BabeBlockWeight;
use sp_consensus_babe::BabeBlockWeight;
use super::{epoch_changes::EpochChangesFor, SharedEpochChanges};
@@ -20,14 +20,14 @@
//! persistent DAG superimposed over the forks of the blockchain.
use std::sync::Arc;
use babe_primitives::{Epoch, SlotNumber, NextEpochDescriptor};
use sp_consensus_babe::{Epoch, SlotNumber, NextEpochDescriptor};
use fork_tree::ForkTree;
use parking_lot::{Mutex, MutexGuard};
use sp_runtime::traits::{Block as BlockT, NumberFor, One, Zero};
use codec::{Encode, Decode};
use client_api::utils::is_descendent_of;
use sc_client_api::utils::is_descendent_of;
use sp_blockchain::{HeaderMetadata, HeaderBackend, Error as ClientError};
use primitives::H256;
use sp_core::H256;
use std::ops::Add;
/// A builder for `is_descendent_of` functions.
+42 -42
View File
@@ -58,15 +58,15 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub use babe_primitives::{
pub use sp_consensus_babe::{
BabeApi, ConsensusLog, BABE_ENGINE_ID, BabePreDigest, SlotNumber, BabeConfiguration,
CompatibleDigestItem,
};
pub use consensus_common::SyncOracle;
pub use sp_consensus::SyncOracle;
use std::{collections::HashMap, sync::Arc, u64, pin::Pin, time::{Instant, Duration}};
use babe_primitives;
use consensus_common::{ImportResult, CanAuthorWith};
use consensus_common::import_queue::{
use sp_consensus_babe;
use sp_consensus::{ImportResult, CanAuthorWith};
use sp_consensus::import_queue::{
BoxJustificationImport, BoxFinalityProofImport,
};
use sp_runtime::{generic::{BlockId, OpaqueDigestItemId}, Justification};
@@ -74,32 +74,32 @@ use sp_runtime::traits::{
Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi,
Zero,
};
use keystore::KeyStorePtr;
use sc_keystore::KeyStorePtr;
use parking_lot::Mutex;
use primitives::{Blake2Hasher, H256, Pair};
use inherents::{InherentDataProviders, InherentData};
use sp_core::{Blake2Hasher, H256, Pair};
use sp_inherents::{InherentDataProviders, InherentData};
use sc_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG};
use consensus_common::{
use sp_consensus::{
self, BlockImport, Environment, Proposer, BlockCheckParams,
ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError,
SelectChain, SlotData,
};
use babe_primitives::inherents::BabeInherentData;
use sp_consensus_babe::inherents::BabeInherentData;
use sp_timestamp::{TimestampInherentData, InherentType as TimestampInherent};
use consensus_common::import_queue::{Verifier, BasicQueue, CacheKeyId};
use client_api::{
use sp_consensus::import_queue::{Verifier, BasicQueue, CacheKeyId};
use sc_client_api::{
backend::{AuxStore, Backend},
call_executor::CallExecutor,
BlockchainEvents, ProvideUncles,
};
use client::Client;
use sc_client::Client;
use block_builder_api::BlockBuilder as BlockBuilderApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use slots::{CheckedHeader, check_equivocation};
use sc_consensus_slots::{CheckedHeader, check_equivocation};
use futures::prelude::*;
use log::{warn, debug, info, trace};
use slots::{SlotWorker, SlotInfo, SlotCompatible};
use sc_consensus_slots::{SlotWorker, SlotInfo, SlotCompatible};
use epoch_changes::descendent_query;
use sp_blockchain::{
Result as ClientResult, Error as ClientError,
@@ -115,7 +115,7 @@ mod epoch_changes;
mod authorship;
#[cfg(test)]
mod tests;
pub use babe_primitives::{
pub use sp_consensus_babe::{
AuthorityId, AuthorityPair, AuthoritySignature, Epoch, NextEpochDescriptor,
};
pub use epoch_changes::{EpochChanges, EpochChangesFor, SharedEpochChanges};
@@ -130,7 +130,7 @@ enum Error<B: BlockT> {
#[display(fmt = "Multiple BABE epoch change digests, rejecting!")]
MultipleEpochChangeDigests,
#[display(fmt = "Could not extract timestamp and slot: {:?}", _0)]
Extraction(consensus_common::Error),
Extraction(sp_consensus::Error),
#[display(fmt = "Could not fetch epoch at {:?}", _0)]
FetchEpoch(B::Hash),
#[display(fmt = "Header {:?} rejected: too far in the future", _0)]
@@ -172,7 +172,7 @@ enum Error<B: BlockT> {
#[display(fmt = "Checking inherents failed: {}", _0)]
CheckInherents(String),
Client(sp_blockchain::Error),
Runtime(inherents::Error),
Runtime(sp_inherents::Error),
ForkTree(Box<fork_tree::Error<sp_blockchain::Error>>),
}
@@ -201,7 +201,7 @@ macro_rules! babe_info {
// and `super::babe::Config` can be eliminated.
// https://github.com/paritytech/substrate/issues/2434
#[derive(Clone)]
pub struct Config(slots::SlotDuration<BabeConfiguration>);
pub struct Config(sc_consensus_slots::SlotDuration<BabeConfiguration>);
impl Config {
/// Either fetch the slot duration from disk or compute it from the genesis
@@ -210,7 +210,7 @@ impl Config {
C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi<B, Error = sp_blockchain::Error>,
{
trace!(target: "babe", "Getting slot duration");
match slots::SlotDuration::get_or_compute(client, |a, b| a.configuration(b)).map(Self) {
match sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| a.configuration(b)).map(Self) {
Ok(s) => Ok(s),
Err(s) => {
warn!(target: "babe", "Failed to get slot duration");
@@ -289,7 +289,7 @@ pub fn start_babe<B, C, SC, E, I, SO, CAW, Error>(BabeParams {
can_author_with,
}: BabeParams<B, C, E, I, SO, SC, CAW>) -> Result<
impl futures01::Future<Item=(), Error=()>,
consensus_common::Error,
sp_consensus::Error,
> where
B: BlockT<Hash=H256>,
C: ProvideRuntimeApi + ProvideCache<B> + ProvideUncles<B> + BlockchainEvents<B>
@@ -300,7 +300,7 @@ pub fn start_babe<B, C, SC, E, I, SO, CAW, Error>(BabeParams {
E::Proposer: Proposer<B, Error=Error>,
<E::Proposer as Proposer<B>>::Create: Unpin + Send + 'static,
I: BlockImport<B,Error=ConsensusError> + Send + Sync + 'static,
Error: std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
SO: SyncOracle + Send + Sync + Clone,
CAW: CanAuthorWith<B> + Send,
{
@@ -317,14 +317,14 @@ pub fn start_babe<B, C, SC, E, I, SO, CAW, Error>(BabeParams {
};
register_babe_inherent_data_provider(&inherent_data_providers, config.slot_duration())?;
uncles::register_uncles_inherent_data_provider(
sc_consensus_uncles::register_uncles_inherent_data_provider(
client.clone(),
select_chain.clone(),
&inherent_data_providers,
)?;
babe_info!("Starting BABE Authorship worker");
let slot_worker = slots::start_slot_worker(
let slot_worker = sc_consensus_slots::start_slot_worker(
config.0,
select_chain,
worker,
@@ -348,7 +348,7 @@ struct BabeWorker<B: BlockT, C, E, I, SO> {
config: Config,
}
impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I, SO> where
impl<B, C, E, I, Error, SO> sc_consensus_slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I, SO> where
B: BlockT<Hash=H256>,
C: ProvideRuntimeApi + ProvideCache<B> + HeaderBackend<B> + HeaderMetadata<B, Error=ClientError>,
C::Api: BabeApi<B>,
@@ -357,7 +357,7 @@ impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I
<E::Proposer as Proposer<B>>::Create: Unpin + Send + 'static,
I: BlockImport<B> + Send + Sync + 'static,
SO: SyncOracle + Send + Clone,
Error: std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
{
type EpochData = Epoch;
type Claim = (BabePreDigest, AuthorityPair);
@@ -373,7 +373,7 @@ impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I
self.block_import.clone()
}
fn epoch_data(&self, parent: &B::Header, slot_number: u64) -> Result<Self::EpochData, consensus_common::Error> {
fn epoch_data(&self, parent: &B::Header, slot_number: u64) -> Result<Self::EpochData, sp_consensus::Error> {
self.epoch_changes.lock().epoch_for_child_of(
descendent_query(&*self.client),
&parent.hash(),
@@ -383,7 +383,7 @@ impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I
)
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?
.map(|e| e.into_inner())
.ok_or(consensus_common::Error::InvalidAuthoritiesSet)
.ok_or(sp_consensus::Error::InvalidAuthoritiesSet)
}
fn authorities_len(&self, epoch_data: &Self::EpochData) -> usize {
@@ -422,7 +422,7 @@ impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I
&B::Hash,
Vec<B::Extrinsic>,
Self::Claim,
) -> consensus_common::BlockImportParams<B> + Send> {
) -> sp_consensus::BlockImportParams<B> + Send> {
Box::new(|header, header_hash, body, (_, pair)| {
// sign the pre-sealed hash of the block and then
// add it to a digest item.
@@ -455,9 +455,9 @@ impl<B, C, E, I, Error, SO> slots::SimpleSlotWorker<B> for BabeWorker<B, C, E, I
&mut self.sync_oracle
}
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, consensus_common::Error> {
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, sp_consensus::Error> {
self.env.init(block).map_err(|e| {
consensus_common::Error::ClientImport(format!("{:?}", e))
sp_consensus::Error::ClientImport(format!("{:?}", e))
})
}
@@ -510,12 +510,12 @@ impl<B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<B, C, E, I, SO> where
<E::Proposer as Proposer<B>>::Create: Unpin + Send + 'static,
I: BlockImport<B> + Send + Sync + 'static,
SO: SyncOracle + Send + Sync + Clone,
Error: std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
Error: std::error::Error + Send + From<::sp_consensus::Error> + From<I::Error> + 'static,
{
type OnSlot = Pin<Box<dyn Future<Output = Result<(), consensus_common::Error>> + Send>>;
type OnSlot = Pin<Box<dyn Future<Output = Result<(), sp_consensus::Error>> + Send>>;
fn on_slot(&mut self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot {
<Self as slots::SimpleSlotWorker<B>>::on_slot(self, chain_head, slot_info)
<Self as sc_consensus_slots::SimpleSlotWorker<B>>::on_slot(self, chain_head, slot_info)
}
}
@@ -571,12 +571,12 @@ impl SlotCompatible for TimeSource {
fn extract_timestamp_and_slot(
&self,
data: &InherentData,
) -> Result<(TimestampInherent, u64, std::time::Duration), consensus_common::Error> {
) -> Result<(TimestampInherent, u64, std::time::Duration), sp_consensus::Error> {
trace!(target: "babe", "extract timestamp");
data.timestamp_inherent_data()
.and_then(|t| data.babe_inherent_data().map(|a| (t, a)))
.map_err(Into::into)
.map_err(consensus_common::Error::InherentData)
.map_err(sp_consensus::Error::InherentData)
.map(|(x, y)| (x, y, self.0.lock().0.take().unwrap_or_default()))
}
}
@@ -592,7 +592,7 @@ pub struct BabeLink<Block: BlockT> {
pub struct BabeVerifier<B, E, Block: BlockT, RA, PRA> {
client: Arc<Client<B, E, Block, RA>>,
api: Arc<PRA>,
inherent_data_providers: inherents::InherentDataProviders,
inherent_data_providers: sp_inherents::InherentDataProviders,
config: Config,
epoch_changes: SharedEpochChanges<Block>,
time_source: TimeSource,
@@ -818,13 +818,13 @@ pub type BabeImportQueue<B> = BasicQueue<B>;
fn register_babe_inherent_data_provider(
inherent_data_providers: &InherentDataProviders,
slot_duration: u64,
) -> Result<(), consensus_common::Error> {
) -> Result<(), sp_consensus::Error> {
debug!(target: "babe", "Registering");
if !inherent_data_providers.has_provider(&babe_primitives::inherents::INHERENT_IDENTIFIER) {
if !inherent_data_providers.has_provider(&sp_consensus_babe::inherents::INHERENT_IDENTIFIER) {
inherent_data_providers
.register_provider(babe_primitives::inherents::InherentDataProvider::new(slot_duration))
.register_provider(sp_consensus_babe::inherents::InherentDataProvider::new(slot_duration))
.map_err(Into::into)
.map_err(consensus_common::Error::InherentData)
.map_err(sp_consensus::Error::InherentData)
} else {
Ok(())
}
+16 -17
View File
@@ -22,10 +22,10 @@
use super::*;
use authorship::claim_slot;
use babe_primitives::{AuthorityPair, SlotNumber};
use block_builder::BlockBuilder;
use consensus_common::NoNetwork as DummyOracle;
use consensus_common::import_queue::{
use sp_consensus_babe::{AuthorityPair, SlotNumber};
use sc_block_builder::BlockBuilder;
use sp_consensus::NoNetwork as DummyOracle;
use sp_consensus::import_queue::{
BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
};
use sc_network_test::*;
@@ -33,8 +33,7 @@ use sc_network_test::{Block as TestBlock, PeersClient};
use sc_network::config::{BoxFinalityProofRequestBuilder, ProtocolConfig};
use sp_runtime::{generic::DigestItem, traits::{Block as BlockT, DigestFor}};
use tokio::runtime::current_thread;
use client_api::BlockchainEvents;
use test_client;
use sc_client_api::BlockchainEvents;
use log::debug;
use std::{time::Duration, cell::RefCell};
@@ -42,11 +41,11 @@ type Item = DigestItem<Hash>;
type Error = sp_blockchain::Error;
type TestClient = client::Client<
test_client::Backend,
test_client::Executor,
type TestClient = sc_client::Client<
substrate_test_runtime_client::Backend,
substrate_test_runtime_client::Executor,
TestBlock,
test_client::runtime::RuntimeApi,
substrate_test_runtime_client::runtime::RuntimeApi,
>;
#[derive(Copy, Clone, PartialEq)]
@@ -196,10 +195,10 @@ type TestExtrinsic = <TestBlock as BlockT>::Extrinsic;
pub struct TestVerifier {
inner: BabeVerifier<
test_client::Backend,
test_client::Executor,
substrate_test_runtime_client::Backend,
substrate_test_runtime_client::Executor,
TestBlock,
test_client::runtime::RuntimeApi,
substrate_test_runtime_client::runtime::RuntimeApi,
PeersFullClient,
>,
mutator: Mutator,
@@ -358,7 +357,7 @@ fn run_one_test(
let select_chain = peer.select_chain().expect("Full client has select_chain");
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
keystore.write().insert_ephemeral_from_seed::<AuthorityPair>(seed).expect("Generates authority key");
keystore_paths.push(keystore_path);
@@ -403,7 +402,7 @@ fn run_one_test(
force_authoring: false,
babe_link: data.link.clone(),
keystore,
can_author_with: consensus_common::AlwaysCanAuthor,
can_author_with: sp_consensus::AlwaysCanAuthor,
}).expect("Starts babe"));
}
@@ -483,7 +482,7 @@ fn sig_is_not_pre_digest() {
fn can_author_block() {
let _ = env_logger::try_init();
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
let pair = keystore.write().insert_ephemeral_from_seed::<AuthorityPair>("//Alice")
.expect("Generates authority pair");
@@ -634,7 +633,7 @@ fn importing_block_one_sets_genesis_epoch() {
#[test]
fn importing_epoch_change_block_prunes_tree() {
use client_api::Finalizer;
use sc_client_api::Finalizer;
let mut net = BabeTestNet::new(1);
@@ -17,10 +17,10 @@
//! Verification for BABE headers.
use schnorrkel::vrf::{VRFOutput, VRFProof};
use sp_runtime::{traits::Header, traits::DigestItemFor};
use primitives::{Pair, Public};
use babe_primitives::{Epoch, BabePreDigest, CompatibleDigestItem, AuthorityId};
use babe_primitives::{AuthoritySignature, SlotNumber, AuthorityIndex, AuthorityPair};
use slots::CheckedHeader;
use sp_core::{Pair, Public};
use sp_consensus_babe::{Epoch, BabePreDigest, CompatibleDigestItem, AuthorityId};
use sp_consensus_babe::{AuthoritySignature, SlotNumber, AuthorityIndex, AuthorityPair};
use sc_consensus_slots::CheckedHeader;
use log::{debug, trace};
use super::{find_pre_digest, babe_err, BlockT, Error};
use super::authorship::{make_transcript, calculate_primary_threshold, check_primary_threshold, secondary_slot_author};
+6 -6
View File
@@ -7,14 +7,14 @@ edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
primitives = { package = "sp-core", path = "../../../primitives/core" }
sp-core = { path = "../../../primitives/core" }
sp-blockchain = { path = "../../../primitives/blockchain" }
sp-runtime = { path = "../../../primitives/runtime" }
client-api = { package = "sc-client-api", path = "../../api" }
block-builder-api = { package = "sp-block-builder", path = "../../../primitives/block-builder" }
inherents = { package = "sp-inherents", path = "../../../primitives/inherents" }
pow-primitives = { package = "sp-consensus-pow", path = "../../../primitives/consensus/pow" }
consensus-common = { package = "sp-consensus", path = "../../../primitives/consensus/common" }
sc-client-api = { path = "../../api" }
sp-block-builder = { path = "../../../primitives/block-builder" }
sp-inherents = { path = "../../../primitives/inherents" }
sp-consensus-pow = { path = "../../../primitives/consensus/pow" }
sp-consensus = { path = "../../../primitives/consensus/common" }
log = "0.4.8"
futures = { version = "0.3.1", features = ["compat"] }
sp-timestamp = { path = "../../../primitives/timestamp" }
+16 -16
View File
@@ -32,23 +32,23 @@
use std::sync::Arc;
use std::thread;
use std::collections::HashMap;
use client_api::{BlockOf, backend::AuxStore};
use sc_client_api::{BlockOf, backend::AuxStore};
use sp_blockchain::{HeaderBackend, ProvideCache, well_known_cache_keys::Id as CacheKeyId};
use block_builder_api::BlockBuilder as BlockBuilderApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_runtime::{Justification, RuntimeString};
use sp_runtime::generic::{BlockId, Digest, DigestItem};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi};
use sp_timestamp::{TimestampInherentData, InherentError as TIError};
use pow_primitives::{Seal, TotalDifficulty, POW_ENGINE_ID};
use primitives::H256;
use inherents::{InherentDataProviders, InherentData};
use consensus_common::{
use sp_consensus_pow::{Seal, TotalDifficulty, POW_ENGINE_ID};
use sp_core::H256;
use sp_inherents::{InherentDataProviders, InherentData};
use sp_consensus::{
BlockImportParams, BlockOrigin, ForkChoiceStrategy, SyncOracle, Environment, Proposer,
SelectChain, Error as ConsensusError, CanAuthorWith,
};
use consensus_common::import_queue::{BoxBlockImport, BasicQueue, Verifier};
use sp_consensus::import_queue::{BoxBlockImport, BasicQueue, Verifier};
use codec::{Encode, Decode};
use client_api;
use sc_client_api;
use log::*;
#[derive(derive_more::Display, Debug)]
@@ -74,7 +74,7 @@ pub enum Error<B: BlockT> {
#[display(fmt = "Error with block built on {:?}: {:?}", _0, _1)]
BlockBuiltError(B::Hash, ConsensusError),
#[display(fmt = "Creating inherents failed: {}", _0)]
CreateInherents(inherents::Error),
CreateInherents(sp_inherents::Error),
#[display(fmt = "Checking inherents failed: {}", _0)]
CheckInherents(String),
Client(sp_blockchain::Error),
@@ -151,7 +151,7 @@ pub trait PowAlgorithm<B: BlockT> {
pub struct PowVerifier<B: BlockT<Hash=H256>, C, S, Algorithm> {
client: Arc<C>,
algorithm: Algorithm,
inherent_data_providers: inherents::InherentDataProviders,
inherent_data_providers: sp_inherents::InherentDataProviders,
select_chain: Option<S>,
check_inherents_after: <<B as BlockT>::Header as HeaderT>::Number,
}
@@ -162,7 +162,7 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> PowVerifier<B, C, S, Algorithm> {
algorithm: Algorithm,
check_inherents_after: <<B as BlockT>::Header as HeaderT>::Number,
select_chain: Option<S>,
inherent_data_providers: inherents::InherentDataProviders,
inherent_data_providers: sp_inherents::InherentDataProviders,
) -> Self {
Self { client, algorithm, inherent_data_providers, select_chain, check_inherents_after }
}
@@ -314,12 +314,12 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> Verifier<B> for PowVerifier<B, C, S,
/// Register the PoW inherent data provider, if not registered already.
pub fn register_pow_inherent_data_provider(
inherent_data_providers: &InherentDataProviders,
) -> Result<(), consensus_common::Error> {
) -> Result<(), sp_consensus::Error> {
if !inherent_data_providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) {
inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.map_err(Into::into)
.map_err(consensus_common::Error::InherentData)
.map_err(sp_consensus::Error::InherentData)
} else {
Ok(())
}
@@ -336,7 +336,7 @@ pub fn import_queue<B, C, S, Algorithm>(
check_inherents_after: <<B as BlockT>::Header as HeaderT>::Number,
select_chain: Option<S>,
inherent_data_providers: InherentDataProviders,
) -> Result<PowImportQueue<B>, consensus_common::Error> where
) -> Result<PowImportQueue<B>, sp_consensus::Error> where
B: BlockT<Hash=H256>,
C: ProvideRuntimeApi + HeaderBackend<B> + BlockOf + ProvideCache<B> + AuxStore,
C: Send + Sync + AuxStore + 'static,
@@ -382,7 +382,7 @@ pub fn start_mine<B: BlockT<Hash=H256>, C, Algorithm, E, SO, S, CAW>(
mut sync_oracle: SO,
build_time: std::time::Duration,
select_chain: Option<S>,
inherent_data_providers: inherents::InherentDataProviders,
inherent_data_providers: sp_inherents::InherentDataProviders,
can_author_with: CAW,
) where
C: HeaderBackend<B> + AuxStore + 'static,
@@ -433,7 +433,7 @@ fn mine_loop<B: BlockT<Hash=H256>, C, Algorithm, E, SO, S, CAW>(
sync_oracle: &mut SO,
build_time: std::time::Duration,
select_chain: Option<&S>,
inherent_data_providers: &inherents::InherentDataProviders,
inherent_data_providers: &sp_inherents::InherentDataProviders,
can_author_with: &CAW,
) -> Result<(), Error<B>> where
C: HeaderBackend<B> + AuxStore,
+5 -5
View File
@@ -8,17 +8,17 @@ build = "build.rs"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0" }
client-api = { package = "sc-client-api", path = "../../api" }
primitives = { package = "sp-core", path = "../../../primitives/core" }
sc-client-api = { path = "../../api" }
sp-core = { path = "../../../primitives/core" }
sp-blockchain = { path = "../../../primitives/blockchain" }
sp-runtime = { path = "../../../primitives/runtime" }
sc-telemetry = { path = "../../telemetry" }
consensus_common = { package = "sp-consensus", path = "../../../primitives/consensus/common" }
inherents = { package = "sp-inherents", path = "../../../primitives/inherents" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sp-inherents = { path = "../../../primitives/inherents" }
futures = "0.3.1"
futures-timer = "2.0"
parking_lot = "0.9.0"
log = "0.4.8"
[dev-dependencies]
test-client = { package = "substrate-test-runtime-client", path = "../../../test-utils/runtime/client" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" }
@@ -17,7 +17,7 @@
//! Schema for slots in the aux-db.
use codec::{Encode, Decode};
use client_api::backend::AuxStore;
use sc_client_api::backend::AuxStore;
use sp_blockchain::{Result as ClientResult, Error as ClientError};
use sp_runtime::traits::Header;
@@ -151,10 +151,10 @@ pub fn check_equivocation<C, H, P>(
#[cfg(test)]
mod test {
use primitives::{sr25519, Pair};
use primitives::hash::H256;
use sp_core::{sr25519, Pair};
use sp_core::hash::H256;
use sp_runtime::testing::{Header as HeaderTest, Digest as DigestTest};
use test_client;
use substrate_test_runtime_client;
use super::{MAX_SLOT_CAPACITY, PRUNING_BOUND, check_equivocation};
@@ -175,7 +175,7 @@ mod test {
#[test]
fn check_equivocation_works() {
let client = test_client::new();
let client = substrate_test_runtime_client::new();
let (pair, _seed) = sr25519::Pair::generate();
let public = pair.public();
+12 -12
View File
@@ -31,23 +31,23 @@ 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, SlotData};
use sp_consensus::{BlockImport, Proposer, SyncOracle, SelectChain, CanAuthorWith, SlotData};
use futures::{prelude::*, future::{self, Either}};
use futures_timer::Delay;
use inherents::{InherentData, InherentDataProviders};
use sp_inherents::{InherentData, InherentDataProviders};
use log::{debug, error, info, warn};
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{ApiRef, Block as BlockT, Header, ProvideRuntimeApi};
use std::{fmt::Debug, ops::Deref, pin::Pin, sync::Arc, time::{Instant, Duration}};
use sc_telemetry::{telemetry, CONSENSUS_DEBUG, CONSENSUS_WARN, CONSENSUS_INFO};
use parking_lot::Mutex;
use client_api;
use sc_client_api;
/// A worker that should be invoked at every new slot.
pub trait SlotWorker<B: BlockT> {
/// The type of the future that will be returned when a new slot is
/// triggered.
type OnSlot: Future<Output = Result<(), consensus_common::Error>>;
type OnSlot: Future<Output = Result<(), sp_consensus::Error>>;
/// Called when a new slot is triggered.
fn on_slot(&mut self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot;
@@ -80,7 +80,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
/// Returns the epoch data necessary for authoring. For time-dependent epochs,
/// use the provided slot number as a canonical source of time.
fn epoch_data(&self, header: &B::Header, slot_number: u64) -> Result<Self::EpochData, consensus_common::Error>;
fn epoch_data(&self, header: &B::Header, slot_number: u64) -> Result<Self::EpochData, sp_consensus::Error>;
/// Returns the number of authorities given the epoch data.
fn authorities_len(&self, epoch_data: &Self::EpochData) -> usize;
@@ -102,7 +102,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
&B::Hash,
Vec<B::Extrinsic>,
Self::Claim,
) -> consensus_common::BlockImportParams<B> + Send>;
) -> sp_consensus::BlockImportParams<B> + Send>;
/// Whether to force authoring if offline.
fn force_authoring(&self) -> bool;
@@ -111,7 +111,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
fn sync_oracle(&mut self) -> &mut Self::SyncOracle;
/// Returns a `Proposer` to author on top of the given block.
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, consensus_common::Error>;
fn proposer(&mut self, block: &B::Header) -> Result<Self::Proposer, sp_consensus::Error>;
/// Remaining duration of the slot.
fn slot_remaining_duration(&self, slot_info: &SlotInfo) -> Duration {
@@ -134,7 +134,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
/// Implements the `on_slot` functionality from `SlotWorker`.
fn on_slot(&mut self, chain_head: B::Header, slot_info: SlotInfo)
-> Pin<Box<dyn Future<Output = Result<(), consensus_common::Error>> + Send>> where
-> Pin<Box<dyn Future<Output = Result<(), sp_consensus::Error>> + Send>> where
Self: Send + Sync,
<Self::Proposer as Proposer<B>>::Create: Unpin + Send + 'static,
{
@@ -222,7 +222,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
logs,
},
slot_remaining_duration,
).map_err(|e| consensus_common::Error::ClientImport(format!("{:?}", e)));
).map_err(|e| sp_consensus::Error::ClientImport(format!("{:?}", e)));
let delay: Box<dyn Future<Output=()> + Unpin + Send> = match proposing_remaining_duration {
Some(r) => Box::new(Delay::new(r)),
None => Box::new(future::pending()),
@@ -239,7 +239,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
telemetry!(CONSENSUS_INFO; "slots.discarding_proposal_took_too_long";
"slot" => slot_number,
);
Err(consensus_common::Error::ClientImport("Timeout in the Slots proposer".into()))
Err(sp_consensus::Error::ClientImport("Timeout in the Slots proposer".into()))
},
}));
@@ -293,7 +293,7 @@ pub trait SlotCompatible {
fn extract_timestamp_and_slot(
&self,
inherent: &InherentData,
) -> Result<(u64, u64, std::time::Duration), consensus_common::Error>;
) -> Result<(u64, u64, std::time::Duration), sp_consensus::Error>;
/// Get the difference between chain time and local time. Defaults to
/// always returning zero.
@@ -417,7 +417,7 @@ impl<T: Clone> SlotDuration<T> {
/// `slot_key` is marked as `'static`, as it should really be a
/// compile-time constant.
pub fn get_or_compute<B: BlockT, C, CB>(client: &C, cb: CB) -> sp_blockchain::Result<Self> where
C: client_api::backend::AuxStore,
C: sc_client_api::backend::AuxStore,
C: ProvideRuntimeApi,
CB: FnOnce(ApiRef<C::Api>, &BlockId<B>) -> sp_blockchain::Result<T>,
T: SlotData + Encode + Decode + Debug,
@@ -19,9 +19,9 @@
//! This is used instead of `futures_timer::Interval` because it was unreliable.
use super::SlotCompatible;
use consensus_common::Error;
use sp_consensus::Error;
use futures::{prelude::*, task::Context, task::Poll};
use inherents::{InherentData, InherentDataProviders};
use sp_inherents::{InherentData, InherentDataProviders};
use std::{pin::Pin, time::{Duration, Instant}};
use futures_timer::Delay;
@@ -135,7 +135,7 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> {
let inherent_data = match self.inherent_data_providers.create_inherent_data() {
Ok(id) => id,
Err(err) => return Poll::Ready(Some(Err(consensus_common::Error::InherentData(err)))),
Err(err) => return Poll::Ready(Some(Err(sp_consensus::Error::InherentData(err)))),
};
let result = self.timestamp_extractor.extract_timestamp_and_slot(&inherent_data);
let (timestamp, slot_num, offset) = match result {
+4 -4
View File
@@ -6,10 +6,10 @@ description = "Generic uncle inclusion utilities for consensus"
edition = "2018"
[dependencies]
client-api = { package = "sc-client-api", path = "../../api" }
primitives = { package = "sp-core", path = "../../../primitives/core" }
sc-client-api = { path = "../../api" }
sp-core = { path = "../../../primitives/core" }
sp-runtime = { path = "../../../primitives/runtime" }
sp-authorship = { path = "../../../primitives/authorship" }
consensus_common = { package = "sp-consensus", path = "../../../primitives/consensus/common" }
inherents = { package = "sp-inherents", path = "../../../primitives/inherents" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sp-inherents = { path = "../../../primitives/inherents" }
log = "0.4.8"
+5 -5
View File
@@ -19,10 +19,10 @@
#![deny(warnings)]
#![forbid(unsafe_code, missing_docs)]
use consensus_common::SelectChain;
use inherents::{InherentDataProviders};
use sp_consensus::SelectChain;
use sp_inherents::{InherentDataProviders};
use log::warn;
use client_api::ProvideUncles;
use sc_client_api::ProvideUncles;
use sp_runtime::traits::{Block as BlockT, Header};
use std::sync::Arc;
use sp_authorship;
@@ -35,7 +35,7 @@ pub fn register_uncles_inherent_data_provider<B, C, SC>(
client: Arc<C>,
select_chain: SC,
inherent_data_providers: &InherentDataProviders,
) -> Result<(), consensus_common::Error> where
) -> Result<(), sp_consensus::Error> where
B: BlockT,
C: ProvideUncles<B> + Send + Sync + 'static,
SC: SelectChain<B> + 'static,
@@ -60,7 +60,7 @@ pub fn register_uncles_inherent_data_provider<B, C, SC>(
}
}
}))
.map_err(|err| consensus_common::Error::InherentData(err.into()))?;
.map_err(|err| sp_consensus::Error::InherentData(err.into()))?;
}
Ok(())
}