feat: separate node-builder crate (#6302)

This commit is contained in:
Dan Cline
2024-01-31 13:03:03 -05:00
committed by GitHub
parent 34cda3a99f
commit 1223895466
45 changed files with 191 additions and 100 deletions

View File

@ -0,0 +1,24 @@
[package]
name = "reth-node-optimism"
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
[features]
optimism = ["reth-node-api/optimism"]

View File

@ -0,0 +1,26 @@
use reth_node_api::{
optimism_validate_version_specific_fields, AttributesValidationError, EngineApiMessageVersion,
EngineTypes, PayloadOrAttributes,
};
use reth_payload_builder::{EthBuiltPayload, OptimismPayloadBuilderAttributes};
use reth_primitives::ChainSpec;
use reth_rpc_types::engine::OptimismPayloadAttributes;
/// The types used in the optimism beacon consensus engine.
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct OptimismEngineTypes;
impl EngineTypes for OptimismEngineTypes {
type PayloadAttributes = OptimismPayloadAttributes;
type PayloadBuilderAttributes = OptimismPayloadBuilderAttributes;
type BuiltPayload = EthBuiltPayload;
fn validate_version_specific_fields(
chain_spec: &ChainSpec,
version: EngineApiMessageVersion,
payload_or_attrs: PayloadOrAttributes<'_, OptimismPayloadAttributes>,
) -> Result<(), AttributesValidationError> {
optimism_validate_version_specific_fields(chain_spec, version, payload_or_attrs)
}
}

View File

@ -0,0 +1,73 @@
use reth_node_api::EvmEnvConfig;
use reth_primitives::{
revm::{config::revm_spec, env::fill_op_tx_env},
revm_primitives::{AnalysisKind, CfgEnv, TxEnv},
Address, Bytes, ChainSpec, Head, Header, Transaction, U256,
};
/// Optimism-related EVM configuration.
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
pub struct OptimismEvmConfig;
impl EvmEnvConfig for OptimismEvmConfig {
type TxMeta = Bytes;
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Bytes)
where
T: AsRef<Transaction>,
{
fill_op_tx_env(tx_env, transaction, sender, meta);
}
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;
// optimism-specific configuration
cfg_env.optimism = chain_spec.is_optimism();
}
}
#[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;
OptimismEvmConfig::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());
}
}

View File

@ -0,0 +1,20 @@
//! Standalone crate for Optimism-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))]
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
/// Exports optimism-specific implementations of the [EngineTypes](reth_node_api::EngineTypes)
/// trait.
pub mod engine;
pub use engine::OptimismEngineTypes;
/// Exports optimism-specific implementations of the [EvmEnvConfig](reth_node_api::EvmEnvConfig)
/// trait.
pub mod evm;
pub use evm::OptimismEvmConfig;