Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump revm to newest #6357

Merged
merged 27 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ reth-transaction-pool = { path = "crates/transaction-pool" }
reth-trie = { path = "crates/trie" }

# revm
revm = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze", features = [
revm = { git = "https://github.com/bluealloy/revm", branch = "main", features = [
"std",
"secp256k1",
], default-features = false }
revm-primitives = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze", features = [
revm-primitives = { git = "https://github.com/bluealloy/revm", branch = "main", features = [
"std",
], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev="e900523"}
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", branch = "main" }

# eth
alloy-chains = { version = "0.1", feature = ["serde", "rlp", "arbitrary"] }
Expand Down Expand Up @@ -220,7 +220,7 @@ strum = "0.26"
rayon = "1.7"
itertools = "0.12"
parking_lot = "0.12"
metrics = "0.21.1" # Needed for `metrics-macro` to resolve the crate using `::metrics` notation
metrics = "0.21.1" # Needed for `metrics-macro` to resolve the crate using `::metrics` notation
hex-literal = "0.4"
once_cell = "1.17"
syn = "2.0"
Expand Down
17 changes: 14 additions & 3 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ reth-trie.workspace = true
reth-nippy-jar.workspace = true
reth-node-api.workspace = true
reth-node-ethereum.workspace = true
reth-node-optimism = { workspace = true, optional = true, features = ["optimism"] }
reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
] }
reth-node-core.workspace = true

# crypto
alloy-rlp.workspace = true
alloy-chains.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "rand-std", "recovery"] }
secp256k1 = { workspace = true, features = [
"global-context",
"rand-std",
"recovery",
] }
revm-inspectors.workspace = true

# tracing
Expand Down Expand Up @@ -93,7 +99,12 @@ ratatui = "0.25.0"
human_bytes = "0.4.1"

# async
tokio = { workspace = true, features = ["sync", "macros", "time", "rt-multi-thread"] }
tokio = { workspace = true, features = [
"sync",
"macros",
"time",
"rt-multi-thread",
] }
futures.workspace = true
pin-project.workspace = true

