diff --git a/Cargo.lock b/Cargo.lock index fd6b57918b310..6cfc2d19db81f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4542,6 +4542,7 @@ dependencies = [ "sc-cli", "sc-client-api", "sc-client-db", + "sc-consensus", "sc-executor", "sc-service", "sp-api", @@ -7242,7 +7243,6 @@ dependencies = [ "sc-state-db", "sp-arithmetic", "sp-blockchain", - "sp-consensus", "sp-core", "sp-database", "sp-keyring", @@ -7260,11 +7260,24 @@ name = "sc-consensus" version = "0.10.0-dev" dependencies = [ "async-trait", + "futures 0.3.15", + "futures-timer 3.0.2", + "libp2p", + "log", "parking_lot 0.11.1", "sc-client-api", + "serde", + "sp-api", "sp-blockchain", "sp-consensus", + "sp-core", "sp-runtime", + "sp-state-machine", + "sp-test-primitives", + "sp-utils", + "substrate-prometheus-endpoint", + "thiserror", + "wasm-timer", ] [[package]] @@ -7281,6 +7294,7 @@ dependencies = [ "parking_lot 0.11.1", "sc-block-builder", "sc-client-api", + "sc-consensus", "sc-consensus-slots", "sc-executor", "sc-keystore", @@ -7331,6 +7345,7 @@ dependencies = [ "retain_mut", "sc-block-builder", "sc-client-api", + "sc-consensus", "sc-consensus-epochs", "sc-consensus-slots", "sc-consensus-uncles", @@ -7422,6 +7437,7 @@ dependencies = [ "parking_lot 0.11.1", "sc-basic-authorship", "sc-client-api", + "sc-consensus", "sc-consensus-babe", "sc-consensus-epochs", "sc-transaction-pool", @@ -7457,6 +7473,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.11.1", "sc-client-api", + "sc-consensus", "sp-api", "sp-block-builder", "sp-blockchain", @@ -7479,6 +7496,7 @@ dependencies = [ "log", "parity-scale-codec", "sc-client-api", + "sc-consensus", "sc-telemetry", "sp-api", "sp-application-crypto", @@ -7695,6 +7713,7 @@ dependencies = [ "rand 0.8.3", "sc-block-builder", "sc-client-api", + "sc-consensus", "sc-finality-grandpa", "sc-network", "sc-service", @@ -7797,6 +7816,7 @@ dependencies = [ "rand 0.7.3", "sc-block-builder", "sc-client-api", + "sc-consensus", "sc-peerset", "serde", "serde_json", @@ -7954,6 +7974,7 @@ dependencies = [ "serde_json", "sp-api", "sp-blockchain", + "sp-consensus", "sp-core", "sp-io", "sp-keystore", @@ -8048,6 +8069,7 @@ dependencies = [ "sc-chain-spec", "sc-client-api", "sc-client-db", + "sc-consensus", "sc-executor", "sc-finality-grandpa", "sc-informant", @@ -8110,6 +8132,7 @@ dependencies = [ "sc-block-builder", "sc-client-api", "sc-client-db", + "sc-consensus", "sc-executor", "sc-light", "sc-network", @@ -8847,7 +8870,6 @@ dependencies = [ "async-trait", "futures 0.3.15", "futures-timer 3.0.2", - "libp2p", "log", "parity-scale-codec", "parking_lot 0.11.1", @@ -9768,6 +9790,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-block-builder", + "sp-consensus", "sp-consensus-aura", "sp-consensus-babe", "sp-core", @@ -10024,7 +10047,6 @@ dependencies = [ "sc-network", "sc-service", "sp-api", - "sp-consensus", "sp-consensus-babe", "sp-inherents", "sp-keyring", diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index d97f29c00bca4..dbdb3074d6863 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -32,7 +32,7 @@ pub fn new_partial( FullClient, FullBackend, FullSelectChain, - sp_consensus::DefaultImportQueue, + sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, ( sc_finality_grandpa::GrandpaBlockImport< diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 47bc5f5b021f5..e7181d3caec38 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -46,7 +46,7 @@ pub fn new_partial( FullClient, FullBackend, FullSelectChain, - sp_consensus::DefaultImportQueue, + sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, ( impl Fn(node_rpc::DenyUnsafe, sc_rpc::SubscriptionTaskExecutor) -> node_rpc::IoHandler, @@ -595,14 +595,13 @@ mod tests { Address, BalancesCall, Call, UncheckedExtrinsic, }; use sc_client_api::BlockBackend; + use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy}; use sc_consensus_babe::{BabeIntermediate, CompatibleDigestItem, INTERMEDIATE_KEY}; use sc_consensus_epochs::descendent_query; use sc_keystore::LocalKeystore; use sc_service_test::TestNetNode; use sc_transaction_pool_api::{ChainEvent, MaintainedTransactionPool}; - use sp_consensus::{ - BlockImport, BlockImportParams, BlockOrigin, Environment, ForkChoiceStrategy, Proposer, - }; + use sp_consensus::{BlockOrigin, Environment, Proposer}; use sp_core::{crypto::Pair as CryptoPair, Public, H256}; use sp_inherents::InherentDataProvider; use sp_keyring::AccountKeyring; diff --git a/bin/node/test-runner-example/Cargo.toml b/bin/node/test-runner-example/Cargo.toml index 3435a34c45c1e..ef75731c38a60 100644 --- a/bin/node/test-runner-example/Cargo.toml +++ b/bin/node/test-runner-example/Cargo.toml @@ -31,7 +31,6 @@ sc-informant = { path = "../../../client/informant" } sc-consensus = { path = "../../../client/consensus/common" } sp-runtime = { path = "../../../primitives/runtime" } -sp-consensus = { path = "../../../primitives/consensus/common" } sp-keyring = { path = "../../../primitives/keyring" } sp-timestamp = { path = "../../../primitives/timestamp" } sp-api = { path = "../../../primitives/api" } diff --git a/bin/node/testing/Cargo.toml b/bin/node/testing/Cargo.toml index e2a4555e6797c..656f9331c5af9 100644 --- a/bin/node/testing/Cargo.toml +++ b/bin/node/testing/Cargo.toml @@ -17,6 +17,7 @@ pallet-balances = { version = "4.0.0-dev", path = "../../../frame/balances" } sc-service = { version = "0.10.0-dev", features = ["test-helpers", "db"], path = "../../../client/service" } sc-client-db = { version = "0.10.0-dev", path = "../../../client/db/", features = ["kvdb-rocksdb", "parity-db"] } sc-client-api = { version = "4.0.0-dev", path = "../../../client/api/" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } codec = { package = "parity-scale-codec", version = "2.0.0" } pallet-contracts = { version = "4.0.0-dev", path = "../../../frame/contracts" } pallet-grandpa = { version = "4.0.0-dev", path = "../../../frame/grandpa" } diff --git a/bin/node/testing/src/bench.rs b/bin/node/testing/src/bench.rs index ceca493874dcb..6aaaab04b627e 100644 --- a/bin/node/testing/src/bench.rs +++ b/bin/node/testing/src/bench.rs @@ -45,12 +45,11 @@ use sc_client_api::{ BlockBackend, ExecutionStrategy, }; use sc_client_db::PruningMode; +use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux}; use sc_executor::{NativeExecutor, WasmExecutionMethod}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; -use sp_consensus::{ - BlockImport, BlockImportParams, BlockOrigin, ForkChoiceStrategy, ImportResult, ImportedAux, -}; +use sp_consensus::BlockOrigin; use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, ExecutionContext, Pair, Public}; use sp_inherents::InherentData; use sp_runtime::{ diff --git a/client/api/src/backend.rs b/client/api/src/backend.rs index 965e0151c3cba..0fcd85120c896 100644 --- a/client/api/src/backend.rs +++ b/client/api/src/backend.rs @@ -42,7 +42,6 @@ use std::{ sync::Arc, }; -pub use sp_consensus::ImportedState; pub use sp_state_machine::Backend as StateBackend; use std::marker::PhantomData; diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index f5a8aaf9dadbb..c23ad55505766 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -20,6 +20,7 @@ sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" } sc-client-api = { version = "4.0.0-dev", path = "../../api" } codec = { package = "parity-scale-codec", version = "2.0.0" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sp-consensus-slots = { version = "0.10.0-dev", path = "../../../primitives/consensus/slots" } derive_more = "0.99.2" futures = "0.3.9" diff --git a/client/consensus/aura/src/import_queue.rs b/client/consensus/aura/src/import_queue.rs index a8036f28f1648..96045fde43a9f 100644 --- a/client/consensus/aura/src/import_queue.rs +++ b/client/consensus/aura/src/import_queue.rs @@ -23,6 +23,10 @@ use codec::{Codec, Decode, Encode}; use log::{debug, info, trace}; use prometheus_endpoint::Registry; use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider}; +use sc_consensus::{ + block_import::{BlockImport, BlockImportParams, ForkChoiceStrategy}, + import_queue::{BasicQueue, BoxJustificationImport, DefaultImportQueue, Verifier}, +}; use sc_consensus_slots::{check_equivocation, CheckedHeader, InherentDataProviderExt}; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_TRACE}; use sp_api::{ApiExt, ProvideRuntimeApi}; @@ -31,11 +35,7 @@ use sp_blockchain::{ well_known_cache_keys::{self, Id as CacheKeyId}, HeaderBackend, ProvideCache, }; -use sp_consensus::{ - import_queue::{BasicQueue, BoxJustificationImport, DefaultImportQueue, Verifier}, - BlockImport, BlockImportParams, BlockOrigin, CanAuthorWith, Error as ConsensusError, - ForkChoiceStrategy, -}; +use sp_consensus::{BlockOrigin, CanAuthorWith, Error as ConsensusError}; use sp_consensus_aura::{ digests::CompatibleDigestItem, inherents::AuraInherentData, AuraApi, ConsensusLog, AURA_ENGINE_ID, diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 8efd39aa612ea..d9c089b9561e1 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -45,6 +45,7 @@ use log::{debug, trace}; use codec::{Codec, Decode, Encode}; use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider}; +use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, StateAction}; use sc_consensus_slots::{ BackoffAuthoringBlocksStrategy, InherentDataProviderExt, SlotInfo, StorageChanges, }; @@ -53,8 +54,7 @@ use sp_api::ProvideRuntimeApi; use sp_application_crypto::{AppKey, AppPublic}; use sp_blockchain::{HeaderBackend, ProvideCache, Result as CResult}; use sp_consensus::{ - BlockImport, BlockImportParams, BlockOrigin, CanAuthorWith, Environment, - Error as ConsensusError, ForkChoiceStrategy, Proposer, SelectChain, StateAction, + BlockOrigin, CanAuthorWith, Environment, Error as ConsensusError, Proposer, SelectChain, }; use sp_consensus_slots::Slot; use sp_core::crypto::{Pair, Public}; @@ -185,7 +185,7 @@ where PF: Environment + Send + Sync + 'static, PF::Proposer: Proposer>, SO: SyncOracle + Send + Sync + Clone, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, CIDP: CreateInherentDataProviders + Send, CIDP::InherentDataProviders: InherentDataProviderExt + Send, BS: BackoffAuthoringBlocksStrategy> + Send + 'static, @@ -277,7 +277,7 @@ where I: BlockImport> + Send + Sync + 'static, Error: std::error::Error + Send + From + 'static, SO: SyncOracle + Send + Sync + Clone, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, BS: BackoffAuthoringBlocksStrategy> + Send + 'static, { AuraWorker { @@ -324,7 +324,7 @@ where P::Public: AppPublic + Public + Member + Encode + Decode + Hash, P::Signature: TryFrom> + Member + Encode + Decode + Hash + Debug, SO: SyncOracle + Send + Clone, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, BS: BackoffAuthoringBlocksStrategy> + Send + 'static, Error: std::error::Error + Send + From + 'static, { @@ -395,7 +395,7 @@ where Self::Claim, Self::EpochData, ) -> Result< - sp_consensus::BlockImportParams>, + sc_consensus::BlockImportParams>, sp_consensus::Error, > + Send + 'static, @@ -431,7 +431,7 @@ where import_block.post_digests.push(signature_digest_item); import_block.body = Some(body); import_block.state_action = - StateAction::ApplyChanges(sp_consensus::StorageChanges::Changes(storage_changes)); + StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(storage_changes)); import_block.fork_choice = Some(ForkChoiceStrategy::LongestChain); Ok(import_block) @@ -560,14 +560,14 @@ mod tests { use parking_lot::Mutex; use sc_block_builder::BlockBuilderProvider; use sc_client_api::BlockchainEvents; + use sc_consensus::BoxJustificationImport; use sc_consensus_slots::{BackoffAuthoringOnFinalizedHeadLagging, SimpleSlotWorker}; use sc_keystore::LocalKeystore; use sc_network::config::ProtocolConfig; use sc_network_test::{Block as TestBlock, *}; use sp_application_crypto::key_types::AURA; use sp_consensus::{ - import_queue::BoxJustificationImport, AlwaysCanAuthor, DisableProofRecording, - NoNetwork as DummyOracle, Proposal, SlotData, + AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal, SlotData, }; use sp_consensus_aura::sr25519::AuthorityPair; use sp_inherents::InherentData; diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index e76e293df5bb4..e6538cb57aae6 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" } sp-application-crypto = { version = "4.0.0-dev", path = "../../../primitives/application-crypto" } sp-keystore = { version = "0.10.0-dev", path = "../../../primitives/keystore" } diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index a8258e2c83522..b09cd6ad86b82 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -85,6 +85,13 @@ use retain_mut::RetainMut; use schnorrkel::SignatureError; use sc_client_api::{backend::AuxStore, BlockchainEvents, ProvideUncles, UsageProvider}; +use sc_consensus::{ + block_import::{ + BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, + StateAction, + }, + import_queue::{BasicQueue, BoxJustificationImport, DefaultImportQueue, Verifier}, +}; use sc_consensus_epochs::{ descendent_query, Epoch as EpochT, EpochChangesFor, SharedEpochChanges, ViableEpochDescriptor, }; @@ -100,10 +107,8 @@ use sp_blockchain::{ Error as ClientError, HeaderBackend, HeaderMetadata, ProvideCache, Result as ClientResult, }; use sp_consensus::{ - import_queue::{BasicQueue, BoxJustificationImport, CacheKeyId, DefaultImportQueue, Verifier}, - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, CanAuthorWith, Environment, - Error as ConsensusError, ForkChoiceStrategy, ImportResult, Proposer, SelectChain, SlotData, - StateAction, + BlockOrigin, CacheKeyId, CanAuthorWith, Environment, Error as ConsensusError, Proposer, + SelectChain, SlotData, }; use sp_consensus_babe::inherents::BabeInherentData; use sp_consensus_slots::Slot; @@ -465,7 +470,7 @@ where + Sync + 'static, SO: SyncOracle + Send + Sync + Clone + 'static, - L: sp_consensus::JustificationSyncLink + 'static, + L: sc_consensus::JustificationSyncLink + 'static, CIDP: CreateInherentDataProviders + Send + Sync + 'static, CIDP::InherentDataProviders: InherentDataProviderExt + Send, BS: BackoffAuthoringBlocksStrategy> + Send + 'static, @@ -668,7 +673,7 @@ where E::Proposer: Proposer>, I: BlockImport> + Send + Sync + 'static, SO: SyncOracle + Send + Clone, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, BS: BackoffAuthoringBlocksStrategy>, Error: std::error::Error + Send + From + From + 'static, { @@ -774,7 +779,7 @@ where StorageChanges, Self::Claim, Self::EpochData, - ) -> Result, sp_consensus::Error> + ) -> Result, sp_consensus::Error> + Send + 'static, > { @@ -809,7 +814,7 @@ where import_block.post_digests.push(digest_item); import_block.body = Some(body); import_block.state_action = StateAction::ApplyChanges( - sp_consensus::StorageChanges::Changes(storage_changes), + sc_consensus::StorageChanges::Changes(storage_changes), ); import_block.intermediates.insert( Cow::from(INTERMEDIATE_KEY), diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index fa42df356a091..d21911a7fe50b 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -29,15 +29,13 @@ use rand::RngCore; use rand_chacha::{rand_core::SeedableRng, ChaChaRng}; use sc_block_builder::{BlockBuilder, BlockBuilderProvider}; use sc_client_api::{backend::TransactionFor, BlockchainEvents}; +use sc_consensus::{BoxBlockImport, BoxJustificationImport}; use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging; use sc_keystore::LocalKeystore; use sc_network::config::ProtocolConfig; use sc_network_test::{Block as TestBlock, *}; use sp_application_crypto::key_types::BABE; -use sp_consensus::{ - import_queue::{BoxBlockImport, BoxJustificationImport}, - AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal, -}; +use sp_consensus::{AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal}; use sp_consensus_babe::{ inherents::InherentDataProvider, make_transcript, make_transcript_data, AllowedSlots, AuthorityPair, Slot, diff --git a/client/consensus/common/Cargo.toml b/client/consensus/common/Cargo.toml index c8d86b06115a3..c34e5416f84b2 100644 --- a/client/consensus/common/Cargo.toml +++ b/client/consensus/common/Cargo.toml @@ -13,9 +13,24 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -async-trait = "0.1" +thiserror = "1.0.21" +libp2p = { version = "0.37.1", default-features = false } +log = "0.4.8" +futures = { version = "0.3.1", features = ["thread-pool"] } +futures-timer = "3.0.1" sc-client-api = { version = "4.0.0-dev", path = "../../api" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } +sp-core = { path = "../../../primitives/core", version = "4.0.0-dev"} +sp-consensus = { path = "../../../primitives/consensus/common", version = "0.10.0-dev"} +sp-state-machine = { version = "0.10.0-dev", path = "../../../primitives/state-machine" } sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" } -sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sp-utils = { version = "4.0.0-dev", path = "../../../primitives/utils" } +sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } parking_lot = "0.11.1" +serde = { version = "1.0", features = ["derive"] } +prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.9.0" } +wasm-timer = "0.2.5" +async-trait = "0.1.42" + +[dev-dependencies] +sp-test-primitives = { version = "2.0.0", path = "../../../primitives/test-primitives" } diff --git a/primitives/consensus/common/src/block_import.rs b/client/consensus/common/src/block_import.rs similarity index 96% rename from primitives/consensus/common/src/block_import.rs rename to client/consensus/common/src/block_import.rs index c742e24a0cc01..616378fc9b184 100644 --- a/primitives/consensus/common/src/block_import.rs +++ b/client/consensus/common/src/block_import.rs @@ -24,7 +24,7 @@ use sp_runtime::{ }; use std::{any::Any, borrow::Cow, collections::HashMap, sync::Arc}; -use crate::{import_queue::CacheKeyId, Error}; +use sp_consensus::{BlockOrigin, CacheKeyId, Error}; /// Block import result. #[derive(Debug, PartialEq, Eq)] @@ -92,23 +92,6 @@ impl ImportResult { } } -/// Block data origin. -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum BlockOrigin { - /// Genesis block built into the client. - Genesis, - /// Block is part of the initial sync with the network. - NetworkInitialSync, - /// Block was broadcasted on the network. - NetworkBroadcast, - /// Block that was received from the network and validated in the consensus process. - ConsensusBroadcast, - /// Block that was collated by this node. - Own, - /// Block was imported from a file. - File, -} - /// Fork choice strategy. #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum ForkChoiceStrategy { @@ -354,7 +337,7 @@ impl BlockImport for crate::import_queue::BoxBlockImp where Transaction: Send + 'static, { - type Error = crate::error::Error; + type Error = sp_consensus::error::Error; type Transaction = Transaction; /// Check block preconditions. diff --git a/primitives/consensus/common/src/import_queue.rs b/client/consensus/common/src/import_queue.rs similarity index 90% rename from primitives/consensus/common/src/import_queue.rs rename to client/consensus/common/src/import_queue.rs index 6eb8d0a750a24..b1a24e5620d3f 100644 --- a/primitives/consensus/common/src/import_queue.rs +++ b/client/consensus/common/src/import_queue.rs @@ -28,6 +28,7 @@ use std::collections::HashMap; +use log::{debug, trace}; use sp_runtime::{ traits::{Block as BlockT, Header as _, NumberFor}, Justifications, @@ -35,13 +36,13 @@ use sp_runtime::{ use crate::{ block_import::{ - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, ImportResult, ImportedAux, - ImportedState, JustificationImport, StateAction, + BlockCheckParams, BlockImport, BlockImportParams, ImportResult, ImportedAux, ImportedState, + JustificationImport, StateAction, }, - error::Error as ConsensusError, metrics::Metrics, }; pub use basic_queue::BasicQueue; +use sp_consensus::{error::Error as ConsensusError, BlockOrigin, CacheKeyId}; /// A commonly-used Import Queue type. /// @@ -80,7 +81,7 @@ pub struct IncomingBlock { pub origin: Option, /// Allow importing the block skipping state verification if parent state is missing. pub allow_missing_state: bool, - /// Skip block exection and state verification. + /// Skip block execution and state verification. pub skip_execution: bool, /// Re-validate existing block. pub import_existing: bool, @@ -88,9 +89,6 @@ pub struct IncomingBlock { pub state: Option>, } -/// Type of keys in the blockchain cache that consensus module could use for its needs. -pub type CacheKeyId = [u8; 4]; - /// Verify a justification of a block #[async_trait::async_trait] pub trait Verifier: Send + Sync { @@ -137,9 +135,10 @@ pub trait Link: Send { &mut self, _imported: usize, _count: usize, - _results: Vec<(Result>, BlockImportError>, B::Hash)>, + _results: Vec<(BlockImportResult, B::Hash)>, ) { } + /// Justification import result. fn justification_imported( &mut self, @@ -149,13 +148,14 @@ pub trait Link: Send { _success: bool, ) { } + /// Request a justification for the given block. fn request_justification(&mut self, _hash: &B::Hash, _number: NumberFor) {} } /// Block import successful result. #[derive(Debug, PartialEq)] -pub enum BlockImportResult { +pub enum BlockImportStatus { /// Imported known block. ImportedKnown(N, Option), /// Imported unknown block. @@ -181,13 +181,15 @@ pub enum BlockImportError { Other(ConsensusError), } +type BlockImportResult = Result>, BlockImportError>; + /// Single block import function. pub async fn import_single_block, Transaction: Send + 'static>( import_handle: &mut impl BlockImport, block_origin: BlockOrigin, block: IncomingBlock, verifier: &mut V, -) -> Result>, BlockImportError> { +) -> BlockImportResult { import_single_block_metered(import_handle, block_origin, block, verifier, None).await } @@ -202,7 +204,7 @@ pub(crate) async fn import_single_block_metered< block: IncomingBlock, verifier: &mut V, metrics: Option, -) -> Result>, BlockImportError> { +) -> BlockImportResult { let peer = block.origin; let (header, justifications) = match (block.header, block.justifications) { @@ -226,16 +228,18 @@ pub(crate) async fn import_single_block_metered< let import_handler = |import| match import { Ok(ImportResult::AlreadyInChain) => { trace!(target: "sync", "Block already in chain {}: {:?}", number, hash); - Ok(BlockImportResult::ImportedKnown(number, peer.clone())) + Ok(BlockImportStatus::ImportedKnown(number, peer.clone())) }, Ok(ImportResult::Imported(aux)) => - Ok(BlockImportResult::ImportedUnknown(number, aux, peer.clone())), + Ok(BlockImportStatus::ImportedUnknown(number, aux, peer.clone())), Ok(ImportResult::MissingState) => { - debug!(target: "sync", "Parent state is missing for {}: {:?}, parent: {:?}", number, hash, parent_hash); + debug!(target: "sync", "Parent state is missing for {}: {:?}, parent: {:?}", + number, hash, parent_hash); Err(BlockImportError::MissingState) }, Ok(ImportResult::UnknownParent) => { - debug!(target: "sync", "Block with unknown parent {}: {:?}, parent: {:?}", number, hash, parent_hash); + debug!(target: "sync", "Block with unknown parent {}: {:?}, parent: {:?}", + number, hash, parent_hash); Err(BlockImportError::UnknownParent) }, Ok(ImportResult::KnownBad) => { @@ -259,7 +263,7 @@ pub(crate) async fn import_single_block_metered< }) .await, )? { - BlockImportResult::ImportedUnknown { .. } => (), + BlockImportStatus::ImportedUnknown { .. } => (), r => return Ok(r), // Any other successful result means that the block is already imported. } @@ -291,7 +295,8 @@ pub(crate) async fn import_single_block_metered< import_block.indexed_body = block.indexed_body; let mut import_block = import_block.clear_storage_changes_and_mutate(); if let Some(state) = block.state { - import_block.state_action = StateAction::ApplyChanges(crate::StorageChanges::Import(state)); + let changes = crate::block_import::StorageChanges::Import(state); + import_block.state_action = StateAction::ApplyChanges(changes); } else if block.skip_execution { import_block.state_action = StateAction::Skip; } else if block.allow_missing_state { diff --git a/primitives/consensus/common/src/import_queue/basic_queue.rs b/client/consensus/common/src/import_queue/basic_queue.rs similarity index 94% rename from primitives/consensus/common/src/import_queue/basic_queue.rs rename to client/consensus/common/src/import_queue/basic_queue.rs index 2610a92ad83e4..2de5f578a7a66 100644 --- a/primitives/consensus/common/src/import_queue/basic_queue.rs +++ b/client/consensus/common/src/import_queue/basic_queue.rs @@ -14,13 +14,14 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - use futures::{ prelude::*, task::{Context, Poll}, }; use futures_timer::Delay; +use log::{debug, trace}; use prometheus_endpoint::Registry; +use sp_consensus::BlockOrigin; use sp_runtime::{ traits::{Block as BlockT, Header as HeaderT, NumberFor}, Justification, Justifications, @@ -29,10 +30,9 @@ use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnbound use std::{marker::PhantomData, pin::Pin, time::Duration}; use crate::{ - block_import::BlockOrigin, import_queue::{ buffered_link::{self, BufferedLinkReceiver, BufferedLinkSender}, - import_single_block_metered, BlockImportError, BlockImportResult, BoxBlockImport, + import_single_block_metered, BlockImportError, BlockImportStatus, BoxBlockImport, BoxJustificationImport, ImportQueue, IncomingBlock, Link, Origin, Verifier, }, metrics::Metrics, @@ -41,7 +41,7 @@ use crate::{ /// Interface to a basic block import queue that is importing blocks sequentially in a separate /// task, with plugable verification. pub struct BasicQueue { - /// Channel to send justifcation import messages to the background task. + /// Channel to send justification import messages to the background task. justification_sender: TracingUnboundedSender>, /// Channel to send block import messages to the background task. block_import_sender: TracingUnboundedSender>, @@ -156,9 +156,9 @@ mod worker_messages { /// The process of importing blocks. /// -/// This polls the `block_import_receiver` for new blocks to import and than awaits on importing these blocks. -/// After each block is imported, this async function yields once to give other futures the possibility -/// to be run. +/// This polls the `block_import_receiver` for new blocks to import and than awaits on +/// importing these blocks. After each block is imported, this async function yields once +/// to give other futures the possibility to be run. /// /// Returns when `block_import` ended. async fn block_import_process( @@ -325,12 +325,13 @@ struct ImportManyBlocksResult { /// The total number of blocks processed. block_count: usize, /// The import results for each block. - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(Result>, BlockImportError>, B::Hash)>, } /// Import several blocks at once, returning import result for each block. /// -/// This will yield after each imported block once, to ensure that other futures can be called as well. +/// This will yield after each imported block once, to ensure that other futures can +/// be called as well. async fn import_many_blocks, Transaction: Send + 'static>( import_handle: &mut BoxBlockImport, blocks_origin: BlockOrigin, @@ -410,11 +411,11 @@ async fn import_many_blocks, Transaction: Send + 'stat } } -/// A future that will always `yield` on the first call of `poll` but schedules the current task for -/// re-execution. +/// A future that will always `yield` on the first call of `poll` but schedules the +/// current task for re-execution. /// -/// This is done by getting the waker and calling `wake_by_ref` followed by returning `Pending`. -/// The next time the `poll` is called, it will return `Ready`. +/// This is done by getting the waker and calling `wake_by_ref` followed by returning +/// `Pending`. The next time the `poll` is called, it will return `Ready`. struct Yield(bool); impl Yield { @@ -441,8 +442,10 @@ impl Future for Yield { mod tests { use super::*; use crate::{ + block_import::{ + BlockCheckParams, BlockImport, BlockImportParams, ImportResult, JustificationImport, + }, import_queue::{CacheKeyId, Verifier}, - BlockCheckParams, BlockImport, BlockImportParams, ImportResult, JustificationImport, }; use futures::{executor::block_on, Future}; use sp_test_primitives::{Block, BlockNumber, Extrinsic, Hash, Header}; @@ -463,7 +466,7 @@ mod tests { #[async_trait::async_trait] impl BlockImport for () { - type Error = crate::Error; + type Error = sp_consensus::Error; type Transaction = Extrinsic; async fn check_block( @@ -484,7 +487,7 @@ mod tests { #[async_trait::async_trait] impl JustificationImport for () { - type Error = crate::Error; + type Error = sp_consensus::Error; async fn on_start(&mut self) -> Vec<(Hash, BlockNumber)> { Vec::new() @@ -516,7 +519,7 @@ mod tests { &mut self, _imported: usize, _count: usize, - results: Vec<(Result, BlockImportError>, Hash)>, + results: Vec<(Result, BlockImportError>, Hash)>, ) { if let Some(hash) = results.into_iter().find_map(|(r, h)| r.ok().map(|_| h)) { self.events.push(Event::BlockImported(hash)); diff --git a/primitives/consensus/common/src/import_queue/buffered_link.rs b/client/consensus/common/src/import_queue/buffered_link.rs similarity index 92% rename from primitives/consensus/common/src/import_queue/buffered_link.rs rename to client/consensus/common/src/import_queue/buffered_link.rs index 8d146dfbe461f..45aaf706ee1bd 100644 --- a/primitives/consensus/common/src/import_queue/buffered_link.rs +++ b/client/consensus/common/src/import_queue/buffered_link.rs @@ -22,8 +22,8 @@ //! # Example //! //! ``` -//! use sp_consensus::import_queue::Link; -//! # use sp_consensus::import_queue::buffered_link::buffered_link; +//! use sc_consensus::import_queue::Link; +//! # use sc_consensus::import_queue::buffered_link::buffered_link; //! # use sp_test_primitives::Block; //! # struct DummyLink; impl Link for DummyLink {} //! # let mut my_link = DummyLink; @@ -37,7 +37,7 @@ //! }); //! ``` -use crate::import_queue::{BlockImportError, BlockImportResult, Link, Origin}; +use crate::import_queue::{Link, Origin}; use futures::prelude::*; use sp_runtime::traits::{Block as BlockT, NumberFor}; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; @@ -46,6 +46,8 @@ use std::{ task::{Context, Poll}, }; +use super::BlockImportResult; + /// Wraps around an unbounded channel from the `futures` crate. The sender implements `Link` and /// can be used to buffer commands, and the receiver can be used to poll said commands and transfer /// them to another link. @@ -78,11 +80,7 @@ impl Clone for BufferedLinkSender { /// Internal buffered message. enum BlockImportWorkerMsg { - BlocksProcessed( - usize, - usize, - Vec<(Result>, BlockImportError>, B::Hash)>, - ), + BlocksProcessed(usize, usize, Vec<(BlockImportResult, B::Hash)>), JustificationImported(Origin, B::Hash, NumberFor, bool), RequestJustification(B::Hash, NumberFor), } @@ -92,7 +90,7 @@ impl Link for BufferedLinkSender { &mut self, imported: usize, count: usize, - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(BlockImportResult, B::Hash)>, ) { let _ = self .tx diff --git a/client/consensus/common/src/lib.rs b/client/consensus/common/src/lib.rs index 9b4d705769196..640bad237e882 100644 --- a/client/consensus/common/src/lib.rs +++ b/client/consensus/common/src/lib.rs @@ -18,7 +18,22 @@ //! Collection of common consensus specific implementations +pub mod block_import; +pub mod import_queue; +pub mod metrics; + +pub use block_import::{ + BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, + ImportedAux, ImportedState, JustificationImport, JustificationSyncLink, StateAction, + StorageChanges, +}; +pub use import_queue::{ + import_single_block, BasicQueue, BlockImportError, BlockImportStatus, BoxBlockImport, + BoxJustificationImport, DefaultImportQueue, ImportQueue, IncomingBlock, Link, Verifier, +}; + mod longest_chain; + pub mod shared_data; pub use longest_chain::LongestChain; diff --git a/primitives/consensus/common/src/metrics.rs b/client/consensus/common/src/metrics.rs similarity index 96% rename from primitives/consensus/common/src/metrics.rs rename to client/consensus/common/src/metrics.rs index c56f68625b6a0..e9af41914a6e6 100644 --- a/primitives/consensus/common/src/metrics.rs +++ b/client/consensus/common/src/metrics.rs @@ -24,7 +24,7 @@ use prometheus_endpoint::{ use sp_runtime::traits::{Block as BlockT, NumberFor}; -use crate::import_queue::{BlockImportError, BlockImportResult}; +use crate::import_queue::{BlockImportError, BlockImportStatus}; /// Generic Prometheus metrics for common consensus functionality. #[derive(Clone)] @@ -71,7 +71,7 @@ impl Metrics { pub fn report_import( &self, - result: &Result>, BlockImportError>, + result: &Result>, BlockImportError>, ) { let label = match result { Ok(_) => "success", diff --git a/client/consensus/manual-seal/Cargo.toml b/client/consensus/manual-seal/Cargo.toml index 8a236b0591b86..a0de596b005b7 100644 --- a/client/consensus/manual-seal/Cargo.toml +++ b/client/consensus/manual-seal/Cargo.toml @@ -26,6 +26,7 @@ assert_matches = "1.3.0" async-trait = "0.1.50" sc-client-api = { path = "../../api", version = "4.0.0-dev"} +sc-consensus = { version = "0.10.0-dev", path = "../../consensus/common" } sc-consensus-babe = { path = "../../consensus/babe", version = "0.10.0-dev"} sc-consensus-epochs = { path = "../../consensus/epochs", version = "0.10.0-dev"} sp-consensus-babe = { path = "../../../primitives/consensus/babe", version = "0.10.0-dev"} diff --git a/client/consensus/manual-seal/src/consensus.rs b/client/consensus/manual-seal/src/consensus.rs index 1f7ee413b71d0..33a4c8616f6d2 100644 --- a/client/consensus/manual-seal/src/consensus.rs +++ b/client/consensus/manual-seal/src/consensus.rs @@ -19,7 +19,7 @@ //! Extensions for manual seal to produce blocks valid for any runtime. use super::Error; -use sp_consensus::BlockImportParams; +use sc_consensus::BlockImportParams; use sp_inherents::InherentData; use sp_runtime::traits::{Block as BlockT, DigestFor}; diff --git a/client/consensus/manual-seal/src/consensus/babe.rs b/client/consensus/manual-seal/src/consensus/babe.rs index 3773c7c3cf121..9edcb8fd13a17 100644 --- a/client/consensus/manual-seal/src/consensus/babe.rs +++ b/client/consensus/manual-seal/src/consensus/babe.rs @@ -36,12 +36,10 @@ use std::{ time::SystemTime, }; +use sc_consensus::{BlockImportParams, ForkChoiceStrategy, Verifier}; use sp_api::{ProvideRuntimeApi, TransactionFor}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; -use sp_consensus::{ - import_queue::{CacheKeyId, Verifier}, - BlockImportParams, BlockOrigin, ForkChoiceStrategy, -}; +use sp_consensus::{BlockOrigin, CacheKeyId}; use sp_consensus_babe::{ digests::{NextEpochDescriptor, PreDigest, SecondaryPlainPreDigest}, inherents::BabeInherentData, diff --git a/client/consensus/manual-seal/src/error.rs b/client/consensus/manual-seal/src/error.rs index cd7fc0ee73ce1..8585e6a70d644 100644 --- a/client/consensus/manual-seal/src/error.rs +++ b/client/consensus/manual-seal/src/error.rs @@ -20,8 +20,9 @@ //! This is suitable for a testing environment. use futures::channel::{mpsc::SendError, oneshot}; +use sc_consensus::ImportResult; use sp_blockchain::Error as BlockchainError; -use sp_consensus::{Error as ConsensusError, ImportResult}; +use sp_consensus::Error as ConsensusError; use sp_inherents::Error as InherentsError; /// Error code for rpc diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs index 1aacd22aa7bb8..7d4dfefe50c66 100644 --- a/client/consensus/manual-seal/src/lib.rs +++ b/client/consensus/manual-seal/src/lib.rs @@ -22,12 +22,12 @@ use futures::prelude::*; use prometheus_endpoint::Registry; use sc_client_api::backend::{Backend as ClientBackend, Finalizer}; -use sp_blockchain::HeaderBackend; -use sp_consensus::{ - import_queue::{BasicQueue, BoxBlockImport, CacheKeyId, Verifier}, - BlockImport, BlockImportParams, BlockOrigin, Environment, ForkChoiceStrategy, Proposer, - SelectChain, +use sc_consensus::{ + block_import::{BlockImport, BlockImportParams, ForkChoiceStrategy}, + import_queue::{BasicQueue, BoxBlockImport, Verifier}, }; +use sp_blockchain::HeaderBackend; +use sp_consensus::{BlockOrigin, CacheKeyId, Environment, Proposer, SelectChain}; use sp_inherents::CreateInherentDataProviders; use sp_runtime::{traits::Block as BlockT, ConsensusEngineId, Justifications}; use std::{marker::PhantomData, sync::Arc}; @@ -257,9 +257,9 @@ mod tests { use super::*; use sc_basic_authorship::ProposerFactory; use sc_client_api::BlockBackend; + use sc_consensus::ImportedAux; use sc_transaction_pool::{BasicPool, Options, RevalidationType}; use sc_transaction_pool_api::{MaintainedTransactionPool, TransactionPool, TransactionSource}; - use sp_consensus::ImportedAux; use sp_runtime::generic::BlockId; use substrate_test_runtime_client::{ AccountKeyring::*, DefaultTestClientBuilderExt, TestClientBuilder, TestClientBuilderExt, diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs index 0f686bc26e7df..699505b00c3c2 100644 --- a/client/consensus/manual-seal/src/rpc.rs +++ b/client/consensus/manual-seal/src/rpc.rs @@ -25,8 +25,8 @@ use futures::{ }; use jsonrpc_core::Error; use jsonrpc_derive::rpc; +use sc_consensus::ImportedAux; use serde::{Deserialize, Serialize}; -use sp_consensus::ImportedAux; use sp_runtime::EncodedJustification; /// Future's type for jsonrpc diff --git a/client/consensus/manual-seal/src/seal_block.rs b/client/consensus/manual-seal/src/seal_block.rs index be97e0ccc360c..502705b411621 100644 --- a/client/consensus/manual-seal/src/seal_block.rs +++ b/client/consensus/manual-seal/src/seal_block.rs @@ -20,13 +20,11 @@ use crate::{rpc, ConsensusDataProvider, CreatedBlock, Error}; use futures::prelude::*; +use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, StateAction}; use sc_transaction_pool_api::TransactionPool; use sp_api::{ProvideRuntimeApi, TransactionFor}; use sp_blockchain::HeaderBackend; -use sp_consensus::{ - self, BlockImport, BlockImportParams, BlockOrigin, Environment, ForkChoiceStrategy, - ImportResult, Proposer, SelectChain, StateAction, -}; +use sp_consensus::{self, BlockOrigin, Environment, Proposer, SelectChain}; use sp_inherents::{CreateInherentDataProviders, InherentDataProvider}; use sp_runtime::{ generic::BlockId, @@ -147,7 +145,7 @@ pub async fn seal_block( params.body = Some(body); params.finalized = finalize; params.fork_choice = Some(ForkChoiceStrategy::LongestChain); - params.state_action = StateAction::ApplyChanges(sp_consensus::StorageChanges::Changes( + params.state_action = StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes( proposal.storage_changes, )); diff --git a/client/consensus/pow/Cargo.toml b/client/consensus/pow/Cargo.toml index 77ed9ba04ce95..368005fafb136 100644 --- a/client/consensus/pow/Cargo.toml +++ b/client/consensus/pow/Cargo.toml @@ -23,6 +23,7 @@ sp-block-builder = { version = "4.0.0-dev", path = "../../../primitives/block-bu sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" } sp-consensus-pow = { version = "0.10.0-dev", path = "../../../primitives/consensus/pow" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } log = "0.4.8" futures = { version = "0.3.1", features = ["compat"] } futures-timer = "3.0.1" diff --git a/client/consensus/pow/src/lib.rs b/client/consensus/pow/src/lib.rs index 7e5b5a59c9170..85a37e73535ad 100644 --- a/client/consensus/pow/src/lib.rs +++ b/client/consensus/pow/src/lib.rs @@ -43,19 +43,23 @@ mod worker; pub use crate::worker::{MiningBuild, MiningMetadata, MiningWorker}; +use crate::worker::UntilImportedOrTimeout; use codec::{Decode, Encode}; use futures::{Future, StreamExt}; use log::*; use parking_lot::Mutex; use prometheus_endpoint::Registry; use sc_client_api::{self, backend::AuxStore, BlockOf, BlockchainEvents}; +use sc_consensus::{ + BasicQueue, BlockCheckParams, BlockImport, BlockImportParams, BoxBlockImport, + BoxJustificationImport, ForkChoiceStrategy, ImportResult, Verifier, +}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::{well_known_cache_keys::Id as CacheKeyId, HeaderBackend, ProvideCache}; use sp_consensus::{ - import_queue::{BasicQueue, BoxBlockImport, BoxJustificationImport, Verifier}, - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, CanAuthorWith, Environment, - Error as ConsensusError, ForkChoiceStrategy, ImportResult, Proposer, SelectChain, SyncOracle, + BlockOrigin, CanAuthorWith, Environment, Error as ConsensusError, Proposer, SelectChain, + SyncOracle, }; use sp_consensus_pow::{Seal, TotalDifficulty, POW_ENGINE_ID}; use sp_inherents::{CreateInherentDataProviders, InherentDataProvider}; @@ -69,8 +73,6 @@ use std::{ time::Duration, }; -use crate::worker::UntilImportedOrTimeout; - #[derive(derive_more::Display, Debug)] pub enum Error { #[display(fmt = "Header uses the wrong engine {:?}", _0)] @@ -540,7 +542,7 @@ where E::Error: std::fmt::Debug, E::Proposer: Proposer>, SO: SyncOracle + Clone + Send + Sync + 'static, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, CIDP: CreateInherentDataProviders, CAW: CanAuthorWith + Clone + Send + 'static, { diff --git a/client/consensus/pow/src/worker.rs b/client/consensus/pow/src/worker.rs index 572ed364c8f82..c0ca16ccad3aa 100644 --- a/client/consensus/pow/src/worker.rs +++ b/client/consensus/pow/src/worker.rs @@ -23,10 +23,8 @@ use futures::{ use futures_timer::Delay; use log::*; use sc_client_api::ImportNotifications; -use sp_consensus::{ - import_queue::BoxBlockImport, BlockImportParams, BlockOrigin, Proposal, StateAction, - StorageChanges, -}; +use sc_consensus::{BlockImportParams, BoxBlockImport, StateAction, StorageChanges}; +use sp_consensus::{BlockOrigin, Proposal}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header as HeaderT}, @@ -67,7 +65,7 @@ pub struct MiningWorker< Block: BlockT, Algorithm: PowAlgorithm, C: sp_api::ProvideRuntimeApi, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, Proof, > { pub(crate) build: Option>, @@ -82,7 +80,7 @@ where C: sp_api::ProvideRuntimeApi, Algorithm: PowAlgorithm, Algorithm::Difficulty: 'static + Send, - L: sp_consensus::JustificationSyncLink, + L: sc_consensus::JustificationSyncLink, sp_api::TransactionFor: Send + 'static, { /// Get the current best hash. `None` if the worker has just started or the client is doing diff --git a/client/consensus/slots/Cargo.toml b/client/consensus/slots/Cargo.toml index 22697e94d358d..4e027ccab7722 100644 --- a/client/consensus/slots/Cargo.toml +++ b/client/consensus/slots/Cargo.toml @@ -21,6 +21,7 @@ sp-trie = { version = "4.0.0-dev", path = "../../../primitives/trie" } sp-application-crypto = { version = "4.0.0-dev", path = "../../../primitives/application-crypto" } sp-arithmetic = { version = "4.0.0-dev", path = "../../../primitives/arithmetic" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sp-consensus-slots = { version = "0.10.0-dev", path = "../../../primitives/consensus/slots" } sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" } sp-state-machine = { version = "0.10.0-dev", path = "../../../primitives/state-machine" } diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index 1a4f29ff8cb0a..1aa8d984d3fa4 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -36,12 +36,11 @@ use codec::{Decode, Encode}; use futures::{future::Either, Future, TryFutureExt}; use futures_timer::Delay; use log::{debug, error, info, warn}; +use sc_consensus::{BlockImport, JustificationSyncLink}; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO, CONSENSUS_WARN}; use sp_api::{ApiRef, ProvideRuntimeApi}; use sp_arithmetic::traits::BaseArithmetic; -use sp_consensus::{ - BlockImport, CanAuthorWith, JustificationSyncLink, Proposer, SelectChain, SlotData, SyncOracle, -}; +use sp_consensus::{CanAuthorWith, Proposer, SelectChain, SlotData, SyncOracle}; use sp_consensus_slots::Slot; use sp_inherents::CreateInherentDataProviders; use sp_runtime::{ @@ -160,7 +159,7 @@ pub trait SimpleSlotWorker { Self::Claim, Self::EpochData, ) -> Result< - sp_consensus::BlockImportParams< + sc_consensus::BlockImportParams< B, >::Transaction, >, diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml index 5873883a11ee6..856770c31f3e5 100644 --- a/client/db/Cargo.toml +++ b/client/db/Cargo.toml @@ -32,7 +32,6 @@ sp-state-machine = { version = "0.10.0-dev", path = "../../primitives/state-mach sc-executor = { version = "0.10.0-dev", path = "../executor" } sc-state-db = { version = "0.10.0-dev", path = "../state-db" } sp-trie = { version = "4.0.0-dev", path = "../../primitives/trie" } -sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" } sp-database = { version = "4.0.0-dev", path = "../../primitives/database" } parity-db = { version = "0.2.4", optional = true } diff --git a/client/finality-grandpa-warp-sync/Cargo.toml b/client/finality-grandpa-warp-sync/Cargo.toml index 43a7cc0565cde..62fe596083336 100644 --- a/client/finality-grandpa-warp-sync/Cargo.toml +++ b/client/finality-grandpa-warp-sync/Cargo.toml @@ -32,5 +32,6 @@ finality-grandpa = { version = "0.14.1" } rand = "0.8" sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" } sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../client/consensus/common" } sp-keyring = { version = "4.0.0-dev", path = "../../primitives/keyring" } substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } diff --git a/client/finality-grandpa/src/import.rs b/client/finality-grandpa/src/import.rs index 18e5e2c89d067..84e6fa9e1fba5 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/finality-grandpa/src/import.rs @@ -22,14 +22,14 @@ use log::debug; use parity_scale_codec::Encode; use sc_client_api::{backend::Backend, utils::is_descendent_of}; -use sc_consensus::shared_data::{SharedDataLocked, SharedDataLockedUpgradable}; +use sc_consensus::{ + shared_data::{SharedDataLocked, SharedDataLockedUpgradable}, + BlockCheckParams, BlockImport, BlockImportParams, ImportResult, JustificationImport, +}; use sc_telemetry::TelemetryHandle; use sp_api::TransactionFor; use sp_blockchain::{well_known_cache_keys, BlockStatus}; -use sp_consensus::{ - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, Error as ConsensusError, - ImportResult, JustificationImport, SelectChain, -}; +use sp_consensus::{BlockOrigin, Error as ConsensusError, SelectChain}; use sp_finality_grandpa::{ConsensusLog, ScheduledChange, SetId, GRANDPA_ENGINE_ID}; use sp_runtime::{ generic::{BlockId, OpaqueDigestItemId}, diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 1e34202ef8f99..8f8ce25b60a5f 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -66,11 +66,12 @@ use sc_client_api::{ BlockchainEvents, CallExecutor, ExecutionStrategy, ExecutorProvider, Finalizer, LockImportRun, TransactionFor, }; +use sc_consensus::BlockImport; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO}; use sp_api::ProvideRuntimeApi; use sp_application_crypto::AppKey; use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata}; -use sp_consensus::{BlockImport, SelectChain}; +use sp_consensus::SelectChain; use sp_core::crypto::Public; use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use sp_runtime::{ diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index 526451696b8bf..bf9faec707533 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -24,6 +24,10 @@ use environment::HasVoted; use futures::executor::block_on; use futures_timer::Delay; use parking_lot::{Mutex, RwLock}; +use sc_consensus::{ + BlockImport, BlockImportParams, BoxJustificationImport, ForkChoiceStrategy, ImportResult, + ImportedAux, +}; use sc_network::config::{ProtocolConfig, Role}; use sc_network_test::{ Block, BlockImportAdapter, FullPeerConfig, Hash, PassThroughVerifier, Peer, PeersClient, @@ -31,10 +35,7 @@ use sc_network_test::{ }; use sp_api::{ApiRef, ProvideRuntimeApi}; use sp_blockchain::Result; -use sp_consensus::{ - import_queue::BoxJustificationImport, BlockImport, BlockImportParams, BlockOrigin, - ForkChoiceStrategy, ImportResult, ImportedAux, -}; +use sp_consensus::BlockOrigin; use sp_core::H256; use sp_finality_grandpa::{ AuthorityList, EquivocationProof, GrandpaApi, OpaqueKeyOwnershipProof, GRANDPA_ENGINE_ID, diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 7ca98150f9dd8..9c6b580fb9c66 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -53,6 +53,7 @@ smallvec = "1.5.0" sp-arithmetic = { version = "4.0.0-dev", path = "../../primitives/arithmetic" } sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" } sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" } sp-core = { version = "4.0.0-dev", path = "../../primitives/core" } sp-runtime = { version = "4.0.0-dev", path = "../../primitives/runtime" } sp-utils = { version = "4.0.0-dev", path = "../../primitives/utils" } diff --git a/client/network/src/behaviour.rs b/client/network/src/behaviour.rs index 37dfc0cf99c24..73d5ec357b2c7 100644 --- a/client/network/src/behaviour.rs +++ b/client/network/src/behaviour.rs @@ -36,10 +36,8 @@ use libp2p::{ }; use log::debug; use prost::Message; -use sp_consensus::{ - import_queue::{IncomingBlock, Origin}, - BlockOrigin, -}; +use sc_consensus::import_queue::{IncomingBlock, Origin}; +use sp_consensus::BlockOrigin; use sp_runtime::{ traits::{Block as BlockT, NumberFor}, Justifications, diff --git a/client/network/src/chain.rs b/client/network/src/chain.rs index 599e9d796c118..7c131dd75370f 100644 --- a/client/network/src/chain.rs +++ b/client/network/src/chain.rs @@ -19,7 +19,8 @@ //! Blockchain access trait use sc_client_api::{BlockBackend, ProofProvider}; -pub use sc_client_api::{ImportedState, StorageData, StorageKey}; +pub use sc_client_api::{StorageData, StorageKey}; +pub use sc_consensus::ImportedState; use sp_blockchain::{Error, HeaderBackend, HeaderMetadata}; use sp_runtime::traits::{Block as BlockT, BlockIdTo}; diff --git a/client/network/src/config.rs b/client/network/src/config.rs index cddc52352485e..2581a08d42460 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -44,7 +44,8 @@ use libp2p::{ multiaddr, wasm_ext, Multiaddr, PeerId, }; use prometheus_endpoint::Registry; -use sp_consensus::{block_validation::BlockAnnounceValidator, import_queue::ImportQueue}; +use sc_consensus::ImportQueue; +use sp_consensus::block_validation::BlockAnnounceValidator; use sp_runtime::traits::Block as BlockT; use std::{ borrow::Cow, diff --git a/client/network/src/gossip/tests.rs b/client/network/src/gossip/tests.rs index bdef28f9bebe5..f4f96b863d624 100644 --- a/client/network/src/gossip/tests.rs +++ b/client/network/src/gossip/tests.rs @@ -50,7 +50,7 @@ fn build_test_full_node(network_config: config::NetworkConfiguration) struct PassThroughVerifier(bool); #[async_trait::async_trait] - impl sp_consensus::import_queue::Verifier for PassThroughVerifier { + impl sc_consensus::Verifier for PassThroughVerifier { async fn verify( &mut self, origin: sp_consensus::BlockOrigin, @@ -59,7 +59,7 @@ fn build_test_full_node(network_config: config::NetworkConfiguration) body: Option>, ) -> Result< ( - sp_consensus::BlockImportParams, + sc_consensus::BlockImportParams, Option)>>, ), String, @@ -79,16 +79,16 @@ fn build_test_full_node(network_config: config::NetworkConfiguration) )] }); - let mut import = sp_consensus::BlockImportParams::new(origin, header); + let mut import = sc_consensus::BlockImportParams::new(origin, header); import.body = body; import.finalized = self.0; import.justifications = justifications; - import.fork_choice = Some(sp_consensus::ForkChoiceStrategy::LongestChain); + import.fork_choice = Some(sc_consensus::ForkChoiceStrategy::LongestChain); Ok((import, maybe_keys)) } } - let import_queue = Box::new(sp_consensus::import_queue::BasicQueue::new( + let import_queue = Box::new(sc_consensus::BasicQueue::new( PassThroughVerifier(false), Box::new(client.clone()), None, diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 0838657fae530..2af33cd1c5a15 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -48,12 +48,9 @@ use message::{ use notifications::{Notifications, NotificationsOut}; use prometheus_endpoint::{register, Gauge, GaugeVec, Opts, PrometheusError, Registry, U64}; use prost::Message as _; +use sc_consensus::import_queue::{BlockImportError, BlockImportStatus, IncomingBlock, Origin}; use sp_arithmetic::traits::SaturatedConversion; -use sp_consensus::{ - block_validation::BlockAnnounceValidator, - import_queue::{BlockImportError, BlockImportResult, IncomingBlock, Origin}, - BlockOrigin, -}; +use sp_consensus::{block_validation::BlockAnnounceValidator, BlockOrigin}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, CheckedSub, Header as HeaderT, NumberFor, Zero}, @@ -1048,7 +1045,7 @@ impl Protocol { &mut self, imported: usize, count: usize, - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(Result>, BlockImportError>, B::Hash)>, ) { let results = self.sync.on_blocks_processed(imported, count, results); for result in results { diff --git a/client/network/src/protocol/sync.rs b/client/network/src/protocol/sync.rs index 3e49a90e9387d..8918d7adde097 100644 --- a/client/network/src/protocol/sync.rs +++ b/client/network/src/protocol/sync.rs @@ -39,11 +39,11 @@ use extra_requests::ExtraRequests; use futures::{stream::FuturesUnordered, task::Poll, Future, FutureExt, StreamExt}; use libp2p::PeerId; use log::{debug, error, info, trace, warn}; +use sc_consensus::{BlockImportError, BlockImportStatus, IncomingBlock}; use sp_arithmetic::traits::Saturating; use sp_blockchain::{Error as ClientError, HeaderMetadata}; use sp_consensus::{ block_validation::{BlockAnnounceValidator, Validation}, - import_queue::{BlockImportError, BlockImportResult, IncomingBlock}, BlockOrigin, BlockStatus, }; use sp_runtime::{ @@ -1240,7 +1240,7 @@ impl ChainSync { &'a mut self, imported: usize, count: usize, - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(Result>, BlockImportError>, B::Hash)>, ) -> impl Iterator), BadPeer>> + 'a { trace!(target: "sync", "Imported {} of {}", imported, count); @@ -1260,12 +1260,12 @@ impl ChainSync { } match result { - Ok(BlockImportResult::ImportedKnown(number, who)) => { + Ok(BlockImportStatus::ImportedKnown(number, who)) => { if let Some(peer) = who.and_then(|p| self.peers.get_mut(&p)) { peer.update_common_number(number); } }, - Ok(BlockImportResult::ImportedUnknown(number, aux, who)) => { + Ok(BlockImportStatus::ImportedUnknown(number, aux, who)) => { if aux.clear_justification_requests { trace!( target: "sync", @@ -2454,7 +2454,7 @@ mod test { /// /// The node is connected to multiple peers. Both of these peers are having a best block (1) that /// is below our best block (3). Now peer 2 announces a fork of block 3 that we will - /// request from peer 2. After imporitng the fork, peer 2 and then peer 1 will announce block 4. + /// request from peer 2. After importing the fork, peer 2 and then peer 1 will announce block 4. /// But as peer 1 in our view is still at block 1, we will request block 2 (which we already have) /// from it. In the meanwhile peer 2 sends us block 4 and 3 and we send another request for block /// 2 to peer 2. Peer 1 answers with block 2 and then peer 2. This will need to succeed, as we @@ -2777,7 +2777,7 @@ mod test { .rev() .map(|b| { ( - Ok(BlockImportResult::ImportedUnknown( + Ok(BlockImportStatus::ImportedUnknown( b.header().number().clone(), Default::default(), Some(peer_id1.clone()), diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 89685849f5bfd..83cf2d675823a 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -68,8 +68,8 @@ use libp2p::{ use log::{debug, error, info, trace, warn}; use metrics::{Histogram, HistogramVec, MetricSources, Metrics}; use parking_lot::Mutex; +use sc_consensus::{BlockImportError, BlockImportStatus, ImportQueue, Link}; use sc_peerset::PeersetHandle; -use sp_consensus::import_queue::{BlockImportError, BlockImportResult, ImportQueue, Link}; use sp_runtime::traits::{Block as BlockT, NumberFor}; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender}; use std::{ @@ -1265,7 +1265,7 @@ impl<'a, B: BlockT + 'static, H: ExHashT> sp_consensus::SyncOracle for &'a Netwo } } -impl sp_consensus::JustificationSyncLink for NetworkService { +impl sc_consensus::JustificationSyncLink for NetworkService { fn request_justification(&self, hash: &B::Hash, number: NumberFor) { NetworkService::request_justification(self, hash, number); } @@ -2104,7 +2104,7 @@ impl<'a, B: BlockT> Link for NetworkLink<'a, B> { &mut self, imported: usize, count: usize, - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(Result>, BlockImportError>, B::Hash)>, ) { self.protocol .behaviour_mut() diff --git a/client/network/src/service/tests.rs b/client/network/src/service/tests.rs index 7acfeadcae13b..a149b09a22ddc 100644 --- a/client/network/src/service/tests.rs +++ b/client/network/src/service/tests.rs @@ -47,7 +47,7 @@ fn build_test_full_node( struct PassThroughVerifier(bool); #[async_trait::async_trait] - impl sp_consensus::import_queue::Verifier for PassThroughVerifier { + impl sc_consensus::Verifier for PassThroughVerifier { async fn verify( &mut self, origin: sp_consensus::BlockOrigin, @@ -56,7 +56,7 @@ fn build_test_full_node( body: Option>, ) -> Result< ( - sp_consensus::BlockImportParams, + sc_consensus::BlockImportParams, Option)>>, ), String, @@ -75,16 +75,16 @@ fn build_test_full_node( vec![(sp_blockchain::well_known_cache_keys::AUTHORITIES, blob.to_vec())] }); - let mut import = sp_consensus::BlockImportParams::new(origin, header); + let mut import = sc_consensus::BlockImportParams::new(origin, header); import.body = body; import.finalized = self.0; import.justifications = justifications; - import.fork_choice = Some(sp_consensus::ForkChoiceStrategy::LongestChain); + import.fork_choice = Some(sc_consensus::ForkChoiceStrategy::LongestChain); Ok((import, maybe_keys)) } } - let import_queue = Box::new(sp_consensus::import_queue::BasicQueue::new( + let import_queue = Box::new(sc_consensus::BasicQueue::new( PassThroughVerifier(false), Box::new(client.clone()), None, diff --git a/client/network/test/src/block_import.rs b/client/network/test/src/block_import.rs index 4593e06250d36..7b5804e0edb77 100644 --- a/client/network/test/src/block_import.rs +++ b/client/network/test/src/block_import.rs @@ -21,12 +21,11 @@ use super::*; use futures::executor::block_on; use sc_block_builder::BlockBuilderProvider; -use sp_consensus::{ - import_queue::{ - import_single_block, BasicQueue, BlockImportError, BlockImportResult, IncomingBlock, - }, - ImportedAux, +use sc_consensus::{ + import_single_block, BasicQueue, BlockImportError, BlockImportStatus, ImportedAux, + IncomingBlock, }; +use sp_consensus::BlockOrigin; use sp_runtime::generic::BlockId; use substrate_test_runtime_client::{ self, @@ -76,7 +75,7 @@ fn import_single_good_block_works() { block, &mut PassThroughVerifier::new(true), )) { - Ok(BlockImportResult::ImportedUnknown(ref num, ref aux, ref org)) + Ok(BlockImportStatus::ImportedUnknown(ref num, ref aux, ref org)) if *num == number && *aux == expected_aux && *org == Some(peer_id) => {}, r @ _ => panic!("{:?}", r), } @@ -91,7 +90,7 @@ fn import_single_good_known_block_is_ignored() { block, &mut PassThroughVerifier::new(true), )) { - Ok(BlockImportResult::ImportedKnown(ref n, _)) if *n == number => {}, + Ok(BlockImportStatus::ImportedKnown(ref n, _)) if *n == number => {}, _ => panic!(), } } diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index 0bdaa0d14e4fb..553353d77ac36 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -40,7 +40,10 @@ use sc_client_api::{ BlockBackend, BlockImportNotification, BlockchainEvents, FinalityNotification, FinalityNotifications, ImportNotifications, }; -use sc_consensus::LongestChain; +use sc_consensus::{ + BasicQueue, BlockCheckParams, BlockImport, BlockImportParams, BoxJustificationImport, + ForkChoiceStrategy, ImportResult, JustificationImport, LongestChain, Verifier, +}; pub use sc_network::config::EmptyTransactionPool; use sc_network::{ block_request_handler::{self, BlockRequestHandler}, @@ -58,11 +61,8 @@ use sp_blockchain::{ HeaderBackend, Info as BlockchainInfo, Result as ClientResult, }; use sp_consensus::{ - block_import::{BlockImport, ImportResult}, block_validation::{BlockAnnounceValidator, DefaultBlockAnnounceValidator}, - import_queue::{BasicQueue, BoxJustificationImport, Verifier}, - BlockCheckParams, BlockImportParams, BlockOrigin, Error as ConsensusError, ForkChoiceStrategy, - JustificationImport, + BlockOrigin, Error as ConsensusError, }; use sp_core::H256; use sp_runtime::{ @@ -152,7 +152,7 @@ pub enum PeersClient { impl PeersClient { pub fn as_full(&self) -> Option> { match *self { - PeersClient::Full(ref client, ref _backend) => Some(client.clone()), + PeersClient::Full(ref client, _) => Some(client.clone()), _ => None, } } @@ -163,15 +163,15 @@ impl PeersClient { pub fn get_aux(&self, key: &[u8]) -> ClientResult>> { match *self { - PeersClient::Full(ref client, ref _backend) => client.get_aux(key), - PeersClient::Light(ref client, ref _backend) => client.get_aux(key), + PeersClient::Full(ref client, _) => client.get_aux(key), + PeersClient::Light(ref client, _) => client.get_aux(key), } } pub fn info(&self) -> BlockchainInfo { match *self { - PeersClient::Full(ref client, ref _backend) => client.chain_info(), - PeersClient::Light(ref client, ref _backend) => client.chain_info(), + PeersClient::Full(ref client, _) => client.chain_info(), + PeersClient::Light(ref client, _) => client.chain_info(), } } @@ -180,8 +180,8 @@ impl PeersClient { block: &BlockId, ) -> ClientResult::Header>> { match *self { - PeersClient::Full(ref client, ref _backend) => client.header(block), - PeersClient::Light(ref client, ref _backend) => client.header(block), + PeersClient::Full(ref client, _) => client.header(block), + PeersClient::Light(ref client, _) => client.header(block), } } @@ -200,22 +200,22 @@ impl PeersClient { pub fn justifications(&self, block: &BlockId) -> ClientResult> { match *self { - PeersClient::Full(ref client, ref _backend) => client.justifications(block), - PeersClient::Light(ref client, ref _backend) => client.justifications(block), + PeersClient::Full(ref client, _) => client.justifications(block), + PeersClient::Light(ref client, _) => client.justifications(block), } } pub fn finality_notification_stream(&self) -> FinalityNotifications { match *self { - PeersClient::Full(ref client, ref _backend) => client.finality_notification_stream(), - PeersClient::Light(ref client, ref _backend) => client.finality_notification_stream(), + PeersClient::Full(ref client, _) => client.finality_notification_stream(), + PeersClient::Light(ref client, _) => client.finality_notification_stream(), } } pub fn import_notification_stream(&self) -> ImportNotifications { match *self { - PeersClient::Full(ref client, ref _backend) => client.import_notification_stream(), - PeersClient::Light(ref client, ref _backend) => client.import_notification_stream(), + PeersClient::Full(ref client, _) => client.import_notification_stream(), + PeersClient::Light(ref client, _) => client.import_notification_stream(), } } diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index 67e78c8de8de9..04eb8b8b3f78e 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -53,6 +53,7 @@ substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/ru tokio = "0.1.22" sc-transaction-pool = { version = "4.0.0-dev", path = "../transaction-pool" } sc-cli = { version = "0.10.0-dev", path = "../cli" } +sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } [features] test-helpers = ["lazy_static"] diff --git a/client/rpc/src/chain/tests.rs b/client/rpc/src/chain/tests.rs index 9bd08a1796adc..bf682a57a341a 100644 --- a/client/rpc/src/chain/tests.rs +++ b/client/rpc/src/chain/tests.rs @@ -24,11 +24,11 @@ use futures::{ executor, }; use sc_block_builder::BlockBuilderProvider; +use sp_consensus::BlockOrigin; use sp_rpc::list::ListOrValue; use substrate_test_runtime_client::{ prelude::*, runtime::{Block, Header, H256}, - sp_consensus::BlockOrigin, }; #[test] diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index dd99360bafba9..3990d6ea8ad3a 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -25,11 +25,12 @@ use futures::{compat::Future01CompatExt, executor}; use futures01::stream::Stream; use sc_block_builder::BlockBuilderProvider; use sc_rpc_api::DenyUnsafe; +use sp_consensus::BlockOrigin; use sp_core::{hash::H256, storage::ChildInfo, ChangesTrieConfiguration}; use sp_io::hashing::blake2_256; use sp_runtime::generic::BlockId; use std::sync::Arc; -use substrate_test_runtime_client::{prelude::*, runtime, sp_consensus::BlockOrigin}; +use substrate_test_runtime_client::{prelude::*, runtime}; const STORAGE_KEY: &[u8] = b"child"; diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 65393647f3ea4..17aa415363887 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -54,6 +54,7 @@ sp-session = { version = "4.0.0-dev", path = "../../primitives/session" } sp-state-machine = { version = "0.10.0-dev", path = "../../primitives/state-machine" } sp-application-crypto = { version = "4.0.0-dev", path = "../../primitives/application-crypto" } sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../client/consensus/common" } sp-inherents = { version = "4.0.0-dev", path = "../../primitives/inherents" } sp-storage = { version = "4.0.0-dev", path = "../../primitives/storage" } sc-network = { version = "0.10.0-dev", path = "../network" } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 2885fb6deb54c..1f54850059fb5 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -36,6 +36,7 @@ use sc_client_api::{ ForkBlocks, StorageProvider, UsageProvider, }; use sc_client_db::{Backend, DatabaseSettings}; +use sc_consensus::import_queue::ImportQueue; use sc_executor::{NativeExecutionDispatch, NativeExecutor, RuntimeInfo}; use sc_keystore::LocalKeystore; use sc_network::{ @@ -49,9 +50,8 @@ use sc_telemetry::{telemetry, ConnectionMessage, Telemetry, TelemetryHandle, SUB use sc_transaction_pool_api::MaintainedTransactionPool; use sp_api::{CallApiAt, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; -use sp_consensus::{ - block_validation::{BlockAnnounceValidator, Chain, DefaultBlockAnnounceValidator}, - import_queue::ImportQueue, +use sp_consensus::block_validation::{ + BlockAnnounceValidator, Chain, DefaultBlockAnnounceValidator, }; use sp_core::traits::{CodeExecutor, SpawnNamed}; use sp_keystore::{CryptoStore, SyncCryptoStore, SyncCryptoStorePtr}; diff --git a/client/service/src/chain_ops/check_block.rs b/client/service/src/chain_ops/check_block.rs index ab924a3f7d9dd..4728e014540ee 100644 --- a/client/service/src/chain_ops/check_block.rs +++ b/client/service/src/chain_ops/check_block.rs @@ -20,7 +20,7 @@ use crate::error::Error; use codec::Encode; use futures::{future, prelude::*}; use sc_client_api::{BlockBackend, UsageProvider}; -use sp_consensus::import_queue::ImportQueue; +use sc_consensus::import_queue::ImportQueue; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; use crate::chain_ops::import_blocks; diff --git a/client/service/src/chain_ops/import_blocks.rs b/client/service/src/chain_ops/import_blocks.rs index ecf028ffeb3f0..396e5b80f2809 100644 --- a/client/service/src/chain_ops/import_blocks.rs +++ b/client/service/src/chain_ops/import_blocks.rs @@ -19,21 +19,21 @@ use crate::{error, error::Error}; use codec::{Decode, IoReader as CodecIoReader}; use futures::{future, prelude::*}; +use futures_timer::Delay; use log::{info, warn}; use sc_chain_spec::ChainSpec; -use sp_consensus::{ - import_queue::{BlockImportError, BlockImportResult, ImportQueue, IncomingBlock, Link}, - BlockOrigin, +use sc_client_api::UsageProvider; +use sc_consensus::import_queue::{ + BlockImportError, BlockImportStatus, ImportQueue, IncomingBlock, Link, }; +use serde_json::{de::IoRead as JsonIoRead, Deserializer, StreamDeserializer}; +use sp_consensus::BlockOrigin; use sp_runtime::{ generic::SignedBlock, - traits::{Block as BlockT, Header, MaybeSerializeDeserialize, NumberFor, Zero}, + traits::{ + Block as BlockT, CheckedDiv, Header, MaybeSerializeDeserialize, NumberFor, Saturating, Zero, + }, }; - -use futures_timer::Delay; -use sc_client_api::UsageProvider; -use serde_json::{de::IoRead as JsonIoRead, Deserializer, StreamDeserializer}; -use sp_runtime::traits::{CheckedDiv, Saturating}; use std::{ convert::{TryFrom, TryInto}, io::{Read, Seek}, @@ -316,7 +316,7 @@ where &mut self, imported: usize, _num_expected_blocks: usize, - results: Vec<(Result>, BlockImportError>, B::Hash)>, + results: Vec<(Result>, BlockImportError>, B::Hash)>, ) { self.imported_blocks += imported as u64; diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index a0d294908c5f6..553584b15c029 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -45,6 +45,9 @@ use sc_client_api::{ notifications::{StorageEventStream, StorageNotifications}, CallExecutor, ExecutorProvider, KeyIterator, ProofProvider, UsageProvider, }; +use sc_consensus::{ + BlockCheckParams, BlockImportParams, ForkChoiceStrategy, ImportResult, StateAction, +}; use sc_executor::RuntimeVersion; use sc_light::fetcher::ChangesProof; use sc_telemetry::{telemetry, TelemetryHandle, SUBSTRATE_INFO}; @@ -56,10 +59,8 @@ use sp_blockchain::{ self as blockchain, well_known_cache_keys::Id as CacheKeyId, Backend as ChainBackend, Cache, CachedHeaderMetadata, Error, HeaderBackend as ChainHeaderBackend, HeaderMetadata, ProvideCache, }; -use sp_consensus::{ - BlockCheckParams, BlockImportParams, BlockOrigin, BlockStatus, Error as ConsensusError, - ForkChoiceStrategy, ImportResult, StateAction, -}; +use sp_consensus::{BlockOrigin, BlockStatus, Error as ConsensusError}; + use sp_core::{ convert_hash, storage::{well_known_keys, ChildInfo, PrefixedStorageKey, StorageData, StorageKey}, @@ -120,17 +121,18 @@ where _phantom: PhantomData, } -// used in importing a block, where additional changes are made after the runtime -// executed. +/// Used in importing a block, where additional changes are made after the runtime +/// executed. enum PrePostHeader { - // they are the same: no post-runtime digest items. + /// they are the same: no post-runtime digest items. Same(H), - // different headers (pre, post). + /// different headers (pre, post). Different(H, H), } impl PrePostHeader { - // get a reference to the "post-header" -- the header as it should be after all changes are applied. + /// get a reference to the "post-header" -- the header as it should be + /// after all changes are applied. fn post(&self) -> &H { match *self { PrePostHeader::Same(ref h) => h, @@ -138,7 +140,8 @@ impl PrePostHeader { } } - // convert to the "post-header" -- the header as it should be after all changes are applied. + /// convert to the "post-header" -- the header as it should be after + /// all changes are applied. fn into_post(self) -> H { match self { PrePostHeader::Same(h) => h, @@ -149,7 +152,7 @@ impl PrePostHeader { enum PrepareStorageChangesResult, Block: BlockT> { Discard(ImportResult), - Import(Option>>), + Import(Option>>), } /// Create an instance of in-memory client. @@ -577,7 +580,8 @@ where Ok(StorageProof::merge(proofs)) } - /// Generates CHT-based proof for roots of changes tries at given blocks (that are part of single CHT). + /// Generates CHT-based proof for roots of changes tries at given blocks + /// (that are part of single CHT). fn changes_trie_roots_proof_at_cht( &self, cht_size: NumberFor, @@ -603,11 +607,12 @@ where Ok(proof) } - /// Returns changes trie storage and all configurations that have been active in the range [first; last]. + /// Returns changes trie storage and all configurations that have been active + /// in the range [first; last]. /// /// Configurations are returned in descending order (and obviously never overlap). - /// If fail_if_disabled is false, returns maximal consequent configurations ranges, starting from last and - /// stopping on either first, or when CT have been disabled. + /// If fail_if_disabled is false, returns maximal consequent configurations ranges, + /// starting from last and stopping on either first, or when CT have been disabled. /// If fail_if_disabled is true, fails when there's a subrange where CT have been disabled /// inside first..last blocks range. fn require_changes_trie( @@ -656,7 +661,7 @@ where import_block: BlockImportParams>, new_cache: HashMap>, storage_changes: Option< - sp_consensus::StorageChanges>, + sc_consensus::StorageChanges>, >, ) -> sp_blockchain::Result where @@ -749,7 +754,7 @@ where body: Option>, indexed_body: Option>>, storage_changes: Option< - sp_consensus::StorageChanges>, + sc_consensus::StorageChanges>, >, new_cache: HashMap>, finalized: bool, @@ -793,7 +798,7 @@ where let storage_changes = match storage_changes { Some(storage_changes) => { let storage_changes = match storage_changes { - sp_consensus::StorageChanges::Changes(storage_changes) => { + sc_consensus::StorageChanges::Changes(storage_changes) => { self.backend .begin_state_operation(&mut operation.op, BlockId::Hash(parent_hash))?; let (main_sc, child_sc, offchain_sc, tx, _, changes_trie_tx, tx_index) = @@ -813,7 +818,7 @@ where Some((main_sc, child_sc)) }, - sp_consensus::StorageChanges::Import(changes) => { + sc_consensus::StorageChanges::Import(changes) => { let storage = sp_storage::Storage { top: changes.state.into_iter().collect(), children_default: Default::default(), @@ -889,7 +894,8 @@ where operation.op.insert_aux(aux)?; - // we only notify when we are already synced to the tip of the chain or if this import triggers a re-org + // we only notify when we are already synced to the tip of the chain + // or if this import triggers a re-org if make_notifications || tree_route.is_some() { if finalized { operation.notify_finalized.push(hash); @@ -933,7 +939,7 @@ where (_, StateAction::Skip) => (false, None), ( BlockStatus::InChainPruned, - StateAction::ApplyChanges(sp_consensus::StorageChanges::Changes(_)), + StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(_)), ) => return Ok(PrepareStorageChangesResult::Discard(ImportResult::MissingState)), (BlockStatus::InChainPruned, StateAction::Execute) => return Ok(PrepareStorageChangesResult::Discard(ImportResult::MissingState)), @@ -975,7 +981,7 @@ where { return Err(Error::InvalidStateRoot) } - Some(sp_consensus::StorageChanges::Changes(gen_storage_changes)) + Some(sc_consensus::StorageChanges::Changes(gen_storage_changes)) }, // No block body, no storage changes (true, None, None) => None, @@ -1852,7 +1858,7 @@ where /// objects. Otherwise, importing blocks directly into the client would be bypassing /// important verification work. #[async_trait::async_trait] -impl sp_consensus::BlockImport for &Client +impl sc_consensus::BlockImport for &Client where B: backend::Backend, E: CallExecutor + Send + Sync, @@ -1960,7 +1966,7 @@ where } #[async_trait::async_trait] -impl sp_consensus::BlockImport for Client +impl sc_consensus::BlockImport for Client where B: backend::Backend, E: CallExecutor + Send + Sync, diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 5d7c490db6abf..a6cefcd5db623 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -67,6 +67,7 @@ pub use sc_chain_spec::{ Properties, RuntimeGenesis, }; use sc_client_api::{blockchain::HeaderBackend, BlockchainEvents}; +pub use sc_consensus::ImportQueue; pub use sc_executor::NativeExecutionDispatch; #[doc(hidden)] pub use sc_network::config::{OnDemand, TransactionImport, TransactionImportFuture}; @@ -74,7 +75,6 @@ pub use sc_rpc::Metadata as RpcMetadata; pub use sc_tracing::TracingReceiver; pub use sc_transaction_pool::Options as TransactionPoolOptions; pub use sc_transaction_pool_api::{error::IntoPoolError, InPoolTransaction, TransactionPool}; -pub use sp_consensus::import_queue::ImportQueue; #[doc(hidden)] pub use std::{ops::Deref, result::Result, sync::Arc}; pub use task_manager::{SpawnTaskHandle, TaskManager}; diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index e7e627f919c12..d0081b3249117 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -31,6 +31,7 @@ futures = { version = "0.3.1", features = ["compat"] } sc-service = { version = "0.10.0-dev", features = ["test-helpers"], path = "../../service" } sc-network = { version = "0.10.0-dev", path = "../../network" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" } sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" } sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" } diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index d6a506ab63d75..dd0a33b7e8584 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -24,13 +24,13 @@ use sc_client_api::{in_mem, BlockBackend, BlockchainEvents, StorageProvider}; use sc_client_db::{ Backend, DatabaseSettings, DatabaseSettingsSrc, KeepBlocks, PruningMode, TransactionStorageMode, }; +use sc_consensus::{ + BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, +}; use sc_executor::native_executor_instance; use sc_service::client::{self, new_in_mem, Client, LocalCallExecutor}; use sp_api::ProvideRuntimeApi; -use sp_consensus::{ - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, BlockStatus, - Error as ConsensusError, ForkChoiceStrategy, ImportResult, SelectChain, -}; +use sp_consensus::{BlockOrigin, BlockStatus, Error as ConsensusError, SelectChain}; use sp_core::{blake2_256, testing::TaskExecutor, ChangesTrieConfiguration, H256}; use sp_runtime::{ generic::BlockId, diff --git a/docs/STYLE_GUIDE.md b/docs/STYLE_GUIDE.md index e6f217f2b4859..ea070cdbc59f3 100644 --- a/docs/STYLE_GUIDE.md +++ b/docs/STYLE_GUIDE.md @@ -2,6 +2,9 @@ title: Style Guide for Rust in Substrate --- +Where possible these styles are enforced by settings in `rustfmt.toml` so if you run `cargo fmt` +then you will adhere to most of these style guidelines automatically. + # Formatting - Indent using tabs. diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index da9d6adff6f3f..4ee5154a6b0fc 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -39,7 +39,7 @@ pub use frame_metadata::{ }; pub use sp_runtime::{traits::Dispatchable, DispatchError}; -/// The return typ of a `Dispatchable` in frame. When returned explicitly from +/// The return type of a `Dispatchable` in frame. When returned explicitly from /// a dispatchable function it allows overriding the default `PostDispatchInfo` /// returned from a dispatch. pub type DispatchResultWithPostInfo = diff --git a/primitives/blockchain/src/backend.rs b/primitives/blockchain/src/backend.rs index 642e7c5b9528f..fb0ef5b4d7a74 100644 --- a/primitives/blockchain/src/backend.rs +++ b/primitives/blockchain/src/backend.rs @@ -293,7 +293,7 @@ pub enum BlockStatus { /// A list of all well known keys in the blockchain cache. pub mod well_known_cache_keys { /// The type representing cache keys. - pub type Id = sp_consensus::import_queue::CacheKeyId; + pub type Id = sp_consensus::CacheKeyId; /// A list of authorities. pub const AUTHORITIES: Id = *b"auth"; diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index 5a9d1814bd63f..ab4f5a24f5c56 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -13,15 +13,14 @@ readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] - [dependencies] -thiserror = "1.0.21" -libp2p = { version = "0.37.1", default-features = false } +async-trait = "0.1.42" +codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } +futures = { version = "0.3.1", features = ["thread-pool"] } log = "0.4.8" sp-core = { path= "../../core", version = "4.0.0-dev"} sp-inherents = { version = "4.0.0-dev", path = "../../inherents" } sp-state-machine = { version = "0.10.0-dev", path = "../../state-machine" } -futures = { version = "0.3.1", features = ["thread-pool"] } futures-timer = "3.0.1" sp-std = { version = "4.0.0-dev", path = "../../std" } sp-version = { version = "4.0.0-dev", path = "../../version" } @@ -29,12 +28,11 @@ sp-runtime = { version = "4.0.0-dev", path = "../../runtime" } sp-utils = { version = "4.0.0-dev", path = "../../utils" } sp-trie = { version = "4.0.0-dev", path = "../../trie" } sp-api = { version = "4.0.0-dev", path = "../../api" } -codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } parking_lot = "0.11.1" serde = { version = "1.0", features = ["derive"] } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.9.0"} wasm-timer = "0.2.5" -async-trait = "0.1.50" +thiserror = "1.0.21" [dev-dependencies] futures = "0.3.9" diff --git a/primitives/consensus/common/src/lib.rs b/primitives/consensus/common/src/lib.rs index eb524422a6e25..f6c1e028b9457 100644 --- a/primitives/consensus/common/src/lib.rs +++ b/primitives/consensus/common/src/lib.rs @@ -21,14 +21,6 @@ //! change. Implementors of traits should not rely on the interfaces to remain //! the same. -// This provides "unused" building blocks to other crates -#![allow(dead_code)] -// our error-chain could potentially blow up otherwise -#![recursion_limit = "128"] - -#[macro_use] -extern crate log; - use std::{sync::Arc, time::Duration}; use futures::prelude::*; @@ -38,25 +30,19 @@ use sp_runtime::{ }; use sp_state_machine::StorageProof; -pub mod block_import; pub mod block_validation; pub mod error; pub mod evaluation; -pub mod import_queue; -mod metrics; mod select_chain; pub use self::error::Error; -pub use block_import::{ - BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, ForkChoiceStrategy, - ImportResult, ImportedAux, ImportedState, JustificationImport, JustificationSyncLink, - StateAction, StorageChanges, -}; -pub use import_queue::DefaultImportQueue; pub use select_chain::SelectChain; pub use sp_inherents::InherentData; pub use sp_state_machine::Backend as StateBackend; +/// Type of keys in the blockchain cache that consensus module could use for its needs. +pub type CacheKeyId = [u8; 4]; + /// Block status. #[derive(Debug, PartialEq, Eq)] pub enum BlockStatus { @@ -72,6 +58,23 @@ pub enum BlockStatus { Unknown, } +/// Block data origin. +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub enum BlockOrigin { + /// Genesis block built into the client. + Genesis, + /// Block is part of the initial sync with the network. + NetworkInitialSync, + /// Block was broadcasted on the network. + NetworkBroadcast, + /// Block that was received from the network and validated in the consensus process. + ConsensusBroadcast, + /// Block that was collated by this node. + Own, + /// Block was imported from a file. + File, +} + /// Environment for a Consensus instance. /// /// Creates proposer instance. diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index ef778ca968057..bf1c9898972ca 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -19,10 +19,9 @@ use codec::alloc::collections::hash_map::HashMap; use sc_client_api::{backend::Finalizer, client::BlockBackend}; +use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy}; use sc_service::client::Client; -use sp_consensus::{ - BlockImport, BlockImportParams, BlockOrigin, Error as ConsensusError, ForkChoiceStrategy, -}; +use sp_consensus::{BlockOrigin, Error as ConsensusError}; use sp_runtime::{generic::BlockId, traits::Block as BlockT, Justification, Justifications}; /// Extension trait for a test client. diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 2a4be6787dd7d..cc57f12ea31a3 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -52,6 +52,7 @@ serde = { version = "1.0.126", optional = true, features = ["derive"] } [dev-dependencies] sc-block-builder = { version = "0.10.0-dev", path = "../../client/block-builder" } sc-executor = { version = "0.10.0-dev", path = "../../client/executor" } +sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" } substrate-test-runtime-client = { version = "2.0.0", path = "./client" } futures = "0.3.9" diff --git a/test-utils/runtime/client/Cargo.toml b/test-utils/runtime/client/Cargo.toml index 24e9f8af29442..9f1dc32a64ffb 100644 --- a/test-utils/runtime/client/Cargo.toml +++ b/test-utils/runtime/client/Cargo.toml @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sc-light = { version = "4.0.0-dev", path = "../../../client/light" } sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" } +sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sc-block-builder = { version = "0.10.0-dev", path = "../../../client/block-builder" } substrate-test-client = { version = "2.0.0", path = "../../client" } sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" } @@ -23,6 +24,5 @@ sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } codec = { package = "parity-scale-codec", version = "2.0.0" } sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" } -sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" } futures = "0.3.9" diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 8da8f5c5db4e3..bdf45ceae88b4 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -1244,12 +1244,12 @@ mod tests { use codec::Encode; use sc_block_builder::BlockBuilderProvider; use sp_api::ProvideRuntimeApi; + use sp_consensus::BlockOrigin; use sp_core::storage::well_known_keys::HEAP_PAGES; use sp_runtime::generic::BlockId; use sp_state_machine::ExecutionStrategy; use substrate_test_runtime_client::{ - prelude::*, runtime::TestAPI, sp_consensus::BlockOrigin, DefaultTestClientBuilderExt, - TestClientBuilder, + prelude::*, runtime::TestAPI, DefaultTestClientBuilderExt, TestClientBuilder, }; #[test] diff --git a/test-utils/test-runner/src/lib.rs b/test-utils/test-runner/src/lib.rs index c73ead9eb59ab..9f0a8d5d6cb6a 100644 --- a/test-utils/test-runner/src/lib.rs +++ b/test-utils/test-runner/src/lib.rs @@ -227,10 +227,11 @@ //! } //! ``` +use sc_consensus::BlockImport; use sc_executor::NativeExecutionDispatch; use sc_service::TFullClient; use sp_api::{ConstructRuntimeApi, TransactionFor}; -use sp_consensus::{BlockImport, SelectChain}; +use sp_consensus::SelectChain; use sp_inherents::InherentDataProvider; use sp_runtime::traits::{Block as BlockT, SignedExtension};