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>
This commit is contained in:
Bastian Köcher
2021-05-10 14:43:00 +02:00
committed by GitHub
parent 647a9e6df9
commit 8accc88e76
22 changed files with 1694 additions and 332 deletions
@@ -15,16 +15,21 @@ sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
# Polkadot dependencies
polkadot-service = { git = "https://github.com/paritytech/polkadot", optional = true, branch = "master" }
# Cumulus dependencies
cumulus-primitives-core = { path = "../core", default-features = false }
# Other dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] }
tracing = { version = "0.1.22", optional = true }
async-trait = { version = "0.1.42", optional = true }
[features]
default = [ "std" ]
std = [
"async-trait",
"codec/std",
"cumulus-primitives-core/std",
"sp-inherents/std",
@@ -36,4 +41,5 @@ std = [
"sp-runtime",
"sc-client-api",
"sp-api",
"polkadot-service",
]
@@ -26,6 +26,7 @@ use cumulus_primitives_core::{
},
InboundDownwardMessage, InboundHrmpMessage, ParaId, PersistedValidationData,
};
use polkadot_service::{Client, ClientHandle, ExecuteWithClient};
use sc_client_api::Backend;
use sp_api::ProvideRuntimeApi;
use sp_runtime::generic::BlockId;
@@ -210,7 +211,8 @@ impl ParachainInherentData {
PClient: ProvideRuntimeApi<PBlock>,
PClient::Api: ParachainHost<PBlock>,
{
let relay_chain_state = collect_relay_storage_proof(polkadot_backend, para_id, relay_parent)?;
let relay_chain_state =
collect_relay_storage_proof(polkadot_backend, para_id, relay_parent)?;
let downward_messages = retrieve_dmq_contents(polkadot_client, para_id, relay_parent)?;
let horizontal_messages =
retrieve_all_inbound_hrmp_channel_contents(polkadot_client, para_id, relay_parent)?;
@@ -222,4 +224,68 @@ impl ParachainInherentData {
relay_chain_state,
})
}
/// Create the [`ParachainInherentData`] at the given `relay_parent`.
///
/// Returns `None` if the creation failed.
pub fn create_at_with_client(
relay_parent: PHash,
polkadot_client: &Client,
relay_chain_backend: &impl Backend<PBlock>,
validation_data: &PersistedValidationData,
para_id: ParaId,
) -> Option<ParachainInherentData> {
polkadot_client.execute_with(CreateAtWithClient {
relay_chain_backend,
validation_data,
para_id,
relay_parent,
})
}
}
#[async_trait::async_trait]
impl sp_inherents::InherentDataProvider for ParachainInherentData {
fn provide_inherent_data(
&self,
inherent_data: &mut sp_inherents::InherentData,
) -> Result<(), sp_inherents::Error> {
inherent_data.put_data(crate::INHERENT_IDENTIFIER, &self)
}
async fn try_handle_error(
&self,
_: &sp_inherents::InherentIdentifier,
_: &[u8],
) -> Option<Result<(), sp_inherents::Error>> {
None
}
}
/// Special structure to run [`ParachainInherentData::create_at`] with a [`Client`].
struct CreateAtWithClient<'a, B> {
relay_parent: PHash,
relay_chain_backend: &'a B,
validation_data: &'a PersistedValidationData,
para_id: ParaId,
}
impl<'a, B> ExecuteWithClient for CreateAtWithClient<'a, B>
where
B: Backend<PBlock>,
{
type Output = Option<ParachainInherentData>;
fn execute_with_client<Client, Api, Backend>(
self,
client: std::sync::Arc<Client>,
) -> Self::Output where Client: ProvideRuntimeApi<PBlock>, Client::Api: ParachainHost<PBlock> {
ParachainInherentData::create_at(
self.relay_parent,
&*client,
self.relay_chain_backend,
self.validation_data,
self.para_id,
)
}
}