introduce errors with info (#1834)

This commit is contained in:
Bernhard Schuster
2020-10-27 08:10:03 +01:00
committed by GitHub
parent 40ea09389c
commit f345123748
58 changed files with 1983 additions and 2030 deletions
+24 -16
View File
@@ -54,6 +54,11 @@
//! ..................................................................
//! ```
// #![deny(unused_results)]
// unused dependencies can not work for test and examples at the same time
// yielding false positives
#![warn(missing_docs)]
use std::fmt::Debug;
use std::pin::Pin;
use std::sync::Arc;
@@ -96,7 +101,6 @@ const STOP_DELAY: u64 = 1;
// Target for logs.
const LOG_TARGET: &'static str = "overseer";
/// A type of messages that are sent from [`Subsystem`] to [`Overseer`].
///
/// It wraps a system-wide [`AllMessages`] type that represents all possible
@@ -160,7 +164,7 @@ impl From<FinalityNotification<Block>> for BlockInfo {
}
}
/// Some event from outer world.
/// Some event from the outer world.
enum Event {
BlockImported(BlockInfo),
BlockFinalized(BlockInfo),
@@ -173,7 +177,7 @@ enum Event {
enum ExternalRequest {
WaitForActivation {
hash: Hash,
response_channel: oneshot::Sender<()>,
response_channel: oneshot::Sender<SubsystemResult<()>>,
},
}
@@ -208,7 +212,7 @@ impl OverseerHandler {
/// Note that due the fact the overseer doesn't store the whole active-leaves set, only deltas,
/// the response channel may never return if the hash was deactivated before this call.
/// In this case, it's the caller's responsibility to ensure a timeout is set.
pub async fn wait_for_activation(&mut self, hash: Hash, response_channel: oneshot::Sender<()>) -> SubsystemResult<()> {
pub async fn wait_for_activation(&mut self, hash: Hash, response_channel: oneshot::Sender<SubsystemResult<()>>) -> SubsystemResult<()> {
self.events_tx.send(Event::ExternalRequest(ExternalRequest::WaitForActivation {
hash,
response_channel
@@ -303,7 +307,11 @@ impl<M: Send + 'static> SubsystemContext for OverseerSubsystemContext<M> {
}
async fn recv(&mut self) -> SubsystemResult<FromOverseer<M>> {
self.rx.next().await.ok_or(SubsystemError)
self.rx.next().await
.ok_or(SubsystemError::Context(
"No more messages in rx queue to process"
.to_owned()
))
}
async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
@@ -398,7 +406,7 @@ pub struct Overseer<S> {
s: S,
/// Here we keep handles to spawned subsystems to be notified when they terminate.
running_subsystems: FuturesUnordered<BoxFuture<'static, ()>>,
running_subsystems: FuturesUnordered<BoxFuture<'static, SubsystemResult<()>>>,
/// Gather running subsystms' outbound streams into one.
running_subsystems_rx: StreamUnordered<mpsc::Receiver<ToOverseer>>,
@@ -407,7 +415,7 @@ pub struct Overseer<S> {
events_rx: mpsc::Receiver<Event>,
/// External listeners waiting for a hash to be in the active-leave set.
activation_external_listeners: HashMap<Hash, Vec<oneshot::Sender<()>>>,
activation_external_listeners: HashMap<Hash, Vec<oneshot::Sender<SubsystemResult<()>>>>,
/// A set of leaves that `Overseer` starts working with.
///
@@ -1267,7 +1275,7 @@ where
loop {
select! {
_ = self.running_subsystems.next() => {
x = self.running_subsystems.next() => {
if self.running_subsystems.is_empty() {
break;
}
@@ -1285,7 +1293,7 @@ where
for (hash, number) in leaves.into_iter() {
update.activated.push(hash);
self.active_leaves.insert(hash, number);
let _ = self.active_leaves.insert(hash, number);
self.on_head_activated(&hash);
}
@@ -1331,7 +1339,7 @@ where
if let Poll::Ready(Some(finished)) = poll!(self.running_subsystems.next()) {
log::error!(target: LOG_TARGET, "Subsystem finished unexpectedly {:?}", finished);
self.stop().await;
return Err(SubsystemError);
return finished;
}
// Looks like nothing is left to be polled, let's take a break.
@@ -1353,7 +1361,7 @@ where
match self.active_leaves.entry(block.hash) {
hash_map::Entry::Vacant(entry) => {
update.activated.push(block.hash);
entry.insert(block.number);
let _ = entry.insert(block.number);
self.on_head_activated(&block.hash);
},
hash_map::Entry::Occupied(entry) => {
@@ -1541,7 +1549,7 @@ where
if let Some(listeners) = self.activation_external_listeners.remove(hash) {
for listener in listeners {
// it's fine if the listener is no longer interested
let _ = listener.send(());
let _ = listener.send(Ok(()));
}
}
}
@@ -1567,7 +1575,7 @@ where
ExternalRequest::WaitForActivation { hash, response_channel } => {
if self.active_leaves.get(&hash).is_some() {
// it's fine if the listener is no longer interested
let _ = response_channel.send(());
let _ = response_channel.send(Ok(()));
} else {
self.activation_external_listeners.entry(hash).or_default().push(response_channel);
}
@@ -1586,7 +1594,7 @@ where
fn spawn<S: SpawnNamed, M: Send + 'static>(
spawner: &mut S,
futures: &mut FuturesUnordered<BoxFuture<'static, ()>>,
futures: &mut FuturesUnordered<BoxFuture<'static, SubsystemResult<()>>>,
streams: &mut StreamUnordered<mpsc::Receiver<ToOverseer>>,
s: impl Subsystem<OverseerSubsystemContext<M>>,
) -> SubsystemResult<OverseenSubsystem<M>> {
@@ -1604,8 +1612,8 @@ fn spawn<S: SpawnNamed, M: Send + 'static>(
spawner.spawn(name, fut);
streams.push(from_rx);
futures.push(Box::pin(rx.map(|_| ())));
let _ = streams.push(from_rx);
futures.push(Box::pin(rx.map(|e| { log::warn!("Dropping error {:?}", e); Ok(()) })));
let instance = Some(SubsystemInstance {
tx: to_tx,