Skip to content

Commit

Permalink
Log missing chain in configuration errors emitted during event proces…
Browse files Browse the repository at this point in the history
…sing at debug level (#2089)

* Log `missing chain in configuration` errors emitted during event processing at debug level

* Add changelog entry

* Undo change in `handle_batch`
  • Loading branch information
romac committed Apr 21, 2022
1 parent 4d33c6a commit 7fa70a0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1936-missing-chain-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Log `missing chain in configuration` errors emitted during event processing at
debug level ([#1936](https://github.com/informalsystems/ibc-rs/issues/1936))
2 changes: 1 addition & 1 deletion relayer-cli/src/cli_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn spawn_chain_runtime_generic<Chain: ChainHandle>(
let chain_config = config
.find_chain(chain_id)
.cloned()
.ok_or_else(|| Error::missing_config(chain_id.clone()))?;
.ok_or_else(|| Error::missing_chain_config(chain_id.clone()))?;

let rt = Arc::new(TokioRuntime::new().unwrap());
let handle =
Expand Down
6 changes: 3 additions & 3 deletions relayer-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ define_error! {
Keys
|_| { "keys error" },

MissingConfig
MissingChainConfig
{ chain_id: ChainId }
| e | {
format_args!("missing chain for id ({}) in configuration file",
format_args!("missing chain with id '{}' in configuration file",
e.chain_id)
},

MissingCounterpartyChannelId
{ channel_end: IdentifiedChannelEnd }
| e | {
format_args!("the channel {:?} counterparty has no channel id",
format_args!("this channel's counterparty has no channel id: {:?}",
e.channel_end)
},

Expand Down
18 changes: 15 additions & 3 deletions relayer/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,27 @@ define_error! {
RuntimeNotFound
| _ | { "expected runtime to be found in registry" },

MissingChain
MissingChainConfig
{ chain_id: ChainId }
| e | {
format_args!("missing chain for id ({}) in configuration file",
format_args!("missing chain config for '{}' in configuration file",
e.chain_id)
}
}
}

impl SpawnError {
pub fn log_as_debug(&self) -> bool {
self.detail().log_as_debug()
}
}

impl SpawnErrorDetail {
pub fn log_as_debug(&self) -> bool {
matches!(self, SpawnErrorDetail::MissingChainConfig(_))
}
}

/// Registry for keeping track of [`ChainHandle`]s indexed by a `ChainId`.
///
/// The purpose of this type is to avoid spawning multiple runtimes for a single `ChainId`.
Expand Down Expand Up @@ -150,7 +162,7 @@ pub fn spawn_chain_runtime<Chain: ChainHandle>(
let chain_config = config
.find_chain(chain_id)
.cloned()
.ok_or_else(|| SpawnError::missing_chain(chain_id.clone()))?;
.ok_or_else(|| SpawnError::missing_chain_config(chain_id.clone()))?;

let handle =
ChainRuntime::<CosmosSdkChain>::spawn(chain_config, rt).map_err(SpawnError::relayer)?;
Expand Down
18 changes: 12 additions & 6 deletions relayer/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::RwLock;

use crossbeam_channel::{unbounded, Receiver, Sender};
use itertools::Itertools;
use tracing::{error, error_span, info, trace, warn};
use tracing::{debug, error, error_span, info, trace, warn};

use ibc::{
core::ics24_host::identifier::{ChainId, ChannelId, PortId},
Expand All @@ -18,10 +18,7 @@ use ibc::{
use crate::{
chain::{handle::ChainHandle, HealthCheck},
config::Config,
event::{
self,
monitor::{Error as EventError, ErrorDetail as EventErrorDetail, EventBatch},
},
event::monitor::{self, Error as EventError, ErrorDetail as EventErrorDetail, EventBatch},
object::Object,
registry::{Registry, SharedRegistry},
rest,
Expand Down Expand Up @@ -50,7 +47,7 @@ use cmd::SupervisorCmd;

use self::{scan::ChainScanner, spawn::SpawnContext};

type ArcBatch = Arc<event::monitor::Result<EventBatch>>;
type ArcBatch = Arc<monitor::Result<EventBatch>>;
type Subscription = Receiver<ArcBatch>;

/**
Expand Down Expand Up @@ -332,6 +329,15 @@ fn relay_on_object<Chain: ChainHandle>(

false
}
Err(e) if e.log_as_debug() => {
debug!(
"denying relaying on object {}, caused by: {}",
object.short_name(),
e
);

false
}
Err(e) => {
warn!(
"denying relaying on object {}, caused by: {}",
Expand Down
6 changes: 6 additions & 0 deletions relayer/src/supervisor/client_state_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ define_error! {
}
}

impl FilterError {
pub fn log_as_debug(&self) -> bool {
matches!(self.detail(), FilterErrorDetail::Spawn(e) if e.source.log_as_debug())
}
}

/// A cache storing filtering status (allow or deny) for
/// arbitrary identifiers.
#[derive(Default, Debug)]
Expand Down
8 changes: 7 additions & 1 deletion relayer/src/supervisor/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ define_error! {

Spawn
[ SpawnError ]
|_| { "supervisor was not able to connect to any chains" },
|_| { "supervisor was not able to spawn chain runtime" },

Scan
[ ScanError ]
|_| { "supervisor encountered an error when scanning chains" },
}
}

impl Error {
pub fn log_as_debug(&self) -> bool {
matches!(self.detail(), ErrorDetail::Spawn(e) if e.source.log_as_debug())
}
}

0 comments on commit 7fa70a0

Please sign in to comment.