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

connected disconnected state removal #3803

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0c576f3
X
drahnr Sep 6, 2021
9b10894
fixup proc macro
drahnr Sep 7, 2021
1a90b59
remove connect disconnect state
drahnr Sep 7, 2021
04b48ea
cleanup warnings
drahnr Sep 7, 2021
8f738dc
split new partial
drahnr Sep 7, 2021
9457019
cleanup: overseer residue
drahnr Sep 8, 2021
b5a3f5f
spellcheck
drahnr Sep 8, 2021
b9d1cf1
fixin
drahnr Sep 8, 2021
2ded22d
groundwork to obsolete Overseer::new and AllSubsystemsGen proc-macro
drahnr Sep 8, 2021
ed10d78
Now all malus & tests can be ported to the builder pattern.
drahnr Sep 8, 2021
f895214
spellcheck
drahnr Sep 8, 2021
4865bdf
adjust tests, minor fixes
drahnr Sep 8, 2021
6cac23e
remove derive macro AllSubsystemsGen
drahnr Sep 8, 2021
f95761d
add forgotten file dummy.rs
drahnr Sep 8, 2021
d212767
remove residue
drahnr Sep 8, 2021
00015d4
good news everyone!
drahnr Sep 9, 2021
f7990be
spellcheck
drahnr Sep 9, 2021
9ef9b2e
spellcheck
drahnr Sep 9, 2021
363231f
Merge remote-tracking branch 'origin/master' into bernhard-overseer-c…
drahnr Sep 9, 2021
618fb53
address review comments
drahnr Sep 9, 2021
8ec0361
fixup imports
drahnr Sep 9, 2021
3fb3a70
refactor init code to not require a `OverseerHandle` when we don't ha…
drahnr Sep 9, 2021
814a18f
make it conditional
drahnr Sep 9, 2021
de6f89a
fixup docs
drahnr Sep 10, 2021
1eda912
reduce import
drahnr Sep 10, 2021
05f3155
Merge remote-tracking branch 'origin' into bernhard-overseer-connecte…
drahnr Sep 10, 2021
1ef6d3b
spellcheck
drahnr Sep 10, 2021
8334908
Merge remote-tracking branch 'origin/master' into bernhard-overseer-c…
drahnr Sep 13, 2021
6acee9f
chore: fmt
drahnr Sep 13, 2021
2f60f54
hide basics
drahnr Sep 13, 2021
9e58be3
Merge remote-tracking branch 'origin/master' into bernhard-overseer-c…
drahnr Sep 14, 2021
be948fd
Update node/service/src/relay_chain_selection.rs
drahnr Sep 14, 2021
a10f0f1
Merge remote-tracking branch 'origin' into bernhard-overseer-connecte…
drahnr Sep 16, 2021
e84e6f4
chore: fmt
drahnr Sep 16, 2021
eee560a
chore: spellcheck / nlprules
drahnr Sep 16, 2021
2e1257f
fixup malus variant-a
drahnr Sep 16, 2021
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
Next Next commit
X
  • Loading branch information
drahnr committed Sep 6, 2021
commit 0c576f32ca1d4a4cd151606b900f721d67b351c6
17 changes: 13 additions & 4 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -293,7 +293,7 @@ fn jaeger_launch_collector_with_agent(
}

#[cfg(feature = "full-node")]
type FullSelectChain = relay_chain_selection::SelectRelayChainWithFallback<FullBackend>;
type FullSelectChain = relay_chain_selection::SelectRelayChain<FullBackend>;
#[cfg(feature = "full-node")]
type FullGrandpaBlockImport<RuntimeApi, ExecutorDispatch> = grandpa::GrandpaBlockImport<
FullBackend,
@@ -391,8 +391,17 @@ where

jaeger_launch_collector_with_agent(task_manager.spawn_handle(), &*config, jaeger_agent)?;

