Skip to content

Commit

Permalink
Merge pull request #325 from PeggyJV/bolten/update-block-delay
Browse files Browse the repository at this point in the history
Update block delay, use chain ID correctly
  • Loading branch information
zmanian authored Jan 14, 2022
2 parents 399ed9d + a066f97 commit e043ac0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions orchestrator/orchestrator/src/ethereum_event_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,8 @@ pub async fn check_for_events(
/// 6 deep reorg every 53,272 years.
///
pub async fn get_block_delay(eth_client: EthClient) -> Result<U64, GravityError> {
// TODO(bolten): technically we want the network id from net_version, but chain id
// should be the same for our use cases...when this PR is in a released version of
// ethers we can move back to net_version:
// https://github.com/gakonst/ethers-rs/pull/595
// 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() {
Expand All @@ -270,13 +268,16 @@ pub async fn get_block_delay(eth_client: EthClient) -> Result<U64, GravityError>
}

match chain_id.unwrap() {
// Mainline Ethereum, Ethereum classic, or the Ropsten, Mordor testnets
// Mainline Ethereum, Ethereum classic, or Ropsten, Mordor testnets
// all POW Chains
1 | 3 | 7 => Ok(6u8.into()),
// Rinkeby, Goerli, Dev, our own Gravity Ethereum testnet, and Kotti respectively
1 | 3 | 61 | 63 => Ok(13u8.into()),
// Dev, our own Gravity Ethereum testnet, Hardhat
// all non-pow chains
4 | 5 | 2018 | 15 | 6 => Ok(0u8.into()),
2018 | 15 | 31337 => Ok(0u8.into()),
// Rinkeby, Goerli, Kotti
// Clique (POA) Consensus
4 | 5 | 6 => Ok(10u8.into()),
// assume the safe option (POW) where we don't know
_ => Ok(6u8.into()),
_ => Ok(13u8.into()),
}
}
4 changes: 2 additions & 2 deletions orchestrator/orchestrator/src/get_with_retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ pub async fn get_last_event_nonce_with_retry(
res.unwrap()
}

/// gets the net version, no matter how long it takes
/// 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;
while res.is_err() {
error!("Failed to get net version! Is your Eth node working?");
error!("Failed to get chain ID! Is your Eth node working?");
delay_for(RETRY_TIME).await;
res = eth_client.get_chainid().await;
}
Expand Down

0 comments on commit e043ac0

Please sign in to comment.