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

Integrate new Aura / Parachain Consensus Logic in Parachain-Template / Polkadot-Parachain #2864

Merged
merged 40 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b8deeb6
add a comment
rphmeier Jul 13, 2023
14cd025
refactor client/service utilities
rphmeier Jul 13, 2023
8efd201
deprecate start_collator
rphmeier Jul 13, 2023
d9e5b0d
update parachain-template
rphmeier Jul 13, 2023
67dc9d8
update test-service in the same way
rphmeier Jul 13, 2023
5010d72
update polkadot-parachain crate
rphmeier Jul 13, 2023
3eeba28
fmt
rphmeier Jul 13, 2023
faaee0c
wire up new SubmitCollation message
rphmeier Jul 14, 2023
d9d4c9d
some runtime utilities for implementing unincluded segment runtime APIs
rphmeier Jul 14, 2023
7591e38
allow parachains to configure their level of sybil-resistance when st…
rphmeier Jul 14, 2023
873be56
make aura-ext compile
rphmeier Jul 14, 2023
0b3b463
update to specify sybil resistance levels
rphmeier Jul 14, 2023
f82cd12
fmt
rphmeier Jul 14, 2023
2318901
specify relay chain slot duration in milliseconds
rphmeier Jul 18, 2023
b4eb494
update Aura to explicitly produce Send futures
rphmeier Jul 18, 2023
bb0fb3f
add authoring duration to basic collator and document params
rphmeier Jul 18, 2023
56be008
integrate new basic collator into parachain-template
rphmeier Jul 18, 2023
b906b88
remove assert_send used for testing
rphmeier Jul 18, 2023
0fa5a58
basic-aura: only author when parent included
rphmeier Jul 18, 2023
51293e3
update polkadot-parachain-bin
rphmeier Jul 19, 2023
aaefdbc
fmt
rphmeier Jul 19, 2023
73b8245
some fixes
rphmeier Jul 23, 2023
62db51b
fixes
rphmeier Jul 23, 2023
f72e351
add a RelayNumberMonotonicallyIncreases
rphmeier Jul 23, 2023
065c911
add a utility function for initializing subsystems
rphmeier Jul 25, 2023
61ded06
some logging for timestamp adjustment
rphmeier Jul 25, 2023
ac05b8a
fmt
rphmeier Jul 25, 2023
07a575b
some fixes for lookahead collator
rphmeier Jul 25, 2023
e37ab0a
add a log
rphmeier Jul 27, 2023
763134b
update `find_potential_parents` to account for sessions
rphmeier Jul 27, 2023
3fd1f51
bound the loop
rphmeier Jul 28, 2023
a9d7438
Merge branch 'slumber-async-backing-feature' into rh-integrate-new-aura
rphmeier Jul 28, 2023
73ebbf5
restore & deprecate old start_collator and start_full_node functions.
rphmeier Jul 28, 2023
c368fc2
Merge branch 'slumber-async-backing-feature' into rh-integrate-new-aura
rphmeier Jul 28, 2023
3ccde1f
remove unnecessary await calls
rphmeier Jul 28, 2023
cdffb35
fix warning
rphmeier Jul 31, 2023
45d2a34
clippy
rphmeier Jul 31, 2023
46d207c
more clippy
rphmeier Aug 1, 2023
39ce40e
remove unneeded logic
rphmeier Aug 1, 2023
55317b1
ci
rphmeier Aug 1, 2023
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
13 changes: 9 additions & 4 deletions Cargo.lock

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

49 changes: 46 additions & 3 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use sp_core::traits::SpawnNamed;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

use cumulus_client_consensus_common::ParachainConsensus;
use polkadot_node_primitives::{CollationResult, MaybeCompressedPoV};
use polkadot_node_primitives::{CollationGenerationConfig, CollationResult, MaybeCompressedPoV};
use polkadot_node_subsystem::messages::{CollationGenerationMessage, CollatorProtocolMessage};
use polkadot_overseer::Handle as OverseerHandle;
use polkadot_primitives::{CollatorPair, Id as ParaId};

Expand Down Expand Up @@ -233,6 +234,31 @@ pub mod relay_chain_driven {
}
}

