From 912c4990d7c2b8e50fc7ca0144ece1211a74a4fb Mon Sep 17 00:00:00 2001 From: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:17:46 +0900 Subject: [PATCH] Problem: chainid is used instead of networkid (#182) --- .../orchestrator/src/ethereum_event_watcher.rs | 16 +++++++--------- orchestrator/orchestrator/src/get_with_retry.rs | 6 +++--- orchestrator/orchestrator/src/main_loop.rs | 2 ++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/orchestrator/orchestrator/src/ethereum_event_watcher.rs b/orchestrator/orchestrator/src/ethereum_event_watcher.rs index fe681b5ab..197877b2e 100644 --- a/orchestrator/orchestrator/src/ethereum_event_watcher.rs +++ b/orchestrator/orchestrator/src/ethereum_event_watcher.rs @@ -2,7 +2,7 @@ //! or a transaction batch update. It then responds to these events by performing actions on the Cosmos chain if required use crate::get_with_retry::get_block_number_with_retry; -use crate::get_with_retry::get_chain_id_with_retry; +use crate::get_with_retry::get_network_id_with_retry; use crate::metrics; use cosmos_gravity::build; use cosmos_gravity::crypto::CosmosSigner; @@ -274,18 +274,16 @@ pub async fn check_for_events( /// /// pub async fn get_block_delay(eth_client: EthClient) -> Result { - // TODO(bolten): get_net_version() exists on the version of ethers we are currently - // depending on, but it's broken, so we're relying on chain ID - let chain_id_result = get_chain_id_with_retry(eth_client.clone()).await; - let chain_id = downcast_to_u64(chain_id_result); - if chain_id.is_none() { + let network_id_string = get_network_id_with_retry(eth_client.clone()).await; + let network_id = network_id_string.parse::(); + if network_id.is_err() { return Err(GravityError::EthereumBadDataError(format!( - "Chain ID is larger than u64 max: {}", - chain_id_result + "Chain ID is not valid {}", + network_id.err().unwrap() ))); } - match chain_id.unwrap() { + match network_id.unwrap() { // Mainline Ethereum, Ethereum classic, or the Ropsten, Kotti, Mordor testnets // all Ethereum proof of stake Chains 1 | 3 | 6 | 7 => Ok(96u8.into()), diff --git a/orchestrator/orchestrator/src/get_with_retry.rs b/orchestrator/orchestrator/src/get_with_retry.rs index eb52f4cad..638d74c16 100644 --- a/orchestrator/orchestrator/src/get_with_retry.rs +++ b/orchestrator/orchestrator/src/get_with_retry.rs @@ -39,12 +39,12 @@ pub async fn get_last_event_nonce_with_retry( } /// gets the chain ID, no matter how long it takes -pub async fn get_chain_id_with_retry(eth_client: EthClient) -> U256 { - let mut res = eth_client.get_chainid().await; +pub async fn get_network_id_with_retry(eth_client: EthClient) -> String { + let mut res = eth_client.get_net_version().await; while res.is_err() { error!("Failed to get chain ID! Is your Eth node working?"); delay_for(RETRY_TIME).await; - res = eth_client.get_chainid().await; + res = eth_client.get_net_version().await; } res.unwrap() } diff --git a/orchestrator/orchestrator/src/main_loop.rs b/orchestrator/orchestrator/src/main_loop.rs index 5590a17b0..a0fdd27af 100644 --- a/orchestrator/orchestrator/src/main_loop.rs +++ b/orchestrator/orchestrator/src/main_loop.rs @@ -160,6 +160,8 @@ pub async fn eth_oracle_main_loop( exit(1); } }; + + info!("Using block delay {:?}", block_delay); let mut last_checked_block = get_last_checked_block( grpc_client.clone(), our_cosmos_address,