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

Commit d01bc24

Browse files
bkchrpepyakinandresilva
authored
Aura consensus for parachains (#371)
* Update polkadot * Migrate all uses of MQC heads to merkle proofs * Mass rename `relay_parent_storage_root` * Restore parachain-system tests * Update polkadot and libp2p swarm for testing * Collapse match into an if let Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Start with something * Update Substrate & Polkadot * Start to make it compile * Make it compile * Begin with something * Yep * I'm a hacker * Bring back the builder * Make it work in some way * Compile * Parachains use their own "slot" * Adds cumulus-pallet-aura * Wrap AuRa import queue to disable equivocation checking by default * Pass slot duration * Check the seal when validating a block * Adds missing file * Try to make the seal working * Fix it * Some fixes * Bring in the latest features to cleanup the code * Update and make it compile * Improve the import * Start fixing * More work * Fix fix fix * Make everything compile * Small cleanups * Rename and more docs * Docs * Fixes fixes fixes * Update rococo-parachains/src/chain_spec.rs * Update client/consensus/aura/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/aura/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update primitives/parachain-inherent/Cargo.toml Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update primitives/parachain-inherent/Cargo.toml * Update primitives/parachain-inherent/Cargo.toml * Update primitives/parachain-inherent/Cargo.toml Co-authored-by: Sergei Shulepov <sergei@parity.io> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
1 parent 78ad174 commit d01bc24

File tree

22 files changed

+1694
-332
lines changed

22 files changed

+1694
-332
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[workspace]
22
members = [
33
"client/cli",
4+
"client/consensus/aura",
45
"client/consensus/common",
56
"client/consensus/relay-chain",
67
"client/network",
78
"client/service",
9+
"pallets/aura-ext",
810
"pallets/dmp-queue",
911
"pallets/parachain-system",
1012
"pallets/xcm",

client/consensus/aura/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "cumulus-client-consensus-aura"
3+
description = "AURA consensus algorithm for parachains"
4+
version = "0.1.0"
5+
authors = ["Parity Technologies <admin@parity.io>"]
6+
edition = "2018"
7+
8+
[dependencies]
9+
# Substrate dependencies
10+
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
11+
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" }
12+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
13+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
14+
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
15+
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
16+
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
17+
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" }
18+
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
19+
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" }
20+
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
21+
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" }
22+
sc-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "master" }
23+
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
24+
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
25+
26+
# Polkadot dependencies
27+
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
28+
29+
# Cumulus dependencies
30+
cumulus-client-consensus-common = { path = "../common" }
31+
cumulus-primitives-core = { path = "../../../primitives/core" }
32+
33+
# Other deps
34+
futures = { version = "0.3.8", features = ["compat"] }
35+
codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ] }
36+
tracing = "0.1.22"
37+
async-trait = "0.1.42"
38+
parking_lot = "0.9"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2021 Parity Technologies (UK) Ltd.
2+
// This file is part of Cumulus.
3+
4+
// Cumulus is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Cumulus is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Parachain specific wrapper for the AuRa import queue.
18+
19+
use codec::Codec;
20+
use sc_client_api::{backend::AuxStore, BlockOf};
21+
use sc_consensus_slots::InherentDataProviderExt;
22+
use sp_api::{ApiExt, ProvideRuntimeApi};
23+
use sp_block_builder::BlockBuilder as BlockBuilderApi;
24+
use sp_blockchain::{HeaderBackend, ProvideCache};
25+
use sp_consensus::{
26+
import_queue::DefaultImportQueue, BlockImport, CanAuthorWith, Error as ConsensusError,
27+
};
28+
use sp_consensus_aura::{digests::CompatibleDigestItem, AuraApi};
29+
use sp_core::crypto::Pair;
30+
use sp_inherents::CreateInherentDataProviders;
31+
use sp_runtime::traits::{Block as BlockT, DigestItemFor};
32+
use std::{fmt::Debug, hash::Hash, sync::Arc};
33+
use substrate_prometheus_endpoint::Registry;
34+
use sc_telemetry::TelemetryHandle;
35+
36+
/// Parameters of [`import_queue`].
37+
pub struct ImportQueueParams<'a, I, C, IDP, S, CAW> {
38+
/// The block import to use.
39+
pub block_import: I,
40+
/// The client to interact with the chain.
41+
pub client: Arc<C>,
42+
/// The inherent data providers, to create the inherent data.
43+
pub create_inherent_data_providers: IDP,
44+
/// The spawner to spawn background tasks.
45+
pub spawner: &'a S,
46+
/// The prometheus registry.
47+
pub registry: Option<&'a Registry>,
48+
/// Can we author with the current node?
49+
pub can_author_with: CAW,
50+
/// The telemetry handle.
51+
pub telemetry: Option<TelemetryHandle>,
52+
}
53+
54+
/// Start an import queue for the Aura consensus algorithm.
55+
pub fn import_queue<'a, P, Block, I, C, S, CAW, IDP>(
56+
ImportQueueParams {
57+
block_import,
58+
client,
59+
create_inherent_data_providers,
60+
spawner,
61+
registry,
62+
can_author_with,
63+
telemetry,
64+
}: ImportQueueParams<'a, I, C, IDP, S, CAW>,
65+
) -> Result<DefaultImportQueue<Block, C>, sp_consensus::Error>
66+
where
67+
Block: BlockT,
68+
C::Api: BlockBuilderApi<Block> + AuraApi<Block, P::Public> + ApiExt<Block>,
69+
C: 'static
70+
+ ProvideRuntimeApi<Block>
71+
+ BlockOf
72+
+ ProvideCache<Block>
73+
+ Send
74+
+ Sync
75+
+ AuxStore
76+
+ HeaderBackend<Block>,
77+
I: BlockImport<Block, Error = ConsensusError, Transaction = sp_api::TransactionFor<C, Block>>
78+
+ Send
79+
+ Sync
80+
+ 'static,
81+
DigestItemFor<Block>: CompatibleDigestItem<P::Signature>,
82+
P: Pair + Send + Sync + 'static,
83+
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Codec,
84+
P::Signature: Codec,
85+
S: sp_core::traits::SpawnEssentialNamed,
86+
CAW: CanAuthorWith<Block> + Send + Sync + 'static,
87+
IDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
88+
IDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
89+
{
90+
sc_consensus_aura::import_queue::<P, _, _, _, _, _, _>(sc_consensus_aura::ImportQueueParams {
91+
block_import: crate::ParachainBlockImport(block_import),
92+
justification_import: None,
93+
client,
94+
create_inherent_data_providers,
95+
spawner,
96+
registry,
97+
can_author_with,
98+
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
99+
telemetry,
100+
})
101+
}

0 commit comments

Comments
 (0)