From 7a0dbd1d2424e20efb9e9d254981ec211f183dcf Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Mon, 23 Dec 2024 18:29:48 +0000 Subject: [PATCH] (feat) Start of an exception list --- bridge-validators/src/block.rs | 7 ++++++- bridge-validators/src/client.rs | 4 +++- bridge-validators/src/exceptions.rs | 18 ++++++++++++++++++ bridge-validators/src/main.rs | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 bridge-validators/src/exceptions.rs diff --git a/bridge-validators/src/block.rs b/bridge-validators/src/block.rs index 8fc8d28..14b61f8 100644 --- a/bridge-validators/src/block.rs +++ b/bridge-validators/src/block.rs @@ -112,7 +112,11 @@ impl ChainClient { } if matches { info!("Event matches; pushing for transit"); - result.push(log); + if let Some(v) = self.except.transform_log(&log) { + result.push(v); + } else { + info!("Log {log:?} could not be sent for transit due transform_log() failure"); + } } } } else { @@ -202,6 +206,7 @@ impl BlockPolling for ChainClient { let events: Vec = logs .into_iter() + .filter_map(|log| self.except.transform_log(&log)) .map(|log| Ok(parse_log::(log)?)) .collect::>>()?; diff --git a/bridge-validators/src/client.rs b/bridge-validators/src/client.rs index f2dc13a..77a25ac 100644 --- a/bridge-validators/src/client.rs +++ b/bridge-validators/src/client.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::{ChainGateway, ValidatorManager}; +use crate::{exceptions, ChainGateway, ValidatorManager}; use anyhow::Result; use ethers::{ middleware::{MiddlewareBuilder, NonceManagerMiddleware, SignerMiddleware}, @@ -37,6 +37,7 @@ pub struct ChainClient { pub scan_behind_blocks: u64, pub log_strategy: LogStrategy, pub to_block_number: Option, + pub except: exceptions::ExceptionProcessor, } impl fmt::Display for ChainClient { @@ -106,6 +107,7 @@ impl ChainClient { scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(), log_strategy: strategy, to_block_number: config.to_block_number, + except: exceptions::ExceptionProcessor::new(), }) } } diff --git a/bridge-validators/src/exceptions.rs b/bridge-validators/src/exceptions.rs new file mode 100644 index 0000000..da0d923 --- /dev/null +++ b/bridge-validators/src/exceptions.rs @@ -0,0 +1,18 @@ +use ethers::types::Log; + +/// The exception processor handles exceptions - these are txns which were issued in error, usually as a result +/// of a bug in the relayer contracts; their parameters are corrected here before being passed on to the rest of +/// the relayer logic for execution. +#[derive(Debug, Clone)] +pub struct ExceptionProcessor {} + +impl ExceptionProcessor { + pub fn new() -> Self { + ExceptionProcessor {} + } + + // We'll warn!() if we have to drop a log. + pub fn transform_log(&self, log: &Log) -> Option { + Some(log.clone()) + } +} diff --git a/bridge-validators/src/main.rs b/bridge-validators/src/main.rs index 00dfc7b..85443b2 100644 --- a/bridge-validators/src/main.rs +++ b/bridge-validators/src/main.rs @@ -3,6 +3,7 @@ mod bridge_node; mod client; mod crypto; mod event; +mod exceptions; mod message; mod p2p_node; mod signature;