From d1f5586e911950c1b3dd7a5380c1822920437021 Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Tue, 26 Nov 2024 19:16:51 +0000 Subject: [PATCH] (fix) Force transaction enumeration for zq1 in an attempt to ensure that we don't accidentally process logs from failed txns --- bridge-validators/src/block.rs | 15 ++----------- bridge-validators/src/client.rs | 38 +++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/bridge-validators/src/block.rs b/bridge-validators/src/block.rs index c98f710..8fc8d28 100644 --- a/bridge-validators/src/block.rs +++ b/bridge-validators/src/block.rs @@ -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()) diff --git a/bridge-validators/src/client.rs b/bridge-validators/src/client.rs index 8af79d2..f2dc13a 100644 --- a/bridge-validators/src/client.rs +++ b/bridge-validators/src/client.rs @@ -8,6 +8,7 @@ use ethers::{ signers::{LocalWallet, Signer}, types::{Address, U256}, }; +use serde::{Deserialize, Serialize}; use std::fmt; use tracing::info; @@ -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 { info!( @@ -52,6 +59,10 @@ impl ChainClient { config.chain_gateway_address ); let provider = Provider::::try_from(config.rpc_url.as_str())?; + let maybe_version = provider + .request::<(), VersionStruct>("GetVersion", ()) + .await + .ok(); // let provider = Provider::::connect(&config.rpc_url).await?; let chain_id = provider.get_chainid().await?; let client: Arc = Arc::new( @@ -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,