mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: separate node-builder crate (#6302)
This commit is contained in:
21
crates/node-ethereum/Cargo.toml
Normal file
21
crates/node-ethereum/Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "reth-node-ethereum"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
reth-payload-builder.workspace = true
|
||||
reth-rpc-types.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
|
||||
# io
|
||||
serde.workspace = true
|
||||
26
crates/node-ethereum/src/engine.rs
Normal file
26
crates/node-ethereum/src/engine.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use reth_node_api::{
|
||||
validate_version_specific_fields, AttributesValidationError, EngineApiMessageVersion,
|
||||
EngineTypes, PayloadOrAttributes,
|
||||
};
|
||||
use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes};
|
||||
use reth_primitives::ChainSpec;
|
||||
use reth_rpc_types::engine::PayloadAttributes as EthPayloadAttributes;
|
||||
|
||||
/// The types used in the default mainnet ethereum beacon consensus engine.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct EthEngineTypes;
|
||||
|
||||
impl EngineTypes for EthEngineTypes {
|
||||
type PayloadAttributes = EthPayloadAttributes;
|
||||
type PayloadBuilderAttributes = EthPayloadBuilderAttributes;
|
||||
type BuiltPayload = EthBuiltPayload;
|
||||
|
||||
fn validate_version_specific_fields(
|
||||
chain_spec: &ChainSpec,
|
||||
version: EngineApiMessageVersion,
|
||||
payload_or_attrs: PayloadOrAttributes<'_, EthPayloadAttributes>,
|
||||
) -> Result<(), AttributesValidationError> {
|
||||
validate_version_specific_fields(chain_spec, version, payload_or_attrs)
|
||||
}
|
||||
}
|
||||
70
crates/node-ethereum/src/evm.rs
Normal file
70
crates/node-ethereum/src/evm.rs
Normal file
@ -0,0 +1,70 @@
|
||||
use reth_node_api::EvmEnvConfig;
|
||||
use reth_primitives::{
|
||||
revm::{config::revm_spec, env::fill_tx_env},
|
||||
revm_primitives::{AnalysisKind, CfgEnv, TxEnv},
|
||||
Address, ChainSpec, Head, Header, Transaction, U256,
|
||||
};
|
||||
|
||||
/// Ethereum-related EVM configuration.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct EthEvmConfig;
|
||||
|
||||
impl EvmEnvConfig for EthEvmConfig {
|
||||
type TxMeta = ();
|
||||
|
||||
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, _meta: ())
|
||||
where
|
||||
T: AsRef<Transaction>,
|
||||
{
|
||||
fill_tx_env(tx_env, transaction, sender)
|
||||
}
|
||||
|
||||
fn fill_cfg_env(
|
||||
cfg_env: &mut CfgEnv,
|
||||
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.spec_id = spec_id;
|
||||
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use reth_primitives::revm_primitives::BlockEnv;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_fill_cfg_and_block_env() {
|
||||
let mut cfg_env = CfgEnv::default();
|
||||
let mut block_env = BlockEnv::default();
|
||||
let header = Header::default();
|
||||
let chain_spec = ChainSpec::default();
|
||||
let total_difficulty = U256::ZERO;
|
||||
|
||||
EthEvmConfig::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());
|
||||
}
|
||||
}
|
||||
18
crates/node-ethereum/src/lib.rs
Normal file
18
crates/node-ethereum/src/lib.rs
Normal file
@ -0,0 +1,18 @@
|
||||
//! Standalone crate for ethereum-specific Reth configuration and builder types.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
|
||||
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
|
||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||
)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
/// Exports commonly used concrete instances of the [EngineTypes](reth_node_api::EngineTypes)
|
||||
/// trait.
|
||||
pub mod engine;
|
||||
pub use engine::EthEngineTypes;
|
||||
|
||||
/// Exports commonly used concrete instances of the [EvmEnvConfig](reth_node_api::EvmEnvConfig)
|
||||
/// trait.
|
||||
pub mod evm;
|
||||
pub use evm::EthEvmConfig;
|
||||
Reference in New Issue
Block a user