let select_chain = relay_chain_selection::SelectRelayChainWithFallback::new(
// we should remove this check before we deploy parachains on polkadot
// TODO: https://github.com/paritytech/polkadot/issues/3326
let chain_spec = config.chain_spec.as_ref();
let is_relay_chain = chain_spec.is_kusama() ||
chain_spec.is_westend() ||
chain_spec.is_rococo() ||
chain_spec.is_wococo();

let select_chain = relay_chain_selection::SelectRelayChain::new(
backend.clone(),
is_relay_chain,
Handle::new_disconnected(),
polkadot_node_subsystem_util::metrics::Metrics::register(config.prometheus_registry())?,
);
@@ -891,12 +900,12 @@ where
);
// we should remove this check before we deploy parachains on polkadot
// TODO: https://github.com/paritytech/polkadot/issues/3326
rphmeier marked this conversation as resolved.
Show resolved Hide resolved
let should_connect_overseer = chain_spec.is_kusama() ||
let is_relay_chain = chain_spec.is_kusama() ||
chain_spec.is_westend() ||
chain_spec.is_rococo() ||
chain_spec.is_wococo();

if should_connect_overseer {
if is_relay_chain {
select_chain.connect_to_overseer(overseer_handle.clone());
} else {
tracing::info!("Overseer is running in the disconnected state");
73 changes: 30 additions & 43 deletions node/service/src/relay_chain_selection.rs
Original file line number Diff line number Diff line change
@@ -109,66 +109,53 @@ impl Metrics {
}

/// A chain-selection implementation which provides safety for relay chains.
pub struct SelectRelayChainWithFallback<B: sc_client_api::Backend<PolkadotBlock>> {
// A fallback to use in case the overseer is disconnected.
//
// This is used on relay chains which have not yet enabled
// parachains as well as situations where the node is offline.
fallback: sc_consensus::LongestChain<B, PolkadotBlock>,
selection: SelectRelayChain<B, Handle>,
pub struct SelectRelayChain<B: sc_client_api::Backend<PolkadotBlock>> {
is_relay_chain: bool,
longest_chain: sc_consensus::LongestChain<B, PolkadotBlock>,
selection: SelectRelayChainInner<B, Handle>,
}

impl<B> Clone for SelectRelayChainWithFallback<B>
impl<B> Clone for SelectRelayChain<B>
where
B: sc_client_api::Backend<PolkadotBlock>,
SelectRelayChain<B, Handle>: Clone,
SelectRelayChainInner<B, Handle>: Clone,
{
fn clone(&self) -> Self {
Self { fallback: self.fallback.clone(), selection: self.selection.clone() }
Self { longest_chain: self.longest_chain.clone(), selection: self.selection.clone() }
}
}

impl<B> SelectRelayChainWithFallback<B>
impl<B> SelectRelayChain<B>
where
B: sc_client_api::Backend<PolkadotBlock> + 'static,
{
/// Create a new [`SelectRelayChainWithFallback`] wrapping the given chain backend
/// Create a new [`SelectRelayChain`] wrapping the given chain backend
/// and a handle to the overseer.
pub fn new(backend: Arc<B>, overseer: Handle, metrics: Metrics) -> Self {
SelectRelayChainWithFallback {
fallback: sc_consensus::LongestChain::new(backend.clone()),
selection: SelectRelayChain::new(backend, overseer, metrics),
pub fn new(backend: Arc<B>, is_relay_chain: bool, overseer: Handle, metrics: Metrics) -> Self {
SelectRelayChain {
is_relay_chain,
longest_chain: sc_consensus::LongestChain::new(backend.clone()),
selection: SelectRelayChainInner::new(backend, overseer, metrics),
}
}
}

impl<B> SelectRelayChainWithFallback<B>
where
B: sc_client_api::Backend<PolkadotBlock> + 'static,
{
/// Given an overseer handle, this connects the [`SelectRelayChainWithFallback`]'s
/// internal handle and its clones to the same overseer.
pub fn connect_to_overseer(&mut self, handle: OverseerHandle) {
self.selection.overseer.connect_to_overseer(handle);
}
}

#[async_trait::async_trait]
impl<B> SelectChain<PolkadotBlock> for SelectRelayChainWithFallback<B>
impl<B> SelectChain<PolkadotBlock> for SelectRelayChain<B>
where
B: sc_client_api::Backend<PolkadotBlock> + 'static,
{
async fn leaves(&self) -> Result<Vec<Hash>, ConsensusError> {
if self.selection.overseer.is_disconnected() {
return self.fallback.leaves().await
if !self.is_relay_chain {
return self.longest_chain.leaves().await
}

self.selection.leaves().await
}

async fn best_chain(&self) -> Result<PolkadotHeader, ConsensusError> {
if self.selection.overseer.is_disconnected() {
return self.fallback.best_chain().await
if !self.is_relay_chain {
return self.longest_chain.best_chain().await
}
self.selection.best_chain().await
}
@@ -179,34 +166,34 @@ where
maybe_max_number: Option<BlockNumber>,
) -> Result<Option<Hash>, ConsensusError> {
let longest_chain_best =
self.fallback.finality_target(target_hash, maybe_max_number).await?;
self.longest_chain.finality_target(target_hash, maybe_max_number).await?;

if self.selection.overseer.is_disconnected() {
if self.is_relay_chain {
drahnr marked this conversation as resolved.
Show resolved Hide resolved
drahnr marked this conversation as resolved.
Show resolved Hide resolved
return Ok(longest_chain_best)
}
self.selection
.finality_target_with_fallback(target_hash, longest_chain_best, maybe_max_number)
.finality_target_with_longest_chain(target_hash, longest_chain_best, maybe_max_number)
.await
}
}

/// A chain-selection implementation which provides safety for relay chains
/// but does not handle situations where the overseer is not yet connected.
pub struct SelectRelayChain<B, OH> {
pub struct SelectRelayChainInner<B, OH> {
drahnr marked this conversation as resolved.
Show resolved Hide resolved
backend: Arc<B>,
overseer: OH,
metrics: Metrics,
}

impl<B, OH> SelectRelayChain<B, OH>
impl<B, OH> SelectRelayChainInner<B, OH>
where
B: HeaderProviderProvider<PolkadotBlock>,
OH: OverseerHandleT,
{
/// Create a new [`SelectRelayChain`] wrapping the given chain backend
/// Create a new [`SelectRelayChainInner`] wrapping the given chain backend
/// and a handle to the overseer.
pub fn new(backend: Arc<B>, overseer: OH, metrics: Metrics) -> Self {
SelectRelayChain { backend, overseer, metrics }
SelectRelayChainInner { backend, overseer, metrics }
}

fn block_header(&self, hash: Hash) -> Result<PolkadotHeader, ConsensusError> {
@@ -234,13 +221,13 @@ where
}
}

impl<B, OH> Clone for SelectRelayChain<B, OH>
impl<B, OH> Clone for SelectRelayChainInner<B, OH>
where
B: HeaderProviderProvider<PolkadotBlock> + Send + Sync,
OH: OverseerHandleT,
{
fn clone(&self) -> Self {
SelectRelayChain {
SelectRelayChainInner {
backend: self.backend.clone(),
overseer: self.overseer.clone(),
metrics: self.metrics.clone(),
@@ -273,7 +260,7 @@ impl OverseerHandleT for Handle {
}
}

impl<B, OH> SelectRelayChain<B, OH>
impl<B, OH> SelectRelayChainInner<B, OH>
where
B: HeaderProviderProvider<PolkadotBlock>,
OH: OverseerHandleT,
@@ -317,7 +304,7 @@ where
///
/// It will also constrain the chain to only chains which are fully
/// approved, and chains which contain no disputes.
pub(crate) async fn finality_target_with_fallback(
pub(crate) async fn finality_target_with_longest_chain(
&self,
target_hash: Hash,
best_leaf: Option<Hash>,
2 changes: 1 addition & 1 deletion node/service/src/tests.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(

let (finality_target_tx, finality_target_rx) = oneshot::channel::<Option<Hash>>();

let select_relay_chain = SelectRelayChain::<TestChainStorage, TestSubsystemSender>::new(
let select_relay_chain = SelectRelayChainInner::<TestChainStorage, TestSubsystemSender>::new(
Arc::new(case_vars.chain.clone()),
context.sender().clone(),
Default::default(),