Expand Down
25 changes: 12 additions & 13 deletions crates/node-api/src/engine/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{validate_version_specific_fields, AttributesValidationError, EngineApiMessageVersion};
use reth_primitives::{
revm::config::revm_spec_by_timestamp_after_merge,
revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, SpecId},
revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId},
Address, ChainSpec, Header, SealedBlock, Withdrawals, B256, U256,
};
use reth_rpc_types::{
Expand Down Expand Up @@ -74,36 +74,35 @@ pub trait PayloadBuilderAttributes: Send + Sync + std::fmt::Debug {
/// Returns the withdrawals for the running payload job.
fn withdrawals(&self) -> &Withdrawals;

/// Returns the configured [CfgEnv] and [BlockEnv] for the targeted payload (that has the
/// `parent` as its parent).
/// Returns the configured [CfgEnvWithHandlerCfg] and [BlockEnv] for the targeted payload (that
/// has the `parent` as its parent).
///
/// The `chain_spec` is used to determine the correct chain id and hardfork for the payload
/// based on its timestamp.
///
/// Block related settings are derived from the `parent` block and the configured attributes.
///
/// NOTE: This is only intended for beacon consensus (after merge).
fn cfg_and_block_env(&self, chain_spec: &ChainSpec, parent: &Header) -> (CfgEnv, BlockEnv) {
// TODO: should be different once revm has configurable cfgenv
fn cfg_and_block_env(
&self,
chain_spec: &ChainSpec,
parent: &Header,
) -> (CfgEnvWithHandlerCfg, BlockEnv) {
// TODO: should be different once revm has configurable CfgEnvWithHandlerCfg
// configure evm env based on parent block
let mut cfg = CfgEnv::default();
cfg.chain_id = chain_spec.chain().id();

#[cfg(feature = "optimism")]
{
cfg.optimism = chain_spec.is_optimism();
}

// ensure we're not missing any timestamp based hardforks
cfg.spec_id = revm_spec_by_timestamp_after_merge(chain_spec, self.timestamp());
let spec_id = revm_spec_by_timestamp_after_merge(chain_spec, self.timestamp());

// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
// cancun now, we need to set the excess blob gas to the default value
let blob_excess_gas_and_price = parent
.next_block_excess_blob_gas()
.map_or_else(
|| {
if cfg.spec_id == SpecId::CANCUN {
if spec_id == SpecId::CANCUN {
// default excess blob gas is zero
Some(0)
} else {
Expand Down Expand Up @@ -131,7 +130,7 @@ pub trait PayloadBuilderAttributes: Send + Sync + std::fmt::Debug {
blob_excess_gas_and_price,
};

(cfg, block_env)
(CfgEnvWithHandlerCfg::new(cfg, spec_id), block_env)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/node-api/src/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use reth_primitives::{revm::env::fill_block_env, Address, ChainSpec, Header, Transaction, U256};
use revm_primitives::{BlockEnv, CfgEnv, SpecId, TxEnv};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId, TxEnv};

/// This represents the set of methods used to configure the EVM before execution.
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
Expand All @@ -11,9 +11,9 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
where
T: AsRef<Transaction>;

/// Fill [CfgEnv] fields according to the chain spec and given header
/// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header
fn fill_cfg_env(
cfg_env: &mut CfgEnv,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
Expand All @@ -22,14 +22,14 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
/// Convenience function to call both [fill_cfg_env](ConfigureEvmEnv::fill_cfg_env) and
/// [fill_block_env].
fn fill_cfg_and_block_env(
cfg: &mut CfgEnv,
cfg: &mut CfgEnvWithHandlerCfg,
block_env: &mut BlockEnv,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
) {
Self::fill_cfg_env(cfg, chain_spec, header, total_difficulty);
let after_merge = cfg.spec_id >= SpecId::MERGE;
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
fill_block_env(block_env, chain_spec, header, after_merge);
}
}
11 changes: 6 additions & 5 deletions crates/node-ethereum/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reth_node_api::ConfigureEvmEnv;
use reth_primitives::{
revm::{config::revm_spec, env::fill_tx_env},
revm_primitives::{AnalysisKind, CfgEnv, TxEnv},
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
Address, ChainSpec, Head, Header, Transaction, U256,
};

Expand All @@ -21,7 +21,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
}

fn fill_cfg_env(
cfg_env: &mut CfgEnv,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
Expand All @@ -38,20 +38,21 @@ impl ConfigureEvmEnv for EthEvmConfig {
);

cfg_env.chain_id = chain_spec.chain().id();
cfg_env.spec_id = spec_id;
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
}
}

#[cfg(test)]
mod tests {
use super::*;
use reth_primitives::revm_primitives::BlockEnv;
use reth_primitives::revm_primitives::{BlockEnv, CfgEnv, SpecId};

#[test]
#[ignore]
fn test_fill_cfg_and_block_env() {
let mut cfg_env = CfgEnv::default();
let mut cfg_env = CfgEnvWithHandlerCfg::new(CfgEnv::default(), SpecId::LATEST);
let mut block_env = BlockEnv::default();
let header = Header::default();
let chain_spec = ChainSpec::default();
Expand Down
13 changes: 6 additions & 7 deletions crates/node-optimism/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reth_node_api::ConfigureEvmEnv;
use reth_primitives::{
revm::{config::revm_spec, env::fill_op_tx_env},
revm_primitives::{AnalysisKind, CfgEnv, TxEnv},
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
Address, Bytes, ChainSpec, Head, Header, Transaction, U256,
};

Expand All @@ -21,7 +21,7 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
}

fn fill_cfg_env(
cfg_env: &mut CfgEnv,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
Expand All @@ -38,23 +38,22 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
);

cfg_env.chain_id = chain_spec.chain().id();
cfg_env.spec_id = spec_id;
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

// optimism-specific configuration
cfg_env.optimism = chain_spec.is_optimism();
cfg_env.handler_cfg.spec_id = spec_id;
cfg_env.handler_cfg.is_optimism = chain_spec.is_optimism();
}
}

#[cfg(test)]
mod tests {
use super::*;
use reth_primitives::revm_primitives::BlockEnv;
use reth_primitives::revm_primitives::{BlockEnv, CfgEnv, SpecId};

#[test]
#[ignore]
fn test_fill_cfg_and_block_env() {
let mut cfg_env = CfgEnv::default();
let mut cfg_env = CfgEnvWithHandlerCfg::new(CfgEnv::default(), SpecId::LATEST);
let mut block_env = BlockEnv::default();
let header = Header::default();
let chain_spec = ChainSpec::default();
Expand Down
29 changes: 14 additions & 15 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use reth_revm::state_change::{
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
use revm::{
primitives::{BlockEnv, CfgEnv, Env},
Database, DatabaseCommit, State,
primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg},
Database, DatabaseCommit, Evm, State,
};
use std::{
future::Future,
Expand Down Expand Up @@ -633,7 +633,7 @@ pub struct PayloadConfig<Attributes> {
/// Pre-configured block environment.
pub initialized_block_env: BlockEnv,
/// Configuration for the environment.
pub initialized_cfg: CfgEnv,
pub initialized_cfg: CfgEnvWithHandlerCfg,
/// The parent block.
pub parent_block: Arc<SealedBlock>,
/// Block extra data.
Expand Down Expand Up @@ -849,8 +849,8 @@ pub fn commit_withdrawals<DB: Database<Error = ProviderError>>(

/// Apply the [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) pre block contract call.
///
/// This constructs a new [EVM](revm::EVM) with the given DB, and environment ([CfgEnv] and
/// [BlockEnv]) to execute the pre block contract call.
/// This constructs a new [Evm] with the given DB, and environment
/// ([CfgEnvWithHandlerCfg] and [BlockEnv]) to execute the pre block contract call.
///
/// The parent beacon block root used for the call is gathered from the given
/// [PayloadBuilderAttributes].
Expand All @@ -861,24 +861,23 @@ pub fn pre_block_beacon_root_contract_call<DB: Database + DatabaseCommit, Attrib
db: &mut DB,
chain_spec: &ChainSpec,
block_number: u64,
initialized_cfg: &CfgEnv,
initialized_cfg: &CfgEnvWithHandlerCfg,
initialized_block_env: &BlockEnv,
attributes: &Attributes,
) -> Result<(), PayloadBuilderError>
where
DB::Error: std::fmt::Display,
Attributes: PayloadBuilderAttributes,
{
// Configure the environment for the block.
let env = Env {
cfg: initialized_cfg.clone(),
block: initialized_block_env.clone(),
..Default::default()
};

// apply pre-block EIP-4788 contract call
let mut evm_pre_block = revm::EVM::with_env(env);
evm_pre_block.database(db);
let mut evm_pre_block = Evm::builder()
.with_db(db)
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
initialized_cfg.clone(),
initialized_block_env.clone(),
Default::default(),
))
.build();

// initialize a block from the env, because the pre block call needs the block itself
apply_beacon_root_contract_call(
Expand Down
Loading
Loading