From 44b4970ad8238aaf4b95309132d4c138abc304c7 Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Tue, 26 Nov 2024 08:45:34 +0000 Subject: [PATCH] (feat) Ignore status where necessary - some chains don't provide it --- bridge-validators/config.toml | 5 +++++ bridge-validators/src/block.rs | 11 ++++++++--- bridge-validators/src/client.rs | 5 ++++- bridge-validators/src/main.rs | 5 +++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bridge-validators/config.toml b/bridge-validators/config.toml index 5a7e990..fa3f4ef 100644 --- a/bridge-validators/config.toml +++ b/bridge-validators/config.toml @@ -42,6 +42,11 @@ legacy_gas_estimation_percent = 130 ## fetching the receipt and scanning it for relevant logs. This is slow, but at least it works .. ## use_get_transactions = true +## Some chains (like ZQ1) insist on generating events for failed txns; these come with a status==0 +## value. However, other chains (eg. BSC) do not send a status==0 value but only generate events +## for txns which succeed. In order to fail safe, we need to mark when we should accept logs with +## nonexistent statuses +accept_events_with_no_status = true # BSC Mainnet # [[chain_configs]] diff --git a/bridge-validators/src/block.rs b/bridge-validators/src/block.rs index c98f710..01b2211 100644 --- a/bridge-validators/src/block.rs +++ b/bridge-validators/src/block.rs @@ -65,8 +65,10 @@ impl ChainClient { info!("[1] txn failed - skipping"); continue; } + } else if self.accept_events_with_no_status { + info!("[1] txn {:#x} has no status - accept_events_with_no_status = true; accepting", txn_hash); } else { - info!("[1] txn {:#x} has no status - ignoring", txn_hash); + info!("[1] txn {:#x} has no status - accept_events_with_no_status = false; rejecting", txn_hash); continue; } info!("Got receipt for txn {:#x}", txn_hash); @@ -168,7 +170,8 @@ impl BlockPolling for ChainClient { .filter(|log| { log.get("status") .and_then(|v| v.as_i64()) - .map_or(false, |s| { + .map_or( + self.accept_events_with_no_status, |s| { if s != 1 { info!("txn failed: status = {s:#x}"); false @@ -183,10 +186,12 @@ impl BlockPolling for ChainClient { .and_then(|val| val.parse::
().ok()) .map(|from_address| { if from_address == self.chain_gateway_address { + info!("event from {0:#x} has correct chain_gateway_address {1:#x}; accepting", + from_address, self.chain_gateway_address); true } else { info!( - "event from {0:#x} , chain gateway {1:#x}", + "event from {0:#x} , chain gateway {1:#x} - rejecting", from_address, self.chain_gateway_address ); false diff --git a/bridge-validators/src/client.rs b/bridge-validators/src/client.rs index 8af79d2..f4bd915 100644 --- a/bridge-validators/src/client.rs +++ b/bridge-validators/src/client.rs @@ -36,6 +36,7 @@ pub struct ChainClient { pub scan_behind_blocks: u64, pub log_strategy: LogStrategy, pub to_block_number: Option, + pub accept_events_with_no_status: bool, } impl fmt::Display for ChainClient { @@ -46,8 +47,9 @@ impl fmt::Display for ChainClient { impl ChainClient { pub async fn new(config: &ChainConfig, wallet: LocalWallet) -> Result { + let accept_events_with_no_status = config.accept_events_with_no_status.unwrap_or(false); info!( - "initialising chain client for URL {0} with gateway {1:#x} ... ", + "initialising chain client for URL {0} with gateway {1:#x}; accept_events_with_no_status = {accept_events_with_no_status} ... ", config.rpc_url.as_str(), config.chain_gateway_address ); @@ -82,6 +84,7 @@ impl ChainClient { scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(), log_strategy: strategy, to_block_number: config.to_block_number, + accept_events_with_no_status, }) } } diff --git a/bridge-validators/src/main.rs b/bridge-validators/src/main.rs index 00dfc7b..39a9721 100644 --- a/bridge-validators/src/main.rs +++ b/bridge-validators/src/main.rs @@ -35,6 +35,11 @@ pub struct ChainConfig { pub scan_behind_blocks: Option, pub use_get_transactions: Option, pub to_block_number: Option, + /// If set, we will accept events with no status - this covers the vast + /// majority of networks; Zilliqa 1 unfortunely will emit events with no + /// status, and failing safe requires us to generate the option this way + /// around :-( + pub accept_events_with_no_status: Option, } #[derive(Debug, Clone, Deserialize)]