-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor: Tx process and Validation #8
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
Changes from all commits
20114b1
e9b201a
0a20f25
9df6fdd
d370e69
97a56ba
9f93938
0bcbbaf
2a0bffb
e7442fc
f03f1ef
a5319ab
185347a
68fdb50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| use crate::{ | ||
| MorphBlockAssembler, MorphBlockExecutionCtx, MorphEvmConfig, MorphEvmError, | ||
| MorphNextBlockEnvAttributes, | ||
| }; | ||
| use alloy_consensus::BlockHeader; | ||
| use morph_chainspec::hardfork::MorphHardforks; | ||
| use morph_primitives::Block; | ||
| use morph_primitives::{MorphHeader, MorphPrimitives}; | ||
| use morph_revm::MorphBlockEnv; | ||
| use reth_chainspec::EthChainSpec; | ||
| use reth_evm::{ | ||
| ConfigureEvm, EvmEnv, EvmEnvFor, | ||
| eth::{EthBlockExecutionCtx, NextEvmEnvAttributes}, | ||
| }; | ||
| use reth_primitives_traits::{SealedBlock, SealedHeader}; | ||
| use std::borrow::Cow; | ||
|
|
||
| impl ConfigureEvm for MorphEvmConfig { | ||
| type Primitives = MorphPrimitives; | ||
| type Error = MorphEvmError; | ||
| type NextBlockEnvCtx = MorphNextBlockEnvAttributes; | ||
| type BlockExecutorFactory = Self; | ||
| type BlockAssembler = MorphBlockAssembler; | ||
|
|
||
| fn block_executor_factory(&self) -> &Self::BlockExecutorFactory { | ||
| self | ||
| } | ||
|
|
||
| fn block_assembler(&self) -> &Self::BlockAssembler { | ||
| &self.block_assembler | ||
| } | ||
|
|
||
| fn evm_env(&self, header: &MorphHeader) -> Result<EvmEnvFor<Self>, Self::Error> { | ||
| let EvmEnv { cfg_env, block_env } = EvmEnv::for_eth_block( | ||
| header, | ||
| self.chain_spec(), | ||
| self.chain_spec().chain().id(), | ||
| self.chain_spec() | ||
| .blob_params_at_timestamp(header.timestamp()), | ||
| ); | ||
|
|
||
| let spec = self.chain_spec().morph_hardfork_at(header.timestamp()); | ||
|
|
||
| Ok(EvmEnv { | ||
| cfg_env: cfg_env.with_spec(spec), | ||
| block_env: MorphBlockEnv { inner: block_env }, | ||
| }) | ||
| } | ||
|
|
||
| fn next_evm_env( | ||
| &self, | ||
| parent: &MorphHeader, | ||
| attributes: &Self::NextBlockEnvCtx, | ||
| ) -> Result<EvmEnvFor<Self>, Self::Error> { | ||
| let EvmEnv { cfg_env, block_env } = EvmEnv::for_eth_next_block( | ||
| parent, | ||
| NextEvmEnvAttributes { | ||
| timestamp: attributes.timestamp, | ||
| suggested_fee_recipient: attributes.suggested_fee_recipient, | ||
| prev_randao: attributes.prev_randao, | ||
| gas_limit: attributes.gas_limit, | ||
| }, | ||
| self.chain_spec() | ||
| .next_block_base_fee(parent, attributes.timestamp) | ||
| .unwrap_or_default(), | ||
| self.chain_spec(), | ||
| self.chain_spec().chain().id(), | ||
| self.chain_spec() | ||
| .blob_params_at_timestamp(attributes.timestamp), | ||
| ); | ||
|
|
||
| let spec = self.chain_spec().morph_hardfork_at(attributes.timestamp); | ||
|
|
||
| Ok(EvmEnv { | ||
| cfg_env: cfg_env.with_spec(spec), | ||
| block_env: MorphBlockEnv { inner: block_env }, | ||
| }) | ||
| } | ||
|
|
||
| fn context_for_block<'a>( | ||
| &self, | ||
| block: &'a SealedBlock<Block>, | ||
| ) -> Result<MorphBlockExecutionCtx<'a>, Self::Error> { | ||
| Ok(MorphBlockExecutionCtx { | ||
| inner: EthBlockExecutionCtx { | ||
| parent_hash: block.header().parent_hash(), | ||
| parent_beacon_block_root: block.header().parent_beacon_block_root(), | ||
| ommers: &[], | ||
| withdrawals: block.body().withdrawals.as_ref().map(Cow::Borrowed), | ||
| extra_data: block.extra_data().clone(), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| fn context_for_next_block( | ||
| &self, | ||
| parent: &SealedHeader<MorphHeader>, | ||
| attributes: Self::NextBlockEnvCtx, | ||
| ) -> Result<MorphBlockExecutionCtx<'_>, Self::Error> { | ||
| Ok(MorphBlockExecutionCtx { | ||
| inner: EthBlockExecutionCtx { | ||
| parent_hash: parent.hash(), | ||
| parent_beacon_block_root: attributes.parent_beacon_block_root, | ||
| ommers: &[], | ||
| withdrawals: attributes.inner.withdrawals.map(Cow::Owned), | ||
| extra_data: attributes.inner.extra_data, | ||
| }, | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,10 @@ | |
| #![cfg_attr(docsrs, feature(doc_cfg))] | ||
|
|
||
| mod assemble; | ||
| #[cfg(feature = "reth-codec")] | ||
| mod config; | ||
|
Comment on lines
6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix 🤖 Prompt for AI Agents |
||
| #[cfg(feature = "engine")] | ||
| mod engine; | ||
| use alloy_consensus::BlockHeader as _; | ||
| pub use assemble::MorphBlockAssembler; | ||
| mod block; | ||
| mod context; | ||
|
|
@@ -15,22 +16,17 @@ pub use context::{MorphBlockExecutionCtx, MorphNextBlockEnvAttributes}; | |
| mod error; | ||
| pub use error::MorphEvmError; | ||
| pub mod evm; | ||
| use std::{borrow::Cow, sync::Arc}; | ||
| use std::sync::Arc; | ||
|
|
||
| use crate::{block::MorphBlockExecutor, evm::MorphEvm}; | ||
| use alloy_evm::{ | ||
| self, Database, EvmEnv, | ||
| self, Database, | ||
| block::{BlockExecutorFactory, BlockExecutorFor}, | ||
| eth::{EthBlockExecutionCtx, NextEvmEnvAttributes}, | ||
| revm::{Inspector, database::State}, | ||
| }; | ||
| pub use evm::MorphEvmFactory; | ||
| use morph_primitives::{Block, MorphHeader, MorphPrimitives, MorphReceipt, MorphTxEnvelope}; | ||
| use reth_chainspec::EthChainSpec; | ||
| use reth_evm::{self, ConfigureEvm, EvmEnvFor}; | ||
| use reth_primitives_traits::{SealedBlock, SealedHeader}; | ||
|
|
||
| use crate::{block::MorphBlockExecutor, evm::MorphEvm}; | ||
| use morph_chainspec::{MorphChainSpec, hardfork::MorphHardforks}; | ||
| use morph_chainspec::MorphChainSpec; | ||
| use morph_primitives::{MorphReceipt, MorphTxEnvelope}; | ||
| use morph_revm::evm::MorphContext; | ||
| use reth_evm_ethereum::EthEvmConfig; | ||
|
|
||
|
|
@@ -95,100 +91,7 @@ impl BlockExecutorFactory for MorphEvmConfig { | |
| } | ||
| } | ||
|
|
||
| impl ConfigureEvm for MorphEvmConfig { | ||
| type Primitives = MorphPrimitives; | ||
| type Error = MorphEvmError; | ||
| type NextBlockEnvCtx = MorphNextBlockEnvAttributes; | ||
| type BlockExecutorFactory = Self; | ||
| type BlockAssembler = MorphBlockAssembler; | ||
|
|
||
| fn block_executor_factory(&self) -> &Self::BlockExecutorFactory { | ||
| self | ||
| } | ||
|
|
||
| fn block_assembler(&self) -> &Self::BlockAssembler { | ||
| &self.block_assembler | ||
| } | ||
|
|
||
| fn evm_env(&self, header: &MorphHeader) -> Result<EvmEnvFor<Self>, Self::Error> { | ||
| let EvmEnv { cfg_env, block_env } = EvmEnv::for_eth_block( | ||
| header, | ||
| self.chain_spec(), | ||
| self.chain_spec().chain().id(), | ||
| self.chain_spec() | ||
| .blob_params_at_timestamp(header.timestamp()), | ||
| ); | ||
|
|
||
| let spec = self.chain_spec().morph_hardfork_at(header.timestamp()); | ||
|
|
||
| Ok(EvmEnv { | ||
| cfg_env: cfg_env.with_spec(spec), | ||
| block_env: MorphBlockEnv { inner: block_env }, | ||
| }) | ||
| } | ||
|
|
||
| fn next_evm_env( | ||
| &self, | ||
| parent: &MorphHeader, | ||
| attributes: &Self::NextBlockEnvCtx, | ||
| ) -> Result<EvmEnvFor<Self>, Self::Error> { | ||
| let EvmEnv { cfg_env, block_env } = EvmEnv::for_eth_next_block( | ||
| parent, | ||
| NextEvmEnvAttributes { | ||
| timestamp: attributes.timestamp, | ||
| suggested_fee_recipient: attributes.suggested_fee_recipient, | ||
| prev_randao: attributes.prev_randao, | ||
| gas_limit: attributes.gas_limit, | ||
| }, | ||
| self.chain_spec() | ||
| .next_block_base_fee(parent, attributes.timestamp) | ||
| .unwrap_or_default(), | ||
| self.chain_spec(), | ||
| self.chain_spec().chain().id(), | ||
| self.chain_spec() | ||
| .blob_params_at_timestamp(attributes.timestamp), | ||
| ); | ||
|
|
||
| let spec = self.chain_spec().morph_hardfork_at(attributes.timestamp); | ||
|
|
||
| Ok(EvmEnv { | ||
| cfg_env: cfg_env.with_spec(spec), | ||
| block_env: MorphBlockEnv { inner: block_env }, | ||
| }) | ||
| } | ||
|
|
||
| fn context_for_block<'a>( | ||
| &self, | ||
| block: &'a SealedBlock<Block>, | ||
| ) -> Result<MorphBlockExecutionCtx<'a>, Self::Error> { | ||
| Ok(MorphBlockExecutionCtx { | ||
| inner: EthBlockExecutionCtx { | ||
| parent_hash: block.header().parent_hash(), | ||
| parent_beacon_block_root: block.header().parent_beacon_block_root(), | ||
| ommers: &[], | ||
| withdrawals: block.body().withdrawals.as_ref().map(Cow::Borrowed), | ||
| extra_data: block.extra_data().clone(), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| fn context_for_next_block( | ||
| &self, | ||
| parent: &SealedHeader<MorphHeader>, | ||
| attributes: Self::NextBlockEnvCtx, | ||
| ) -> Result<MorphBlockExecutionCtx<'_>, Self::Error> { | ||
| Ok(MorphBlockExecutionCtx { | ||
| inner: EthBlockExecutionCtx { | ||
| parent_hash: parent.hash(), | ||
| parent_beacon_block_root: attributes.parent_beacon_block_root, | ||
| ommers: &[], | ||
| withdrawals: attributes.inner.withdrawals.map(Cow::Owned), | ||
| extra_data: attributes.inner.extra_data, | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "reth-codec")] | ||
| #[cfg(test)] | ||
|
Comment on lines
+94
to
95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check the test code structure at lines 94-153
head -160 crates/evm/src/lib.rs | tail -70Repository: morph-l2/morph-reth Length of output: 2417 🏁 Script executed: # Check if MorphEvmConfig is feature-gated in its definition
rg -n "struct MorphEvmConfig" --type rust -B 2 -A 5Repository: morph-l2/morph-reth Length of output: 509 🏁 Script executed: # Search for from_genesis method in the codebase
rg -n "fn from_genesis" --type rust -B 1 -A 3 | head -40Repository: morph-l2/morph-reth Length of output: 462 🏁 Script executed: # Check the chainspec crate Cargo.toml for feature definitions
find . -path "*/chainspec/Cargo.toml" -exec cat {} \;Repository: morph-l2/morph-reth Length of output: 855 🏁 Script executed: # Check what features are required/optional in the evm crate
head -30 crates/evm/Cargo.tomlRepository: morph-l2/morph-reth Length of output: 793 🏁 Script executed: # Get the complete evm Cargo.toml
cat crates/evm/Cargo.tomlRepository: morph-l2/morph-reth Length of output: 1052 🏁 Script executed: # Search for all usages of reth-codec feature gate in the codebase
rg '#\[cfg\(feature = "reth-codec"\)' --type rustRepository: morph-l2/morph-reth Length of output: 381 🏁 Script executed: # Check if reth-codec is defined in workspace Cargo.toml
cat Cargo.toml | grep -A 50 "\[features\]" | head -60Repository: morph-l2/morph-reth Length of output: 45 🏁 Script executed: # Check what morph-primitives/reth-codec feature gates
rg '#\[cfg\(feature = "reth-codec"\)' --type rust crates/primitives/ -B 2 -A 3Repository: morph-l2/morph-reth Length of output: 1264 🏁 Script executed: # Check if any of the test's dependencies are feature-gated on reth-codec
rg 'MorphChainSpec|MorphEvmConfig' --type rust crates/primitives/ | head -20Repository: morph-l2/morph-reth Length of output: 45 🏁 Script executed: # Check both occurrences of reth-codec feature gate in evm/lib.rs
rg '#\[cfg\(feature = "reth-codec"\)' crates/evm/src/lib.rs -B 2 -A 10Repository: morph-l2/morph-reth Length of output: 712 🏁 Script executed: # Find MorphEvmFactory definition to understand test dependencies
rg 'MorphEvmFactory|new_with_default_factory' --type rust -B 2 -A 5 | head -50Repository: morph-l2/morph-reth Length of output: 2699 🏁 Script executed: # Check if MorphEvmConfig::new_with_default_factory uses any feature-gated types
ast-grep --pattern 'fn new_with_default_factory($_) { $$$ }'Repository: morph-l2/morph-reth Length of output: 45 🏁 Script executed: # Check the config module which is feature-gated on reth-codec
cat crates/evm/src/config.rsRepository: morph-l2/morph-reth Length of output: 3841 🏁 Script executed: # Check the full evm lib.rs module structure to understand dependencies
head -50 crates/evm/src/lib.rsRepository: morph-l2/morph-reth Length of output: 1501 Remove the The test does not use any functionality that depends on the 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the feature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Task: Remove reth-codec feature gate from test module
💡 For code changes across multiple files, use |
||
| mod tests { | ||
| use super::*; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the Cargo.toml file for crates/evm to see dependencies and features cat -n crates/evm/Cargo.tomlRepository: morph-l2/morph-reth
Length of output: 1346
🏁 Script executed:
Repository: morph-l2/morph-reth
Length of output: 87
🏁 Script executed:
Repository: morph-l2/morph-reth
Length of output: 641
🏁 Script executed:
# Now examine config.rs to check for cfg attributes and imports cat -n crates/evm/src/config.rsRepository: morph-l2/morph-reth
Length of output: 4611
🏁 Script executed:
# Check lib.rs to see if config.rs is exposed and how cat -n crates/evm/src/lib.rsRepository: morph-l2/morph-reth
Length of output: 5989
reth-codecfeature doesn't enable required optional dependenciesconfig.rsis gated by#[cfg(feature = "reth-codec")]and importsreth-chainspec,reth-primitives-traits, andalloy-consensus, which are optional dependencies. The feature must enable them, or builds withreth-codecwill fail.💡 Proposed fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anylots cc, you should check the compilation with all features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.