Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit b79a7a7

Browse files
gterzianrphmeier
authored andcommitted
move import queue to consensus-common (#1282)
1 parent b98d3b8 commit b79a7a7

File tree

20 files changed

+594
-473
lines changed

20 files changed

+594
-473
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/client/src/client.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use runtime_primitives::{
2525
Justification,
2626
generic::{BlockId, SignedBlock},
2727
};
28-
use consensus::{ImportBlock, ImportResult, BlockOrigin};
28+
use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, BlockOrigin};
2929
use runtime_primitives::traits::{
3030
Block as BlockT, Header as HeaderT, Zero, As, NumberFor, CurrentHeight, BlockNumberToHash,
3131
ApiRef, ProvideRuntimeApi, Digest, DigestItem,
@@ -1019,7 +1019,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
10191019
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
10201020
Block: BlockT<Hash=H256>,
10211021
{
1022-
type Error = Error;
1022+
type Error = ConsensusError;
10231023

10241024
/// Import a checked and validated block. If a justification is provided in
10251025
/// `ImportBlock` then `finalized` *must* be true.
@@ -1044,9 +1044,10 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
10441044

10451045
let parent_hash = header.parent_hash().clone();
10461046

1047-
match self.backend.blockchain().status(BlockId::Hash(parent_hash))? {
1048-
blockchain::BlockStatus::InChain => {},
1049-
blockchain::BlockStatus::Unknown => return Ok(ImportResult::UnknownParent),
1047+
match self.backend.blockchain().status(BlockId::Hash(parent_hash)) {
1048+
Ok(blockchain::BlockStatus::InChain) => {},
1049+
Ok(blockchain::BlockStatus::Unknown) => return Ok(ImportResult::UnknownParent),
1050+
Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into())
10501051
}
10511052

10521053
let import_headers = if post_digests.is_empty() {
@@ -1081,7 +1082,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
10811082
"best" => ?hash,
10821083
"origin" => ?origin
10831084
);
1084-
result.map_err(|e| e.into())
1085+
result.map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()).into())
10851086
}
10861087
}
10871088

core/consensus/aura/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ parking_lot = "0.4"
2121
error-chain = "0.12"
2222
log = "0.3"
2323
substrate-consensus-common = { path = "../common" }
24-
substrate-network = { path = "../../network" }
2524

2625
[dev-dependencies]
2726
substrate-keyring = { path = "../../keyring" }
2827
substrate-executor = { path = "../../executor" }
28+
substrate-network = { path = "../../network", features = ["test-helpers"]}
2929
substrate-service = { path = "../../service" }
3030
substrate-test-client = { path = "../../test-client" }
3131
env_logger = "0.4"
32-
33-
[target.'cfg(test)'.dependencies]
34-
substrate-network = { path = "../../network", features = ["test-helpers"], optional = true }

core/consensus/aura/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ extern crate substrate_consensus_aura_primitives as aura_primitives;
3737
extern crate substrate_consensus_common as consensus_common;
3838
extern crate tokio;
3939
extern crate sr_version as runtime_version;
40-
extern crate substrate_network as network;
4140
extern crate parking_lot;
4241

4342
#[macro_use]
@@ -48,6 +47,8 @@ extern crate futures;
4847
#[cfg(test)]
4948
extern crate substrate_keyring as keyring;
5049
#[cfg(test)]
50+
extern crate substrate_network as network;
51+
#[cfg(test)]
5152
extern crate substrate_service as service;
5253
#[cfg(test)]
5354
extern crate substrate_test_client as test_client;
@@ -60,13 +61,13 @@ use std::sync::Arc;
6061
use std::time::Duration;
6162

6263
use codec::Encode;
63-
use consensus_common::{Authorities, BlockImport, Environment, Proposer};
64+
use consensus_common::{Authorities, BlockImport, Environment, Error as ConsensusError, Proposer};
65+
use consensus_common::import_queue::{Verifier, BasicQueue};
6466
use client::ChainHead;
6567
use client::block_builder::api::BlockBuilder as BlockBuilderApi;
6668
use consensus_common::{ImportBlock, BlockOrigin};
6769
use runtime_primitives::{generic, generic::BlockId, Justification, BasicInherentData};
6870
use runtime_primitives::traits::{Block, Header, Digest, DigestItemFor, ProvideRuntimeApi};
69-
use network::import_queue::{Verifier, BasicQueue};
7071
use primitives::{AuthorityId, ed25519};
7172

7273
use futures::{Stream, Future, IntoFuture, future::{self, Either}};
@@ -214,7 +215,6 @@ pub fn start_aura<B, C, E, I, SO, Error>(
214215
Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>,
215216
{
216217
let make_authorship = move || {
217-
use futures::future;
218218

219219
let client = client.clone();
220220
let pair = local_key.clone();
@@ -596,7 +596,7 @@ pub fn import_queue<B, C, E, MakeInherent, Inherent>(
596596
make_inherent: MakeInherent,
597597
) -> AuraImportQueue<B, C, E, MakeInherent> where
598598
B: Block,
599-
C: Authorities<B> + BlockImport<B,Error=::client::error::Error> + ProvideRuntimeApi + Send + Sync,
599+
C: Authorities<B> + BlockImport<B,Error=ConsensusError> + ProvideRuntimeApi + Send + Sync,
600600
C::Api: BlockBuilderApi<B, Inherent>,
601601
DigestItemFor<B>: CompatibleDigestItem,
602602
E: ExtraVerification<B>,

core/consensus/common/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
55
description = "Common utilities for substrate consensus"
66

77
[dependencies]
8+
log = "0.4"
9+
parking_lot = "0.7"
810
substrate-primitives = { path= "../../primitives" }
911
error-chain = "0.12"
1012
futures = "0.1"
@@ -13,3 +15,6 @@ sr-primitives = { path = "../../sr-primitives" }
1315
tokio = "0.1.7"
1416
parity-codec = "2.1"
1517
parity-codec-derive = "2.0"
18+
19+
[dev-dependencies]
20+
substrate-test-client = { path = "../../test-client" }

core/consensus/common/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,11 @@ error_chain! {
8484
description("Other error")
8585
display("Other error: {}", e.description())
8686
}
87+
88+
/// Error from the client while importing
89+
ClientImport(reason: String) {
90+
description("Import failed"),
91+
display("Import failed: {}", reason),
92+
}
8793
}
8894
}

0 commit comments

Comments
 (0)