-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
8,064 additions
and
56 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "node" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
|
||
[dependencies] | ||
reth.workspace = true | ||
reth-node-api.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use reth::{ | ||
primitives::{ | ||
address, | ||
revm::{config::revm_spec, env::fill_op_tx_env}, | ||
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, Env, PrecompileResult, TxEnv}, | ||
Address, Bytes, ChainSpec, Head, Header, Transaction, U256, | ||
}, | ||
revm::{ | ||
handler::register::EvmHandler, | ||
precompile::{Precompile, PrecompileSpecId, Precompiles}, | ||
Database, | ||
}, | ||
}; | ||
use reth_node_api::ConfigureEvmEnv; | ||
use std::sync::Arc; | ||
|
||
/// Custom EVM configuration | ||
#[derive(Debug, Clone, Copy, Default)] | ||
#[non_exhaustive] | ||
pub struct AlphaNetEvmConfig; | ||
|
||
impl AlphaNetEvmConfig { | ||
/// Sets the precompiles to the EVM handler | ||
/// | ||
/// This will be invoked when the EVM is created via [ConfigureEvm::evm] or | ||
/// [ConfigureEvm::evm_with_inspector] | ||
/// | ||
/// This will use the default mainnet precompiles and add additional precompiles. | ||
pub fn set_precompiles<EXT, DB>(handler: &mut EvmHandler<'_, EXT, DB>) | ||
where | ||
DB: Database, | ||
{ | ||
// first we need the evm spec id, which determines the precompiles | ||
let spec_id = handler.cfg.spec_id; | ||
|
||
// install the precompiles | ||
handler.pre_execution.load_precompiles = Arc::new(move || { | ||
let mut precompiles = Precompiles::new(PrecompileSpecId::from_spec_id(spec_id)).clone(); | ||
precompiles.inner.insert( | ||
address!("0000000000000000000000000000000000000999"), | ||
Precompile::Env(Self::my_precompile), | ||
); | ||
precompiles | ||
}); | ||
} | ||
|
||
/// A custom precompile that does nothing | ||
fn my_precompile(_data: &Bytes, _gas: u64, _env: &Env) -> PrecompileResult { | ||
Ok((0, Bytes::new())) | ||
} | ||
} | ||
|
||
impl ConfigureEvmEnv for AlphaNetEvmConfig { | ||
type TxMeta = Bytes; | ||
|
||
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta) | ||
where | ||
T: AsRef<Transaction>, | ||
{ | ||
fill_op_tx_env(tx_env, transaction, sender, meta) | ||
} | ||
|
||
fn fill_cfg_env( | ||
cfg_env: &mut CfgEnvWithHandlerCfg, | ||
chain_spec: &ChainSpec, | ||
header: &Header, | ||
total_difficulty: U256, | ||
) { | ||
let spec_id = revm_spec( | ||
chain_spec, | ||
Head { | ||
number: header.number, | ||
timestamp: header.timestamp, | ||
difficulty: header.difficulty, | ||
total_difficulty, | ||
hash: Default::default(), | ||
}, | ||
); | ||
|
||
cfg_env.chain_id = chain_spec.chain().id(); | ||
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse; | ||
|
||
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, CfgEnv}; | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_fill_cfg_and_block_env() { | ||
let mut cfg_env = CfgEnvWithHandlerCfg::new_with_spec_id(CfgEnv::default(), SpecId::LATEST); | ||
let mut block_env = BlockEnv::default(); | ||
let header = Header::default(); | ||
let chain_spec = ChainSpec::default(); | ||
let total_difficulty = U256::ZERO; | ||
|
||
AlphaNetEvmConfig::fill_cfg_and_block_env( | ||
&mut cfg_env, | ||
&mut block_env, | ||
&chain_spec, | ||
&header, | ||
total_difficulty, | ||
); | ||
|
||
assert_eq!(cfg_env.chain_id, chain_spec.chain().id()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! Standalone crate for Reth configuration and builder types. | ||
|
||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
|
||
/// Implementation of the EngineTypes trait. | ||
pub mod engine; | ||
/// Implementation of the ConfigureEvmEnv trait. | ||
pub mod evm; | ||
/// Node types config. | ||
pub mod node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|