Move client consensus parts out of primitives and into client/consensus/api (#9319)

* moved client code out of primitives

* bump ci

* Fixup from merge.

* Removed unused deps thanks to review feedback

* Removing unneeded deps

* updating lock file

* note about rustfmt

* fixed typo to bump ci

* Move lonely CacheKeyId to parent

* cargo fmt

* updating import style

* Update docs/STYLE_GUIDE.md

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Squirrel
2021-07-30 14:27:17 +01:00
committed by GitHub
parent 8a44bec2dc
commit df59596ec0
69 changed files with 339 additions and 283 deletions
+25 -3
View File
@@ -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",
@@ -32,7 +32,7 @@ pub fn new_partial(
FullClient,
FullBackend,
FullSelectChain,
sp_consensus::DefaultImportQueue<Block, FullClient>,
sc_consensus::DefaultImportQueue<Block, FullClient>,
sc_transaction_pool::FullPool<Block, FullClient>,
(
sc_finality_grandpa::GrandpaBlockImport<
+3 -4
View File
@@ -46,7 +46,7 @@ pub fn new_partial(
FullClient,
FullBackend,
FullSelectChain,
sp_consensus::DefaultImportQueue<Block, FullClient>,
sc_consensus::DefaultImportQueue<Block, FullClient>,
sc_transaction_pool::FullPool<Block, FullClient>,
(
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;
@@ -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" }
+1
View File
@@ -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" }
+2 -3
View File
@@ -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::{
-1
View File
@@ -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;
@@ -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"
@@ -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,
+9 -9
View File
@@ -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<B, Error = Error> + Send + Sync + 'static,
PF::Proposer: Proposer<B, Error = Error, Transaction = sp_api::TransactionFor<C, B>>,
SO: SyncOracle + Send + Sync + Clone,
L: sp_consensus::JustificationSyncLink<B>,
L: sc_consensus::JustificationSyncLink<B>,
CIDP: CreateInherentDataProviders<B, ()> + Send,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + 'static,
@@ -277,7 +277,7 @@ where
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync + 'static,
Error: std::error::Error + Send + From<sp_consensus::Error> + 'static,
SO: SyncOracle + Send + Sync + Clone,
L: sp_consensus::JustificationSyncLink<B>,
L: sc_consensus::JustificationSyncLink<B>,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + 'static,
{
AuraWorker {
@@ -324,7 +324,7 @@ where
P::Public: AppPublic + Public + Member + Encode + Decode + Hash,
P::Signature: TryFrom<Vec<u8>> + Member + Encode + Decode + Hash + Debug,
SO: SyncOracle + Send + Clone,
L: sp_consensus::JustificationSyncLink<B>,
L: sc_consensus::JustificationSyncLink<B>,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + 'static,
Error: std::error::Error + Send + From<sp_consensus::Error> + 'static,
{
@@ -395,7 +395,7 @@ where
Self::Claim,
Self::EpochData,
) -> Result<
sp_consensus::BlockImportParams<B, sp_api::TransactionFor<C, B>>,
sc_consensus::BlockImportParams<B, sp_api::TransactionFor<C, B>>,
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;
@@ -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" }
+13 -8
View File
@@ -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<B> + 'static,
L: sc_consensus::JustificationSyncLink<B> + 'static,
CIDP: CreateInherentDataProviders<B, ()> + Send + Sync + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + 'static,
@@ -668,7 +673,7 @@ where
E::Proposer: Proposer<B, Error = Error, Transaction = sp_api::TransactionFor<C, B>>,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync + 'static,
SO: SyncOracle + Send + Clone,
L: sp_consensus::JustificationSyncLink<B>,
L: sc_consensus::JustificationSyncLink<B>,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>>,
Error: std::error::Error + Send + From<ConsensusError> + From<I::Error> + 'static,
{
@@ -774,7 +779,7 @@ where
StorageChanges<I::Transaction, B>,
Self::Claim,
Self::EpochData,
) -> Result<sp_consensus::BlockImportParams<B, I::Transaction>, sp_consensus::Error>
) -> Result<sc_consensus::BlockImportParams<B, I::Transaction>, 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),
+2 -4
View File
@@ -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,
+17 -2
View File
@@ -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" }
@@ -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<B: BlockT, Transaction> BlockImport<B> 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.
@@ -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<B: BlockT> {
pub origin: Option<Origin>,
/// 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<B: BlockT> {
pub state: Option<ImportedState<B>>,
}
/// 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<B: BlockT>: Send + Sync {
@@ -137,9 +135,10 @@ pub trait Link<B: BlockT>: Send {
&mut self,
_imported: usize,
_count: usize,
_results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
_results: Vec<(BlockImportResult<B>, B::Hash)>,
) {
}
/// Justification import result.
fn justification_imported(
&mut self,
@@ -149,13 +148,14 @@ pub trait Link<B: BlockT>: Send {
_success: bool,
) {
}
/// Request a justification for the given block.
fn request_justification(&mut self, _hash: &B::Hash, _number: NumberFor<B>) {}
}
/// Block import successful result.
#[derive(Debug, PartialEq)]
pub enum BlockImportResult<N: std::fmt::Debug + PartialEq> {
pub enum BlockImportStatus<N: std::fmt::Debug + PartialEq> {
/// Imported known block.
ImportedKnown(N, Option<Origin>),
/// Imported unknown block.
@@ -181,13 +181,15 @@ pub enum BlockImportError {
Other(ConsensusError),
}
type BlockImportResult<B> = Result<BlockImportStatus<NumberFor<B>>, BlockImportError>;
/// Single block import function.
pub async fn import_single_block<B: BlockT, V: Verifier<B>, Transaction: Send + 'static>(
import_handle: &mut impl BlockImport<B, Transaction = Transaction, Error = ConsensusError>,
block_origin: BlockOrigin,
block: IncomingBlock<B>,
verifier: &mut V,
) -> Result<BlockImportResult<NumberFor<B>>, BlockImportError> {
) -> BlockImportResult<B> {
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<B>,
verifier: &mut V,
metrics: Option<Metrics>,
) -> Result<BlockImportResult<NumberFor<B>>, BlockImportError> {
) -> BlockImportResult<B> {
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 {
@@ -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<B: BlockT, Transaction> {
/// Channel to send justifcation import messages to the background task.
/// Channel to send justification import messages to the background task.
justification_sender: TracingUnboundedSender<worker_messages::ImportJustification<B>>,
/// Channel to send block import messages to the background task.
block_import_sender: TracingUnboundedSender<worker_messages::ImportBlocks<B>>,
@@ -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<B: BlockT, Transaction: Send + 'static>(
@@ -325,12 +325,13 @@ struct ImportManyBlocksResult<B: BlockT> {
/// The total number of blocks processed.
block_count: usize,
/// The import results for each block.
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, 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<B: BlockT, V: Verifier<B>, Transaction: Send + 'static>(
import_handle: &mut BoxBlockImport<B, Transaction>,
blocks_origin: BlockOrigin,
@@ -410,11 +411,11 @@ async fn import_many_blocks<B: BlockT, V: Verifier<B>, 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<Block> 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<Block> 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<BlockImportResult<BlockNumber>, BlockImportError>, Hash)>,
results: Vec<(Result<BlockImportStatus<BlockNumber>, BlockImportError>, Hash)>,
) {
if let Some(hash) = results.into_iter().find_map(|(r, h)| r.ok().map(|_| h)) {
self.events.push(Event::BlockImported(hash));
@@ -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<Block> 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<B: BlockT> Clone for BufferedLinkSender<B> {
/// Internal buffered message.
enum BlockImportWorkerMsg<B: BlockT> {
BlocksProcessed(
usize,
usize,
Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
),
BlocksProcessed(usize, usize, Vec<(BlockImportResult<B>, B::Hash)>),
JustificationImported(Origin, B::Hash, NumberFor<B>, bool),
RequestJustification(B::Hash, NumberFor<B>),
}
@@ -92,7 +90,7 @@ impl<B: BlockT> Link<B> for BufferedLinkSender<B> {
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(BlockImportResult<B>, B::Hash)>,
) {
let _ = self
.tx
@@ -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;
@@ -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<B: BlockT>(
&self,
result: &Result<BlockImportResult<NumberFor<B>>, BlockImportError>,
result: &Result<BlockImportStatus<NumberFor<B>>, BlockImportError>,
) {
let label = match result {
Ok(_) => "success",
@@ -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"}
@@ -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};
@@ -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,
@@ -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
@@ -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,
@@ -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
@@ -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<B, BI, SC, C, E, TP, CIDP>(
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,
));
@@ -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"
+8 -6
View File
@@ -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<B: BlockT> {
#[display(fmt = "Header uses the wrong engine {:?}", _0)]
@@ -540,7 +542,7 @@ where
E::Error: std::fmt::Debug,
E::Proposer: Proposer<Block, Transaction = sp_api::TransactionFor<C, Block>>,
SO: SyncOracle + Clone + Send + Sync + 'static,
L: sp_consensus::JustificationSyncLink<Block>,
L: sc_consensus::JustificationSyncLink<Block>,
CIDP: CreateInherentDataProviders<Block, ()>,
CAW: CanAuthorWith<Block> + Clone + Send + 'static,
{
+4 -6
View File
@@ -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<Block>,
C: sp_api::ProvideRuntimeApi<Block>,
L: sp_consensus::JustificationSyncLink<Block>,
L: sc_consensus::JustificationSyncLink<Block>,
Proof,
> {
pub(crate) build: Option<MiningBuild<Block, Algorithm, C, Proof>>,
@@ -82,7 +80,7 @@ where
C: sp_api::ProvideRuntimeApi<Block>,
Algorithm: PowAlgorithm<Block>,
Algorithm::Difficulty: 'static + Send,
L: sp_consensus::JustificationSyncLink<Block>,
L: sc_consensus::JustificationSyncLink<Block>,
sp_api::TransactionFor<C, Block>: Send + 'static,
{
/// Get the current best hash. `None` if the worker has just started or the client is doing
@@ -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" }
+3 -4
View File
@@ -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<B: BlockT> {
Self::Claim,
Self::EpochData,
) -> Result<
sp_consensus::BlockImportParams<
sc_consensus::BlockImportParams<
B,
<Self::BlockImport as BlockImport<B>>::Transaction,
>,
-1
View File
@@ -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 }
@@ -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" }
@@ -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},
+2 -1
View File
@@ -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::{
@@ -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,
+1
View File
@@ -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" }
+2 -4
View File
@@ -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,
+2 -1
View File
@@ -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};
+2 -1
View File
@@ -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,
+5 -5
View File
@@ -50,7 +50,7 @@ fn build_test_full_node(network_config: config::NetworkConfiguration)
struct PassThroughVerifier(bool);
#[async_trait::async_trait]
impl<B: BlockT> sp_consensus::import_queue::Verifier<B> for PassThroughVerifier {
impl<B: BlockT> sc_consensus::Verifier<B> 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<Vec<B::Extrinsic>>,
) -> Result<
(
sp_consensus::BlockImportParams<B, ()>,
sc_consensus::BlockImportParams<B, ()>,
Option<Vec<(sp_blockchain::well_known_cache_keys::Id, Vec<u8>)>>,
),
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,
+3 -6
View File
@@ -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<B: BlockT> Protocol<B> {
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
) {
let results = self.sync.on_blocks_processed(imported, count, results);
for result in results {
@@ -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<B: BlockT> ChainSync<B> {
&'a mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
) -> impl Iterator<Item = Result<(PeerId, BlockRequest<B>), BadPeer>> + 'a {
trace!(target: "sync", "Imported {} of {}", imported, count);
@@ -1260,12 +1260,12 @@ impl<B: BlockT> ChainSync<B> {
}
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()),
+3 -3
View File
@@ -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<B: BlockT, H: ExHashT> sp_consensus::JustificationSyncLink<B> for NetworkService<B, H> {
impl<B: BlockT, H: ExHashT> sc_consensus::JustificationSyncLink<B> for NetworkService<B, H> {
fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>) {
NetworkService::request_justification(self, hash, number);
}
@@ -2104,7 +2104,7 @@ impl<'a, B: BlockT> Link<B> for NetworkLink<'a, B> {
&mut self,
imported: usize,
count: usize,
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
) {
self.protocol
.behaviour_mut()
@@ -47,7 +47,7 @@ fn build_test_full_node(
struct PassThroughVerifier(bool);
#[async_trait::async_trait]
impl<B: BlockT> sp_consensus::import_queue::Verifier<B> for PassThroughVerifier {
impl<B: BlockT> sc_consensus::Verifier<B> for PassThroughVerifier {
async fn verify(
&mut self,
origin: sp_consensus::BlockOrigin,
@@ -56,7 +56,7 @@ fn build_test_full_node(
body: Option<Vec<B::Extrinsic>>,
) -> Result<
(
sp_consensus::BlockImportParams<B, ()>,
sc_consensus::BlockImportParams<B, ()>,
Option<Vec<(sp_blockchain::well_known_cache_keys::Id, Vec<u8>)>>,
),
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,
@@ -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!(),
}
}
+18 -18
View File
@@ -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<Arc<PeersFullClient>> {
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<Option<Vec<u8>>> {
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<Block> {
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<Block>,
) -> ClientResult<Option<<Block as BlockT>::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<Block>) -> ClientResult<Option<Justifications>> {
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<Block> {
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<Block> {
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(),
}
}
+1
View File
@@ -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"]
+1 -1
View File
@@ -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]
+2 -1
View File
@@ -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";
+1
View File
@@ -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" }
+3 -3
View File
@@ -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};
@@ -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;
@@ -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<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
) {
self.imported_blocks += imported as u64;
+30 -24
View File
@@ -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<RA>,
}
// 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<H> {
// 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<H> PrePostHeader<H> {
// 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<H> PrePostHeader<H> {
}
}
// 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<H> PrePostHeader<H> {
enum PrepareStorageChangesResult<B: backend::Backend<Block>, Block: BlockT> {
Discard(ImportResult),
Import(Option<sp_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>>),
Import(Option<sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>>),
}
/// 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<Block>,
@@ -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<Block, backend::TransactionFor<B, Block>>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
storage_changes: Option<
sp_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
>,
) -> sp_blockchain::Result<ImportResult>
where
@@ -749,7 +754,7 @@ where
body: Option<Vec<Block::Extrinsic>>,
indexed_body: Option<Vec<Vec<u8>>>,
storage_changes: Option<
sp_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
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<B, E, Block, RA> sp_consensus::BlockImport<Block> for &Client<B, E, Block, RA>
impl<B, E, Block, RA> sc_consensus::BlockImport<Block> for &Client<B, E, Block, RA>
where
B: backend::Backend<Block>,
E: CallExecutor<Block> + Send + Sync,
@@ -1960,7 +1966,7 @@ where
}
#[async_trait::async_trait]
impl<B, E, Block, RA> sp_consensus::BlockImport<Block> for Client<B, E, Block, RA>
impl<B, E, Block, RA> sc_consensus::BlockImport<Block> for Client<B, E, Block, RA>
where
B: backend::Backend<Block>,
E: CallExecutor<Block> + Send + Sync,
+1 -1
View File
@@ -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};
+1
View File
@@ -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" }
@@ -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,
+3
View File
@@ -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.
+1 -1
View File
@@ -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 =
@@ -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";
@@ -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"
@@ -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.
@@ -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.
+1
View File
@@ -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"
@@ -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"
+2 -2
View File
@@ -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]
+2 -1
View File
@@ -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};