Skip to content

Commit

Permalink
(feat) Start of an exception list
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Dec 23, 2024
1 parent 652006b commit 7a0dbd1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -202,6 +206,7 @@ impl BlockPolling for ChainClient {

let events: Vec<D> = logs
.into_iter()
.filter_map(|log| self.except.transform_log(&log))
.map(|log| Ok(parse_log::<D>(log)?))
.collect::<Result<Vec<D>>>()?;

Expand Down
4 changes: 3 additions & 1 deletion bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -37,6 +37,7 @@ pub struct ChainClient {
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
pub except: exceptions::ExceptionProcessor,
}

impl fmt::Display for ChainClient {
Expand Down Expand Up @@ -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(),
})
}
}
Expand Down
18 changes: 18 additions & 0 deletions bridge-validators/src/exceptions.rs
Original file line number Diff line number Diff line change
@@ -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<Log> {
Some(log.clone())
}
}
1 change: 1 addition & 0 deletions bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod bridge_node;
mod client;
mod crypto;
mod event;
mod exceptions;
mod message;
mod p2p_node;
mod signature;
Expand Down

0 comments on commit 7a0dbd1

Please sign in to comment.