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

Commit

Permalink
Asynchronous-backing compatible Aura, not plugged in (#2573)
Browse files Browse the repository at this point in the history
* rough draft of potential parent search

* get things compiling

* fmt

* add new function to all RelayChainInterface implementations

* fix compilation

* set slot and timestamp based on relay parent, prepare for find-parent

* skeleton of new aura logic

* fmt

* introduce a collator module in the Aura crate

* extract different implementations into own modules

* make interface more convenient

* docs and todos for lookahead

* refactor basic collator to use new collator utility

* some more refactoring

* finish most of the control flow for new aura

* introduce backend as parameter

* fix compilation

* fix a couple more TODOs

* add an `announce_block` function to collator service

* announce with barrier

* rename block announcement validator to be more specific

* fmt

* clean up unused import errors

* update references to BlockAnnounceValidator

* rename unstable_reimpl

* add AuraUnincludedSegmentApi

* finish rename

* integrate AuraUnincludedSegmentApi

* add a new block announcement validator for backwards compatibility

* add some naive equivocation defenses

* rustfmt

* clean up remaining TODO [now]s

* fmt

* try to fix inprocess-interface

* actually fix compilation

* ignored -> rejected rephrase

* fix test compilation

* fmt

* clippy
  • Loading branch information
rphmeier authored and EgorPopelyaev committed Jul 18, 2023
1 parent de2059b commit a06efab
Show file tree
Hide file tree
Showing 20 changed files with 1,588 additions and 548 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"pallets/xcmp-queue",
"parachain-template/node",
"parachain-template/runtime",
"primitives/aura",
"primitives/core",
"primitives/parachain-inherent",
"primitives/timestamp",
Expand Down
21 changes: 17 additions & 4 deletions client/collator/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ pub trait ServiceInterface<Block: BlockT> {
candidate: ParachainCandidate<Block>,
) -> Option<(Collation, ParachainBlockData<Block>)>;

/// Inform networking systems that the block should be announced after an appropriate
/// signal has been received. This returns the sending half of the signal.
/// Inform networking systems that the block should be announced after a signal has
/// been received to indicate the block has been seconded by a relay-chain validator.
///
/// This sets up the barrier and returns the sending side of a channel, for the signal
/// to be passed through.
fn announce_with_barrier(
&self,
block_hash: Block::Hash,
) -> oneshot::Sender<CollationSecondedSignal>;

/// Directly announce a block on the network.
fn announce_block(&self, block_hash: Block::Hash, data: Option<Vec<u8>>);
}

/// The [`CollatorService`] provides common utilities for parachain consensus and authoring.
Expand All @@ -74,6 +80,7 @@ pub trait ServiceInterface<Block: BlockT> {
pub struct CollatorService<Block: BlockT, BS, RA> {
block_status: Arc<BS>,
wait_to_announce: Arc<Mutex<WaitToAnnounce<Block>>>,
announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
runtime_api: Arc<RA>,
}

Expand All @@ -82,6 +89,7 @@ impl<Block: BlockT, BS, RA> Clone for CollatorService<Block, BS, RA> {
Self {
block_status: self.block_status.clone(),
wait_to_announce: self.wait_to_announce.clone(),
announce_block: self.announce_block.clone(),
runtime_api: self.runtime_api.clone(),
}
}
Expand All @@ -101,9 +109,10 @@ where
announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
runtime_api: Arc<RA>,
) -> Self {
let wait_to_announce = Arc::new(Mutex::new(WaitToAnnounce::new(spawner, announce_block)));
let wait_to_announce =
Arc::new(Mutex::new(WaitToAnnounce::new(spawner, announce_block.clone())));

Self { block_status, wait_to_announce, runtime_api }
Self { block_status, wait_to_announce, announce_block, runtime_api }
}

/// Checks the status of the given block hash in the Parachain.
Expand Down Expand Up @@ -315,4 +324,8 @@ where
) -> oneshot::Sender<CollationSecondedSignal> {
CollatorService::announce_with_barrier(self, block_hash)
}

fn announce_block(&self, block_hash: Block::Hash, data: Option<Vec<u8>>) {
(self.announce_block)(block_hash, data)
}
}
3 changes: 3 additions & 0 deletions client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ async-trait = "0.1.71"
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ] }
futures = "0.3.28"
tracing = "0.1.37"
lru = "0.10.0"

# Substrate
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sc-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
Expand All @@ -35,6 +37,7 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate
cumulus-client-consensus-common = { path = "../common" }
cumulus-relay-chain-interface = { path = "../../relay-chain-interface" }
cumulus-client-consensus-proposer = { path = "../proposer" }
cumulus-primitives-aura = { path = "../../../primitives/aura" }
cumulus-primitives-core = { path = "../../../primitives/core" }
cumulus-primitives-parachain-inherent = { path = "../../../primitives/parachain-inherent" }
cumulus-client-collator = { path = "../../collator" }
Expand Down
Loading

0 comments on commit a06efab

Please sign in to comment.