Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
malik672 committed Oct 14, 2024
1 parent 648f383 commit b24d837
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
23 changes: 8 additions & 15 deletions crates/node/benches/revm_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_primitives:: U256;
use reth_chainspec::{ ChainSpec, EthereumHardfork, ForkCondition, Head};
use reth_optimism_forks::OptimismHardfork;
use reth_revm::primitives::SpecId;
use std::{cmp::Ordering, time::Duration};
use std::time::Duration;


fn revm_spec_one(chain_spec: &ChainSpec, block: &Head) -> SpecId {
Expand Down Expand Up @@ -87,26 +87,19 @@ fn revm_spec_two(chain_spec: &ChainSpec, block: &Head) -> SpecId {
(Hardfork::Ethereum(EthereumHardfork::Frontier), SpecId::FRONTIER),
];

let hardforks = HARDFORKS.iter().rev();

let mut left = 0;
let mut right = HARDFORKS.len() - 1;

while left <= right {
let mid = left + (right - left) / 2;
let (ref fork, spec_id) = HARDFORKS[mid];

for (fork, spec_id) in hardforks {
let is_active = match fork {
Hardfork::Ethereum(f) => chain_spec.fork(*f).active_at_head(block),
Hardfork::Optimism(f) => chain_spec.fork(*f).active_at_head(block),
Hardfork::Ethereum(f) => chain_spec.is_fork_active_at_block(f, block.number),
Hardfork::Optimism(f) => chain_spec.is_fork_active_at_block(f, block.number),
};

match is_active.cmp(&true) {
Ordering::Equal => return spec_id,
Ordering::Greater => right = mid - 1,
Ordering::Less => left = mid + 1,
if is_active {
return *spec_id;
}
}

panic!(
"invalid hardfork chainspec: expected at least one hardfork, got {:?}",
chain_spec.hardforks
Expand Down
24 changes: 9 additions & 15 deletions crates/node/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use reth_revm::{
},
ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector,
};
use std::{cmp::Ordering, sync::Arc};
use std:: sync::Arc;

/// Custom EVM configuration
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -266,7 +266,7 @@ fn revm_spec(chain_spec: &ChainSpec, block: &Head) -> SpecId {
Optimism(OptimismHardfork),
}

const HARDFORKS: &[(Hardfork, SpecId)] = &[
static HARDFORKS: [(Hardfork, SpecId); 20] = [
(Hardfork::Ethereum(EthereumHardfork::Prague), SpecId::PRAGUE_EOF),
(Hardfork::Optimism(OptimismHardfork::Granite), SpecId::GRANITE),
(Hardfork::Optimism(OptimismHardfork::Fjord), SpecId::FJORD),
Expand All @@ -289,25 +289,19 @@ fn revm_spec(chain_spec: &ChainSpec, block: &Head) -> SpecId {
(Hardfork::Ethereum(EthereumHardfork::Frontier), SpecId::FRONTIER),
];

let mut left = 0;
let mut right = HARDFORKS.len() - 1;

while left <= right {
let mid = left + (right - left) / 2;
let (ref fork, spec_id) = HARDFORKS[mid];
let hardforks = HARDFORKS.iter().rev();

for (fork, spec_id) in hardforks {
let is_active = match fork {
Hardfork::Ethereum(f) => chain_spec.fork(*f).active_at_head(block),
Hardfork::Optimism(f) => chain_spec.fork(*f).active_at_head(block),
Hardfork::Ethereum(f) => chain_spec.is_fork_active_at_block(f, block.number),
Hardfork::Optimism(f) => chain_spec.is_fork_active_at_block(f, block.number),
};

match is_active.cmp(&true) {
Ordering::Equal => return spec_id,
Ordering::Greater => right = mid - 1,
Ordering::Less => left = mid + 1,
if is_active {
return *spec_id;
}
}

panic!(
"invalid hardfork chainspec: expected at least one hardfork, got {:?}",
chain_spec.hardforks
Expand Down

0 comments on commit b24d837

Please sign in to comment.