Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Force transaction enumeration for zq1 .. #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading