Skip to content

Commit

Permalink
(feat) Ignore status where necessary - some chains don't provide it
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Nov 26, 2024
1 parent 0e723d8 commit 44b4970
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions bridge-validators/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
11 changes: 8 additions & 3 deletions bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -183,10 +186,12 @@ impl BlockPolling for ChainClient {
.and_then(|val| val.parse::<Address>().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
Expand Down
5 changes: 4 additions & 1 deletion bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct ChainClient {
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
pub accept_events_with_no_status: bool,
}

impl fmt::Display for ChainClient {
Expand All @@ -46,8 +47,9 @@ impl fmt::Display for ChainClient {

impl ChainClient {
pub async fn new(config: &ChainConfig, wallet: LocalWallet) -> Result<Self> {
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
);
Expand Down Expand Up @@ -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,
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub struct ChainConfig {
pub scan_behind_blocks: Option<u64>,
pub use_get_transactions: Option<bool>,
pub to_block_number: Option<u64>,
/// 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<bool>,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down

0 comments on commit 44b4970

Please sign in to comment.