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

Make BlockImport and Verifier async #8472

Merged
31 commits merged into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
202c649
Make grandpa work
bkchr Mar 24, 2021
bedc1c0
Introduce `SharedData`
bkchr Mar 24, 2021
7509754
Add test and fix bugs
bkchr Mar 25, 2021
5048c15
Switch to `SharedData`
bkchr Mar 25, 2021
ee26e09
Make grandpa tests working
bkchr Mar 25, 2021
d4a2498
More Babe work
bkchr Mar 25, 2021
076d4dc
Make it async
bkchr Mar 26, 2021
9fe6ead
Fix fix
bkchr Mar 26, 2021
6560444
Use `async_trait` in sc-consensus-slots
bkchr Mar 26, 2021
4479a55
Make grandpa tests compile
bkchr Mar 26, 2021
fcae728
More Babe tests work
bkchr Mar 25, 2021
a850851
Fix network test
bkchr Mar 26, 2021
0301378
Start fixing service test
bkchr Mar 26, 2021
3095404
Finish service-test
bkchr Mar 26, 2021
36c6bb5
Fix sc-consensus-aura
bkchr Mar 27, 2021
d9a8986
Fix fix fix
bkchr Mar 27, 2021
5104bf6
More fixes
bkchr Mar 27, 2021
efcd0b5
Make everything compile *yeah*
bkchr Mar 27, 2021
15c3189
Merge remote-tracking branch 'origin/master' into bkchr-block-import-…
bkchr Mar 27, 2021
682da05
Fix build when we have Rust 1.51
bkchr Mar 28, 2021
8a63652
Merge remote-tracking branch 'origin/master' into bkchr-block-import-…
bkchr Mar 29, 2021
cc502a2
Merge remote-tracking branch 'origin/master' into bkchr-block-import-…
bkchr Mar 29, 2021
0727f1d
Update client/consensus/common/src/shared_data.rs
bkchr Mar 29, 2021
f5756cd
Update client/consensus/common/src/shared_data.rs
bkchr Mar 29, 2021
70c3d69
Update client/consensus/common/src/shared_data.rs
bkchr Mar 29, 2021
315ddac
Update client/consensus/common/src/shared_data.rs
bkchr Mar 29, 2021
97ef6bb
Update client/consensus/common/src/shared_data.rs
bkchr Mar 29, 2021
6a92c38
Update client/consensus/babe/src/tests.rs
bkchr Mar 29, 2021
de62a7d
Update client/consensus/babe/src/tests.rs
bkchr Mar 29, 2021
7757ec9
Fix warning
bkchr Mar 29, 2021
aa7dffc
Merge remote-tracking branch 'origin/master' into bkchr-block-import-…
bkchr Mar 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ check-web-wasm:
# Note: we don't need to test crates imported in `bin/node/cli`
- time cargo build --manifest-path=client/consensus/aura/Cargo.toml --target=wasm32-unknown-unknown --features getrandom
# Note: the command below is a bit weird because several Cargo issues prevent us from compiling the node in a more straight-forward way.
- time cargo +nightly build --manifest-path=bin/node/cli/Cargo.toml --no-default-features --features browser --target=wasm32-unknown-unknown -Z features=itarget
- time cargo +nightly build --manifest-path=bin/node/cli/Cargo.toml --no-default-features --features browser --target=wasm32-unknown-unknown
# with-tracing must be explicitly activated, we run a test to ensure this works as expected in both cases
- time cargo +nightly test --manifest-path primitives/tracing/Cargo.toml --no-default-features
- time cargo +nightly test --manifest-path primitives/tracing/Cargo.toml --no-default-features --features=with-tracing
Expand Down Expand Up @@ -407,7 +407,7 @@ test-browser-node:
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: "wasm-bindgen-test-runner"
WASM_BINDGEN_TEST_TIMEOUT: 120
script:
- cargo +nightly test --target wasm32-unknown-unknown -p node-browser-testing -Z features=itarget
- cargo +nightly test --target wasm32-unknown-unknown -p node-browser-testing

build-linux-substrate: &build-binary
stage: build
Expand Down
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[workspace]
resolver = "2"

