Showing better errors for critical failures
This commit is contained in:
@@ -36,6 +36,7 @@ impl Processor {
|
||||
|
||||
// since we have no graceful shutdowns, seeing this error means something bad has happened
|
||||
// as all senders got dropped
|
||||
error!("")
|
||||
error!("Dealing Processor has stopped receiving events! The process is in an undefined state. Shutting down...");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::dkg::main_loop::ContractEventsSender;
|
||||
use futures::channel::mpsc;
|
||||
use futures::StreamExt;
|
||||
use log::error;
|
||||
use std::fmt::Display;
|
||||
|
||||
pub(crate) type DispatcherSender = mpsc::UnboundedSender<Event>;
|
||||
pub(crate) type DispatcherReceiver = mpsc::UnboundedReceiver<Event>;
|
||||
@@ -19,13 +20,23 @@ pub(crate) struct Dispatcher {
|
||||
}
|
||||
|
||||
impl Dispatcher {
|
||||
// we require `T` to be explicitly `Display` for the purposes of providing better error messages
|
||||
// before crashing
|
||||
fn forward_event<T: Display>(&self, channel: &mpsc::UnboundedSender<T>, event_item: T) {
|
||||
if let Err(err) = channel.unbounded_send(event_item) {
|
||||
log::error!("Our event dispatcher failed to forward {} event - the receiver has presumably crashed. Shutting down the API...", err.into_inner());
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_event(&self, event: Event) {
|
||||
match event {
|
||||
Event::NewDealing(new_dealing_request) => self
|
||||
.dealing_processor
|
||||
.unbounded_send(new_dealing_request)
|
||||
.expect("failed to forward new dealing message"),
|
||||
_ => todo!(),
|
||||
Event::NewDealing(new_dealing_request) => {
|
||||
self.forward_event(&self.dealing_processor, new_dealing_request)
|
||||
}
|
||||
Event::DkgContractChange(watcher_event) => {
|
||||
self.forward_event(&self.contract_event_sender, watcher_event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +47,7 @@ impl Dispatcher {
|
||||
|
||||
// since we have no graceful shutdowns, seeing this error means something bad has happened
|
||||
// as all senders got dropped
|
||||
error!("")
|
||||
error!("Event Dispatcher has stopped receiving events! The process is in an undefined state. Shutting down...");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,21 +3,23 @@
|
||||
|
||||
use crate::dkg::networking::message::{NewDealingMessage, RemoteDealingRequestMessage};
|
||||
use crate::dkg::smart_contract::watcher;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Event {
|
||||
NewDealing(NewDealingMessage),
|
||||
NewDealingRequest(RemoteDealingRequestMessage),
|
||||
DkgContractChange(watcher::Event),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
pub(crate) fn name(&self) -> String {
|
||||
impl Display for Event {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Event::NewDealing(..) => "NewDealing".to_string(),
|
||||
Event::NewDealingRequest(..) => "NewDealingRequest".to_string(),
|
||||
|
||||
Event::DkgContractChange(..) => "DkgContractChange".to_string(),
|
||||
Event::NewDealing(new_dealing_message) => {
|
||||
write!(f, "NewDealingEvent ({})", new_dealing_message)
|
||||
}
|
||||
Event::DkgContractChange(contract_watcher_event) => {
|
||||
write!(f, "DkgContractChangeEvent ({})", contract_watcher_event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ impl ProcessingLoop {
|
||||
|
||||
// since we have no graceful shutdowns, seeing this error means something bad has happened
|
||||
// as all senders got dropped
|
||||
error!("")
|
||||
error!("DKG Processing Loop has stopped receiving events! The process is in an undefined state. Shutting down...");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::dkg::state::ReceivedDealing;
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use crypto::asymmetric::identity;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
@@ -41,6 +42,17 @@ pub struct NewDealingMessage {
|
||||
pub dealer_signature: identity::Signature,
|
||||
}
|
||||
|
||||
impl Display for NewDealingMessage {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"NewDealingMessage for epoch {} with length {}",
|
||||
self.epoch_id,
|
||||
self.dealing_bytes.len()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RemoteDealingRequestMessage {
|
||||
pub epoch_id: u32,
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Event {
|
||||
NewDealingCommitment,
|
||||
}
|
||||
|
||||
impl Display for Event {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "SmartContractWatcherEvent - ")?;
|
||||
match self {
|
||||
Event::NewDealingCommitment => write!(f, "NewDealingCommitment"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub(crate) struct StateAccessor {
|
||||
impl StateAccessor {
|
||||
pub(crate) async fn push_event(&self, event: Event) {
|
||||
if let Err(err) = self.dispatcher_sender.unbounded_send(event) {
|
||||
log::error!("Our event dispatcher failed to receive {} event - it has presumably crashed. Shutting down the API after saving DKG state", err.into_inner().name());
|
||||
log::error!("Our event dispatcher failed to receive {} event - it has presumably crashed. Shutting down the API after saving DKG state", err.into_inner());
|
||||
self.dkg_state.save().await;
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user