From 112fb17450f8e1b267fb0d38bad011830d92d1b9 Mon Sep 17 00:00:00 2001 From: ZanCorDX <126988525+ZanCorDX@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:05:25 -0300 Subject: [PATCH] Avoid checking illegal blocks. (#230) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📝 Summary There was a bug if the block number was 0 (block_hash got 2^64-1 as a parameter) ## 💡 Motivation and Context Broke devnet tests for Pectra upgrade. --- ## ✅ I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable) --- crates/rbuilder/src/utils/provider_factory_reopen.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/rbuilder/src/utils/provider_factory_reopen.rs b/crates/rbuilder/src/utils/provider_factory_reopen.rs index 32576a88..237cc6a9 100644 --- a/crates/rbuilder/src/utils/provider_factory_reopen.rs +++ b/crates/rbuilder/src/utils/provider_factory_reopen.rs @@ -133,21 +133,18 @@ pub fn check_provider_factory_health( current_block_number: u64, provider_factory: &ProviderFactory, ) -> eyre::Result<()> { - // evm must have access to block hashed of 256 of the previous blocks - for i in 1u64..=256 { + // evm must have access to block hashes of 256 of the previous blocks + let blocks_to_check = current_block_number.min(256); + for i in 1..=blocks_to_check { let num = current_block_number - i; let hash = provider_factory.block_hash(num)?; if hash.is_none() { eyre::bail!( "Missing historical block hash for block {}, current block: {}", - current_block_number - i, + num, current_block_number ); } - - if num == 0 { - break; - } } Ok(())