Skip to content

Commit

Permalink
(fix) Ignore failed transactions.
Browse files Browse the repository at this point in the history
(feat) An `end_block` option to limit history replay for special situations
  • Loading branch information
rrw-zilliqa committed Nov 19, 2024
1 parent 1ed7ea4 commit e907983
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
8 changes: 8 additions & 0 deletions bridge-validators/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
[[chain_configs]]
## The block at which history replay should start.
chain_gateway_block_deployed = 36696045

## When replaying history, we replay dispatches first, then relays. In order to do this
## on old blocks in a reasonable time, we should not only start just before the message to be
## replayed, but stop just after. This allows us to stop at a particular block when catching
## up
## to_block_number = 4000000

## RPC URL to talk to for this chain.
rpc_url = "https://bsc-prebsc-dataseed.bnbchain.org"
## The (EVM) address of the chain gateway contract
Expand Down Expand Up @@ -36,6 +43,7 @@ legacy_gas_estimation_percent = 130
## use_get_transactions = true



# BSC Mainnet
# [[chain_configs]]
# chain_gateway_block_deployed = 0
Expand Down
28 changes: 26 additions & 2 deletions bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ethers::{
use ethers_contract::{parse_log, EthEvent};
use futures::{Stream, StreamExt, TryStreamExt};
use tokio::time::interval;
use tracing::{debug, info, warn};
use tracing::{info, warn};

use crate::client::{ChainClient, LogStrategy};

Expand Down Expand Up @@ -50,7 +50,7 @@ impl ChainClient {
// go through all the transactions
for txn_hash in block.transactions {
// We have a transaction. Did it have any logs?
debug!("block {} txn {:#x}", block_number, txn_hash);
info!("block {} txn {:#x}", block_number, txn_hash);
// Get the receipt
let maybe_receipt = self
.client
Expand All @@ -59,6 +59,16 @@ impl ChainClient {
.await?;
if let Some(receipt) = maybe_receipt {
// Yay!
if let Some(v) = &receipt.status {
info!("[1] txn {:#x} has status {v}", txn_hash);
if *v != U64::from(1) {
info!("[1] txn failed - skipping");
continue;
}
} else {
info!("[1] txn {:#x} has no status - ignoring", txn_hash);
continue;
}
info!("Got receipt for txn {:#x}", txn_hash);
for log in receipt.logs {
// Because FML, the filter doesn't actually include the address.
Expand Down Expand Up @@ -101,6 +111,7 @@ impl ChainClient {
// If there's no filter element for this topic, we're fine.
}
if matches {
info!("Event matches; pushing for transit");
result.push(log);
}
}
Expand Down Expand Up @@ -153,6 +164,19 @@ impl BlockPolling for ChainClient {
.request("eth_getLogs", [event])
.await?;
logs.into_iter()
// Zilliqa 1 will generate logs for failed txns.
.filter(|log| {
log.get("status")
.and_then(|v| v.as_i64())
.map_or(false, |s| {
if s != 1 {
info!("txn failed: status = {s:#x}");
false
} else {
true
}
})
})
.filter(|log| {
log.get("address")
.and_then(|val| val.as_str())
Expand Down
11 changes: 8 additions & 3 deletions bridge-validators/src/bridge_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ impl BridgeNode {
}

pub async fn sync_historic_events(&mut self) -> Result<()> {
let to_block = if self.chain_client.block_instant_finality {
BlockNumber::Latest
let to_block = if let Some(v) = self.chain_client.to_block_number {
BlockNumber::Number(v.into())
} else {
BlockNumber::Finalized
if self.chain_client.block_instant_finality {
BlockNumber::Latest
} else {
BlockNumber::Finalized
}
};

info!(
"Getting Historic Events for chainId#{}: {}",
self.chain_client.chain_id, to_block
Expand Down
2 changes: 2 additions & 0 deletions bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ChainClient {
pub legacy_gas_estimation_percent: Option<u64>,
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
}

impl fmt::Display for ChainClient {
Expand Down Expand Up @@ -80,6 +81,7 @@ impl ChainClient {
legacy_gas_estimation_percent: config.legacy_gas_estimation_percent,
scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(),
log_strategy: strategy,
to_block_number: config.to_block_number,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct ChainConfig {
pub legacy_gas_estimation_percent: Option<u64>,
pub scan_behind_blocks: Option<u64>,
pub use_get_transactions: Option<bool>,
pub to_block_number: Option<u64>,
}

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

0 comments on commit e907983

Please sign in to comment.