members = [
"bin/node-template/node",
"bin/node-template/pallets/template",
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/pallets/template/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
#[allow(unused)]
use crate::Module as Template;
use crate::Pallet as Template;

benchmarks! {
do_something {
Expand Down
10 changes: 5 additions & 5 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ pub fn new_light(

#[cfg(test)]
mod tests {
use std::{sync::Arc, borrow::Cow, any::Any, convert::TryInto};
use std::{sync::Arc, borrow::Cow, convert::TryInto};
use sc_consensus_babe::{CompatibleDigestItem, BabeIntermediate, INTERMEDIATE_KEY};
use sc_consensus_epochs::descendent_query;
use sp_consensus::{
Expand Down Expand Up @@ -648,14 +648,14 @@ mod tests {
&(slot * SLOT_DURATION),
);

let epoch_descriptor = babe_link.epoch_changes().lock().epoch_descriptor_for_child_of(
let epoch_descriptor = babe_link.epoch_changes().shared_data().epoch_descriptor_for_child_of(
descendent_query(&*service.client()),
&parent_hash,
parent_number,
slot.into(),
).unwrap().unwrap();

let epoch = babe_link.epoch_changes().lock().epoch_data(
let epoch = babe_link.epoch_changes().shared_data().epoch_data(
&epoch_descriptor,
|slot| sc_consensus_babe::Epoch::genesis(&babe_link.config(), slot),
).unwrap();
Expand Down Expand Up @@ -703,11 +703,11 @@ mod tests {
params.body = Some(new_body);
params.intermediates.insert(
Cow::from(INTERMEDIATE_KEY),
Box::new(BabeIntermediate::<Block> { epoch_descriptor }) as Box<dyn Any>,
Box::new(BabeIntermediate::<Block> { epoch_descriptor }) as Box<_>,
);
params.fork_choice = Some(ForkChoiceStrategy::LongestChain);

block_import.import_block(params, Default::default())
futures::executor::block_on(block_import.import_block(params, Default::default()))
.expect("error importing test block");
},
|service, _| {
Expand Down
1 change: 1 addition & 0 deletions bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" }
sp-externalities = { version = "0.9.0", path = "../../../primitives/externalities" }
substrate-test-client = { version = "2.0.0", path = "../../../test-utils/client" }
wat = "1.0"
futures = "0.3.9"

[features]
wasmtime = [
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,5 @@ fn should_import_block_with_test_client() {
let block_data = block1.0;
let block = node_primitives::Block::decode(&mut &block_data[..]).unwrap();

client.import(BlockOrigin::Own, block).unwrap();
futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
}
2 changes: 1 addition & 1 deletion bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ impl BenchContext {
assert_eq!(self.client.chain_info().best_number, 0);

assert_eq!(
self.client.import_block(import_params, Default::default())
futures::executor::block_on(self.client.import_block(import_params, Default::default()))
.expect("Failed to import block"),
ImportResult::Imported(
ImportedAux {
Expand Down
27 changes: 14 additions & 13 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ mod tests {
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::NumberFor;
use sc_client_api::Backend;
use futures::executor::block_on;

const SOURCE: TransactionSource = TransactionSource::External;

Expand Down Expand Up @@ -454,11 +455,11 @@ mod tests {
client.clone(),
);

futures::executor::block_on(
block_on(
txpool.submit_at(&BlockId::number(0), SOURCE, vec![extrinsic(0), extrinsic(1)])
).unwrap();

futures::executor::block_on(
block_on(
txpool.maintain(chain_event(
client.header(&BlockId::Number(0u64))
.expect("header get error")
Expand Down Expand Up @@ -492,7 +493,7 @@ mod tests {

// when
let deadline = time::Duration::from_secs(3);
let block = futures::executor::block_on(
let block = block_on(
proposer.propose(Default::default(), Default::default(), deadline)
).map(|r| r.block).unwrap();

Expand Down Expand Up @@ -538,7 +539,7 @@ mod tests {
);

let deadline = time::Duration::from_secs(1);
futures::executor::block_on(
block_on(
proposer.propose(Default::default(), Default::default(), deadline)
).map(|r| r.block).unwrap();
}
Expand All @@ -559,11 +560,11 @@ mod tests {
let genesis_hash = client.info().best_hash;
let block_id = BlockId::Hash(genesis_hash);

futures::executor::block_on(
block_on(
txpool.submit_at(&BlockId::number(0), SOURCE, vec![extrinsic(0)]),
).unwrap();

futures::executor::block_on(
block_on(
txpool.maintain(chain_event(
client.header(&BlockId::Number(0u64))
.expect("header get error")
Expand All @@ -585,7 +586,7 @@ mod tests {
);

let deadline = time::Duration::from_secs(9);
let proposal = futures::executor::block_on(
let proposal = block_on(
proposer.propose(Default::default(), Default::default(), deadline),
).unwrap();

Expand Down Expand Up @@ -625,7 +626,7 @@ mod tests {
client.clone(),
);

futures::executor::block_on(
block_on(
txpool.submit_at(&BlockId::number(0), SOURCE, vec![
extrinsic(0),
extrinsic(1),
Expand Down Expand Up @@ -667,7 +668,7 @@ mod tests {

// when
let deadline = time::Duration::from_secs(9);
let block = futures::executor::block_on(
let block = block_on(
proposer.propose(Default::default(), Default::default(), deadline)
).map(|r| r.block).unwrap();

Expand All @@ -679,7 +680,7 @@ mod tests {
block
};

futures::executor::block_on(
block_on(
txpool.maintain(chain_event(
client.header(&BlockId::Number(0u64))
.expect("header get error")
Expand All @@ -689,9 +690,9 @@ mod tests {

// let's create one block and import it
let block = propose_block(&client, 0, 2, 7);
client.import(BlockOrigin::Own, block).unwrap();
block_on(client.import(BlockOrigin::Own, block)).unwrap();

futures::executor::block_on(
block_on(
txpool.maintain(chain_event(
client.header(&BlockId::Number(1))
.expect("header get error")
Expand All @@ -701,6 +702,6 @@ mod tests {

// now let's make sure that we can still make some progress
let block = propose_block(&client, 1, 2, 5);
client.import(BlockOrigin::Own, block).unwrap();
block_on(client.import(BlockOrigin::Own, block)).unwrap();
}
}
3 changes: 2 additions & 1 deletion client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ futures = "0.3.9"
futures-timer = "3.0.1"
sp-inherents = { version = "3.0.0", path = "../../../primitives/inherents" }
log = "0.4.8"
parking_lot = "0.11.1"
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" }
sp-io = { version = "3.0.0", path = "../../../primitives/io" }
Expand All @@ -38,6 +37,7 @@ sp-timestamp = { version = "3.0.0", path = "../../../primitives/timestamp" }
sp-keystore = { version = "0.9.0", path = "../../../primitives/keystore" }
sc-telemetry = { version = "3.0.0", path = "../../telemetry" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.9.0"}
async-trait = "0.1.42"
# We enable it only for web-wasm check
# See https://docs.rs/getrandom/0.2.1/getrandom/#webassembly-support
getrandom = { version = "0.2", features = ["js"], optional = true }
Expand All @@ -52,3 +52,4 @@ sc-network-test = { version = "0.8.0", path = "../../network/test" }
sc-service = { version = "0.9.0", default-features = false, path = "../../service" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" }
tempfile = "3.1.0"
parking_lot = "0.11.1"
13 changes: 8 additions & 5 deletions client/consensus/aura/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl<C, P, CAW> AuraVerifier<C, P, CAW> where
}
}

#[async_trait::async_trait]
impl<B: BlockT, C, P, CAW> Verifier<B> for AuraVerifier<C, P, CAW> where
C: ProvideRuntimeApi<B> +
Send +
Expand All @@ -234,7 +235,7 @@ impl<B: BlockT, C, P, CAW> Verifier<B> for AuraVerifier<C, P, CAW> where
P::Signature: Encode + Decode,
CAW: CanAuthorWith<B> + Send + Sync + 'static,
{
fn verify(
async fn verify(
&mut self,
origin: BlockOrigin,
header: B::Header,
Expand Down Expand Up @@ -405,25 +406,27 @@ impl<Block: BlockT, C, I: BlockImport<Block>, P> AuraBlockImport<Block, C, I, P>
}
}

#[async_trait::async_trait]
impl<Block: BlockT, C, I, P> BlockImport<Block> for AuraBlockImport<Block, C, I, P> where
I: BlockImport<Block, Transaction = sp_api::TransactionFor<C, Block>> + Send + Sync,
I::Error: Into<ConsensusError>,
C: HeaderBackend<Block> + ProvideRuntimeApi<Block>,
P: Pair + Send + Sync + 'static,
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode,
P::Signature: Encode + Decode,
sp_api::TransactionFor<C, Block>: Send + 'static,
{
type Error = ConsensusError;
type Transaction = sp_api::TransactionFor<C, Block>;

fn check_block(
async fn check_block(
&mut self,
block: BlockCheckParams<Block>,
) -> Result<ImportResult, Self::Error> {
self.inner.check_block(block).map_err(Into::into)
self.inner.check_block(block).await.map_err(Into::into)
}

fn import_block(
async fn import_block(
&mut self,
block: BlockImportParams<Block, Self::Transaction>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
Expand Down Expand Up @@ -453,7 +456,7 @@ impl<Block: BlockT, C, I, P> BlockImport<Block> for AuraBlockImport<Block, C, I,
);
}

self.inner.import_block(block, new_cache).map_err(Into::into)
self.inner.import_block(block, new_cache).await.map_err(Into::into)
}
}

Expand Down
Loading