From 37bfe6bcc74eeb45b2042db92efa98d6cd7b03fe Mon Sep 17 00:00:00 2001 From: Erik Reppel Date: Thu, 25 Apr 2024 16:54:54 -0400 Subject: [PATCH] Return a status enum and break loop if chain not supported --- src/chain.rs | 8 ++++++-- src/run.rs | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/chain.rs b/src/chain.rs index cc17566..959a8d2 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -51,7 +51,7 @@ impl MintChecker { } /// Polls for new mints based on a filter defined by the PremintType - pub async fn poll_for_new_mints(&self) -> eyre::Result<()> { + pub async fn poll_for_new_mints(&self) -> eyre::Result { let mut highest_block: Option = None; let mut filter = if let Some(filter) = T::check_filter(self.chain_id) { @@ -59,7 +59,7 @@ impl MintChecker { } else { let err = eyre::eyre!("No filter for chain / premint type, skipping spawning checker"); tracing::warn!(error = err.to_string(), "checking failed"); - return Err(err); + return Ok(MintCheckerResult::NoFilter); }; loop { @@ -119,6 +119,10 @@ impl MintChecker { } } +pub enum MintCheckerResult { + NoFilter, +} + /// checks the chain to ensure an inclusion claim actually does exist so we can safely prune pub async fn inclusion_claim_correct( premint: &PremintTypes, diff --git a/src/run.rs b/src/run.rs index 8b9e571..323f0f8 100644 --- a/src/run.rs +++ b/src/run.rs @@ -4,7 +4,7 @@ use libp2p::identity::Keypair; use std::time::Duration; use tracing::{info_span, Instrument}; -use crate::chain::{get_contract_boot_nodes, MintChecker}; +use crate::chain::{get_contract_boot_nodes, MintChecker, MintCheckerResult}; use crate::chain_list::CHAINS; use crate::config::{BootNodes, ChainInclusionMode, Config}; use crate::controller::{Controller, ControllerCommands, ControllerInterface}; @@ -143,12 +143,21 @@ pub async fn start_watch_chain(config: &Config, controller: Controll let checker = MintChecker::new(chain_id, rpc_url, controller.clone()); tokio::spawn(async move { loop { - if let Err(err) = checker.poll_for_new_mints::().await { - tracing::error!( - error = err.to_string(), - chain_id = chain_id, - "checker failed" - ); + match checker.poll_for_new_mints::().await { + Ok(MintCheckerResult::NoFilter) => { + tracing::warn!( + chain_id = chain_id, + "No filter for chain / premint type, skipping checker" + ); + break; + } + Err(err) => { + tracing::error!( + error = err.to_string(), + chain_id = chain_id, + "checker failed" + ); + } } } });