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
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 1 addition & 1 deletion node/overseer/overseer-gen/proc-macro/src/impl_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
&mut self.handle
}
/// Obtain access to the overseer handle.
pub fn as_handle(&mut self) -> &#handle {
pub fn as_handle(&self) -> &#handle {
&self.handle
}
}
Expand Down
69 changes: 6 additions & 63 deletions node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ use std::{

use futures::{channel::oneshot, future::BoxFuture, select, Future, FutureExt, StreamExt};
use lru::LruCache;
use parking_lot::RwLock;

use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};
use polkadot_primitives::v1::{Block, BlockId, BlockNumber, Hash, ParachainHost};
Expand Down Expand Up @@ -142,18 +141,12 @@ where
///
/// [`Overseer`]: struct.Overseer.html
#[derive(Clone)]
pub enum Handle {
/// Used only at initialization to break the cyclic dependency.
// TODO: refactor in https://github.com/paritytech/polkadot/issues/3427
Disconnected(Arc<RwLock<Option<OverseerHandle>>>),
/// A handle to the overseer.
Connected(OverseerHandle),
}
pub struct Handle(pub OverseerHandle);

impl Handle {
/// Create a new disconnected [`Handle`].
pub fn new_disconnected() -> Self {
Self::Disconnected(Arc::new(RwLock::new(None)))
/// Create a new [`Handle`].
pub fn new(raw: OverseerHandle) -> Self {
Self(raw)
}

/// Inform the `Overseer` that that some block was imported.
Expand Down Expand Up @@ -202,58 +195,8 @@ impl Handle {

/// Most basic operation, to stop a server.
async fn send_and_log_error(&mut self, event: Event) {
self.try_connect();
if let Self::Connected(ref mut handle) = self {
if handle.send(event).await.is_err() {
tracing::info!(target: LOG_TARGET, "Failed to send an event to Overseer");
}
} else {
tracing::warn!(target: LOG_TARGET, "Using a disconnected Handle to send to Overseer");
}
}

/// Whether the handle is disconnected.
pub fn is_disconnected(&self) -> bool {
match self {
Self::Disconnected(ref x) => x.read().is_none(),
_ => false,
}
}

/// Connect this handle and all disconnected clones of it to the overseer.
pub fn connect_to_overseer(&mut self, handle: OverseerHandle) {
match self {
Self::Disconnected(ref mut x) => {
let mut maybe_handle = x.write();
if maybe_handle.is_none() {
tracing::info!(target: LOG_TARGET, "🖇️ Connecting all Handles to Overseer");
*maybe_handle = Some(handle);
} else {
tracing::warn!(
target: LOG_TARGET,
"Attempting to connect a clone of a connected Handle",
);
}
},
_ => {
tracing::warn!(
target: LOG_TARGET,
"Attempting to connect an already connected Handle",
);
},
}
}

/// Try upgrading from `Self::Disconnected` to `Self::Connected` state
/// after calling `connect_to_overseer` on `self` or a clone of `self`.
fn try_connect(&mut self) {
if let Self::Disconnected(ref mut x) = self {
let guard = x.write();
if let Some(ref h) = *guard {
let handle = h.clone();
drop(guard);
*self = Self::Connected(handle);
}
if self.0.send(event).await.is_err() {
tracing::info!(target: LOG_TARGET, "Failed to send an event to Overseer");
}
}
}
Expand Down
Loading