/// Initialize the collation-related subsystems on the relay-chain side.
///
/// This must be done prior to collation, and does not set up any callback for collation.
/// For callback-driven collators, use the [`relay_chain_driven`] module.
pub async fn initialize_collator_subsystems(
overseer_handle: &mut OverseerHandle,
key: CollatorPair,
para_id: ParaId,
) {
overseer_handle
.send_msg(
CollationGenerationMessage::Initialize(CollationGenerationConfig {
key,
para_id,
collator: None,
}),
"StartCollator",
)
.await;

overseer_handle
.send_msg(CollatorProtocolMessage::CollateOn(para_id), "StartCollator")
.await;
}

/// Parameters for [`start_collator`].
pub struct StartCollatorParams<Block: BlockT, RA, BS, Spawner> {
pub para_id: ParaId,
Expand All @@ -246,7 +272,24 @@ pub struct StartCollatorParams<Block: BlockT, RA, BS, Spawner> {
}

/// Start the collator.
#[deprecated = "Collators should run consensus futures which handle this logic internally"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the futures in the run() functions of lookahead.rs and basic.rs examples of the "consensus futures" you mention here?

Perhaps we would call said run() functions instead of old_consensus::start_collator() in parachain-template/node/src/service.rs to fully activate async backing aura?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

The first step is to use the basic.rs future, which is intended to have the exact same behavior as current Aura. Then, when asynchronous backing is being enabled, the lookahead.rs future would be swapped in.

pub async fn start_collator<Block, RA, BS, Spawner>(
params: StartCollatorParams<Block, RA, BS, Spawner>,
) where
Block: BlockT,
BS: BlockBackend<Block> + Send + Sync + 'static,
Spawner: SpawnNamed + Clone + Send + Sync + 'static,
RA: ProvideRuntimeApi<Block> + Send + Sync + 'static,
RA::Api: CollectCollationInfo<Block>,
{
// This never needed to be asynchronous, but shouldn't be changed due to backcompat.
#[allow(deprecated)]
start_collator_sync(params);
}

/// Start the collator in a synchronous function.
#[deprecated = "Collators should run consensus futures which handle this logic internally"]
pub fn start_collator_sync<Block, RA, BS, Spawner>(
StartCollatorParams {
para_id,
block_status,
Expand All @@ -269,9 +312,8 @@ pub async fn start_collator<Block, RA, BS, Spawner>(

let collator = Collator::new(collator_service, parachain_consensus);

let mut request_stream = relay_chain_driven::init(key, para_id, overseer_handle).await;

let collation_future = Box::pin(async move {
let mut request_stream = relay_chain_driven::init(key, para_id, overseer_handle).await;
while let Some(request) = request_stream.next().await {
let collation = collator
.clone()
Expand Down Expand Up @@ -375,6 +417,7 @@ mod tests {

spawner.spawn("overseer", None, overseer.run().then(|_| async {}).boxed());

#[allow(deprecated)]
let collator_start = start_collator(StartCollatorParams {
runtime_api: client.clone(),
block_status: client.clone(),
Expand Down
1 change: 1 addition & 0 deletions client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ cumulus-client-collator = { path = "../../collator" }
# Polkadot
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "rh-async-backing-feature" }
polkadot-node-primitives = { git = "https://github.com/paritytech/polkadot", branch = "rh-async-backing-feature" }
polkadot-node-subsystem = { git = "https://github.com/paritytech/polkadot", branch = "rh-async-backing-feature" }
polkadot-overseer = { git = "https://github.com/paritytech/polkadot", branch = "rh-async-backing-feature" }
44 changes: 31 additions & 13 deletions client/consensus/aura/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use sp_runtime::{
};
use sp_state_machine::StorageChanges;
use sp_timestamp::Timestamp;
use std::{convert::TryFrom, error::Error, sync::Arc, time::Duration};
use std::{convert::TryFrom, error::Error, time::Duration};

/// Parameters for instantiating a [`Collator`].
pub struct Params<BI, CIDP, RClient, Proposer, CS> {
Expand All @@ -64,7 +64,7 @@ pub struct Params<BI, CIDP, RClient, Proposer, CS> {
/// The block import handle.
pub block_import: BI,
/// An interface to the relay-chain client.
pub relay_client: Arc<RClient>,
pub relay_client: RClient,
/// The keystore handle used for accessing parachain key material.
pub keystore: KeystorePtr,
/// The identifier of the parachain within the relay-chain.
Expand All @@ -81,7 +81,7 @@ pub struct Params<BI, CIDP, RClient, Proposer, CS> {
pub struct Collator<Block, P, BI, CIDP, RClient, Proposer, CS> {
create_inherent_data_providers: CIDP,
block_import: BI,
relay_client: Arc<RClient>,
relay_client: RClient,
keystore: KeystorePtr,
para_id: ParaId,
proposer: Proposer,
Expand Down Expand Up @@ -124,7 +124,7 @@ where
validation_data: &PersistedValidationData,
parent_hash: Block::Hash,
timestamp: impl Into<Option<Timestamp>>,
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error>> {
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error + Send + Sync + 'static>> {
let paras_inherent_data = ParachainInherentData::create_at(
relay_parent,
&self.relay_client,
Expand All @@ -144,7 +144,7 @@ where
let mut other_inherent_data = self
.create_inherent_data_providers
.create_inherent_data_providers(parent_hash, ())
.map_err(|e| e as Box<dyn Error>)
.map_err(|e| e as Box<dyn Error + Send + Sync + 'static>)
.await?
.create_inherent_data()
.await
Expand Down Expand Up @@ -173,7 +173,8 @@ where
inherent_data: (ParachainInherentData, InherentData),
proposal_duration: Duration,
max_pov_size: usize,
) -> Result<(Collation, ParachainBlockData<Block>, Block::Hash), Box<dyn Error>> {
) -> Result<(Collation, ParachainBlockData<Block>, Block::Hash), Box<dyn Error + Send + 'static>>
{
let mut digest = additional_pre_digest.into().unwrap_or_default();
digest.push(slot_claim.pre_digest.clone());

Expand All @@ -188,14 +189,15 @@ where
Some(max_pov_size),
)
.await
.map_err(|e| Box::new(e))?;
.map_err(|e| Box::new(e) as Box<dyn Error + Send>)?;

let sealed_importable = seal::<_, _, P>(
proposal.block,
proposal.storage_changes,
&slot_claim.author_pub,
&self.keystore,
)?;
)
.map_err(|e| e as Box<dyn Error + Send>)?;

let post_hash = sealed_importable.post_hash();
let block = Block::new(
Expand All @@ -207,7 +209,10 @@ where
.clone(),
);

self.block_import.import_block(sealed_importable).await?;
self.block_import
.import_block(sealed_importable)
.map_err(|e| Box::new(e) as Box<dyn Error + Send>)
.await?;

if let Some((collation, block_data)) = self.collator_service.build_collation(
parent_header,
Expand All @@ -232,7 +237,8 @@ where

Ok((collation, block_data, post_hash))
} else {
Err("Unable to produce collation".to_string().into())
Err(Box::<dyn Error + Send + Sync>::from("Unable to produce collation")
as Box<dyn Error + Send>)
}
}

Expand Down Expand Up @@ -286,7 +292,7 @@ pub async fn claim_slot<B, C, P>(
parent_hash: B::Hash,
relay_parent_header: &PHeader,
slot_duration: SlotDuration,
relay_chain_slot_duration: SlotDuration,
relay_chain_slot_duration: Duration,
keystore: &KeystorePtr,
) -> Result<Option<SlotClaim<P::Public>>, Box<dyn Error>>
where
Expand All @@ -305,7 +311,19 @@ where
relay_parent_header,
relay_chain_slot_duration,
) {
Some((_, t)) => (Slot::from_timestamp(t, slot_duration), t),
Some((r_s, t)) => {
let our_slot = Slot::from_timestamp(t, slot_duration);
tracing::debug!(
target: crate::LOG_TARGET,
relay_slot = ?r_s,
para_slot = ?our_slot,
timestamp = ?t,
?slot_duration,
?relay_chain_slot_duration,
"Adjusted relay-chain slot to parachain slot"
);
(our_slot, t)
},
None => return Ok(None),
};

Expand All @@ -327,7 +345,7 @@ pub fn seal<B: BlockT, T, P>(
storage_changes: StorageChanges<T, HashingFor<B>>,
author_pub: &P::Public,
keystore: &KeystorePtr,
) -> Result<BlockImportParams<B, T>, Box<dyn Error>>
) -> Result<BlockImportParams<B, T>, Box<dyn Error + Send + Sync + 'static>>
where
P: Pair,
P::Signature: Codec + TryFrom<Vec<u8>>,
Expand Down
Loading