Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a status enum and break loop if chain not supported #57

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ impl MintChecker {
}

/// Polls for new mints based on a filter defined by the PremintType
pub async fn poll_for_new_mints<T: Premint>(&self) -> eyre::Result<()> {
pub async fn poll_for_new_mints<T: Premint>(&self) -> eyre::Result<MintCheckerResult> {
let mut highest_block: Option<u64> = None;

let mut filter = if let Some(filter) = T::check_filter(self.chain_id) {
filter
} 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 {
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -143,12 +143,21 @@ pub async fn start_watch_chain<T: Premint>(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::<T>().await {
tracing::error!(
error = err.to_string(),
chain_id = chain_id,
"checker failed"
);
match checker.poll_for_new_mints::<T>().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"
);
}
}
}
});
Expand Down
Loading