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

Commit

Permalink
SelectChain implementation for relay chains (#3341)
Browse files Browse the repository at this point in the history
* stubbed SelectRelayChain

* disconnected overseer handlers

* add is_disconnected

* add fallback in case overseer is disconnected

* fall back on fallback

* fetch leaves by calling into chain-selection subsystem

* implement best_chain

* mostly implement finality_target

* chain constrain

* metrics and maximum safeguard

* remove review comment after review
  • Loading branch information
rphmeier authored Jun 22, 2021
1 parent 869a130 commit 6331c25
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

41 changes: 36 additions & 5 deletions node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,33 @@ enum ExternalRequest {
/// [`Overseer`]: struct.Overseer.html
#[derive(Clone)]
pub struct OverseerHandler {
events_tx: metered::MeteredSender<Event>,
events_tx: Option<metered::MeteredSender<Event>>,
}

impl OverseerHandler {
/// Create a disconnected overseer handler.
pub fn disconnected() -> Self {
OverseerHandler {
events_tx: None,
}
}

/// Whether the overseer handler is connected to an overseer.
pub fn is_connected(&self) -> bool {
self.events_tx.is_some()
}

/// Whether the handler is disconnected.
pub fn is_disconnected(&self) -> bool {
self.events_tx.is_none()
}

/// Using this handler, connect another handler to the same
/// overseer, if any.
pub fn connect_other(&self, other: &mut OverseerHandler) {
other.events_tx = self.events_tx.clone();
}

/// Inform the `Overseer` that that some block was imported.
pub async fn block_imported(&mut self, block: BlockInfo) {
self.send_and_log_error(Event::BlockImported(block)).await
Expand Down Expand Up @@ -457,8 +480,10 @@ impl OverseerHandler {
}

async fn send_and_log_error(&mut self, event: Event) {
if self.events_tx.send(event).await.is_err() {
tracing::info!(target: LOG_TARGET, "Failed to send an event to Overseer");
if let Some(ref mut events_tx) = self.events_tx {
if events_tx.send(event).await.is_err() {
tracing::info!(target: LOG_TARGET, "Failed to send an event to Overseer");
}
}
}
}
Expand Down Expand Up @@ -1274,7 +1299,13 @@ where
S: SpawnNamed,
SupportsParachains: HeadSupportsParachains,
{
/// Create a new instance of the `Overseer` with a fixed set of [`Subsystem`]s.
/// Create a new instance of the [`Overseer`] with a fixed set of [`Subsystem`]s.
///
/// This returns the overseer along with an [`OverseerHandler`] which can
/// be used to send messages from external parts of the codebase.
///
/// The [`OverseerHandler`] returned from this function is connected to
/// the returned [`Overseer`].
///
/// ```text
/// +------------------------------------+
Expand Down Expand Up @@ -1393,7 +1424,7 @@ where
let (events_tx, events_rx) = metered::channel(CHANNEL_CAPACITY);

let handler = OverseerHandler {
events_tx: events_tx.clone(),
events_tx: Some(events_tx.clone()),
};

let metrics = <Metrics as metrics::Metrics>::register(prometheus_registry)?;
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ serde = { version = "1.0.123", features = ["derive"] }
thiserror = "1.0.23"
kvdb = "0.9.0"
kvdb-rocksdb = { version = "0.11.1", optional = true }
async-trait = "0.1.42"

# Polkadot
polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" }
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/grandpa_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingVotingRule

/// Returns the block hash of the block at the given `target_number` by walking
/// backwards from the given `current_header`.
fn walk_backwards_to_target_block<Block, B>(
pub(super) fn walk_backwards_to_target_block<Block, B>(
backend: &B,
target_number: NumberFor<Block>,
current_header: &Block::Header,
Expand Down
1 change: 1 addition & 0 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pub mod chain_spec;
mod grandpa_support;
mod parachains_db;
mod relay_chain_selection;

#[cfg(feature = "full-node")]
mod overseer;
Expand Down
Loading

0 comments on commit 6331c25

Please sign in to comment.