diff --git a/orchestrator/orchestrator/src/ethereum_event_watcher.rs b/orchestrator/orchestrator/src/ethereum_event_watcher.rs index 8c189fcae..430aa50db 100644 --- a/orchestrator/orchestrator/src/ethereum_event_watcher.rs +++ b/orchestrator/orchestrator/src/ethereum_event_watcher.rs @@ -35,6 +35,7 @@ pub async fn check_for_events( gravity_contract_address: EthAddress, cosmos_key: CosmosPrivateKey, starting_block: U64, + blocks_to_search: U64, block_delay: U64, msg_sender: tokio::sync::mpsc::Sender>, ) -> Result { @@ -43,6 +44,11 @@ pub async fn check_for_events( let latest_block = get_block_number_with_retry(eth_client.clone()).await; let latest_block = latest_block - block_delay; + let mut ending_block = starting_block + blocks_to_search; + if ending_block > latest_block { + ending_block = latest_block; + } + metrics::set_ethereum_check_for_events_starting_block(starting_block.as_u64()); metrics::set_ethereum_check_for_events_end_block(latest_block.as_u64()); @@ -64,7 +70,7 @@ pub async fn check_for_events( .address(filter_gravity_contract_address.clone()) .event(&ValsetUpdatedEventFilter::abi_signature()); - let search_range = starting_block..latest_block; + let search_range = starting_block..ending_block; // select uses an inclusive version of the range erc20_deployed_filter = erc20_deployed_filter.select(search_range.clone()); @@ -233,9 +239,10 @@ pub async fn check_for_events( } } - Ok(latest_block) + Ok(ending_block) } + /// The number of blocks behind the 'latest block' on Ethereum our event checking should be. /// Ethereum does not have finality and as such is subject to chain reorgs and temporary forks /// if we check for events up to the very latest block we may process an event which did not diff --git a/orchestrator/orchestrator/src/main_loop.rs b/orchestrator/orchestrator/src/main_loop.rs index f61c7e398..a3fae0dbb 100644 --- a/orchestrator/orchestrator/src/main_loop.rs +++ b/orchestrator/orchestrator/src/main_loop.rs @@ -211,6 +211,7 @@ pub async fn eth_oracle_main_loop( gravity_contract_address, cosmos_key, last_checked_block, + blocks_to_search.into(), block_delay, msg_sender.clone(), )