Skip to content

Commit

Permalink
(fix) Force transaction enumeration for zq1 in an attempt to ensure t…
Browse files Browse the repository at this point in the history
…hat we don't accidentally process logs from failed txns
  • Loading branch information
rrw-zilliqa committed Nov 26, 2024
1 parent 0e723d8 commit d1f5586
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
15 changes: 2 additions & 13 deletions bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,9 @@ impl BlockPolling for ChainClient {
.provider()
.request("eth_getLogs", [event])
.await?;
// zq1 will send logs for failed txns; this is avoided here at a higher
// level, by forcing the strategy to be GetTransactions in client.rs
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
38 changes: 31 additions & 7 deletions bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ethers::{
signers::{LocalWallet, Signer},
types::{Address, U256},
};
use serde::{Deserialize, Serialize};
use std::fmt;
use tracing::info;

Expand Down Expand Up @@ -44,6 +45,12 @@ impl fmt::Display for ChainClient {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VersionStruct {
#[serde(rename = "Version")]
pub version: String,
}

impl ChainClient {
pub async fn new(config: &ChainConfig, wallet: LocalWallet) -> Result<Self> {
info!(
Expand All @@ -52,6 +59,10 @@ impl ChainClient {
config.chain_gateway_address
);
let provider = Provider::<Http>::try_from(config.rpc_url.as_str())?;
let maybe_version = provider
.request::<(), VersionStruct>("GetVersion", ())
.await
.ok();
// let provider = Provider::<Ws>::connect(&config.rpc_url).await?;
let chain_id = provider.get_chainid().await?;
let client: Arc<Client> = Arc::new(
Expand All @@ -62,14 +73,27 @@ impl ChainClient {
// TODO: get the validator_manager_address from chain_gateway itself
let chain_gateway = ChainGateway::new(config.chain_gateway_address, client.clone());
let validator_manager_address: Address = chain_gateway.validator_manager().call().await?;
let strategy = match config.use_get_transactions {
None => LogStrategy::GetLogs,
Some(v) => match v {
false => LogStrategy::GetLogs,
true => LogStrategy::GetTransactions,
},
let is_zilliqa1 = if let Some(version) = &maybe_version {
version.version.to_lowercase().starts_with("v9.")
} else {
false
};
let strategy = if is_zilliqa1 {
info!(
" ... this chain looks like zilliqa 1 ; forcing the GetTransactions log strategy"
);
LogStrategy::GetTransactions
} else {
match config.use_get_transactions {
None => LogStrategy::GetLogs,
Some(v) => match v {
false => LogStrategy::GetLogs,
true => LogStrategy::GetTransactions,
},
}
};
info!("... success!");
info!(" ... chain client initialised for chain_id {chain_id}, url {0}, with version {maybe_version:?} and strategy {strategy:?}.",
config.rpc_url.as_str());
Ok(ChainClient {
client,
validator_manager_address,
Expand Down

0 comments on commit d1f5586

Please sign in to comment.