mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 02:49:55 +00:00
chore: Use traits from reth 1.5.0
This commit is contained in:
@ -1,17 +1,15 @@
|
|||||||
use super::HlEvmInner;
|
use super::HlEvmInner;
|
||||||
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
|
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
|
||||||
|
use reth_revm::context::ContextTr;
|
||||||
use revm::{
|
use revm::{
|
||||||
context::{Cfg, JournalOutput},
|
context::Cfg, context_interface::Block, handler::instructions::EthInstructions,
|
||||||
context_interface::{Block, JournalTr},
|
interpreter::interpreter::EthInterpreter, Context, Database,
|
||||||
handler::instructions::EthInstructions,
|
|
||||||
interpreter::interpreter::EthInterpreter,
|
|
||||||
Context, Database,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Trait that allows for hl HlEvm to be built.
|
/// Trait that allows for hl HlEvm to be built.
|
||||||
pub trait HlBuilder: Sized {
|
pub trait HlBuilder: Sized {
|
||||||
/// Type of the context.
|
/// Type of the context.
|
||||||
type Context;
|
type Context: ContextTr;
|
||||||
|
|
||||||
/// Build the hl with an inspector.
|
/// Build the hl with an inspector.
|
||||||
fn build_hl_with_inspector<INSP>(
|
fn build_hl_with_inspector<INSP>(
|
||||||
@ -20,13 +18,12 @@ pub trait HlBuilder: Sized {
|
|||||||
) -> HlEvmInner<Self::Context, INSP, EthInstructions<EthInterpreter, Self::Context>>;
|
) -> HlEvmInner<Self::Context, INSP, EthInstructions<EthInterpreter, Self::Context>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BLOCK, TX, CFG, DB, JOURNAL> HlBuilder for Context<BLOCK, TX, CFG, DB, JOURNAL>
|
impl<BLOCK, TX, CFG, DB> HlBuilder for Context<BLOCK, TX, CFG, DB>
|
||||||
where
|
where
|
||||||
BLOCK: Block,
|
BLOCK: Block,
|
||||||
TX: HlTxTr,
|
TX: HlTxTr,
|
||||||
CFG: Cfg<Spec = HlSpecId>,
|
CFG: Cfg<Spec = HlSpecId>,
|
||||||
DB: Database,
|
DB: Database,
|
||||||
JOURNAL: JournalTr<Database = DB, FinalOutput = JournalOutput>,
|
|
||||||
{
|
{
|
||||||
type Context = Self;
|
type Context = Self;
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,26 @@
|
|||||||
use super::HlEvmInner;
|
use super::HlEvmInner;
|
||||||
use crate::evm::{handler::HlHandler, spec::HlSpecId, transaction::HlTxTr};
|
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
|
||||||
use revm::{
|
use revm::{
|
||||||
context::{ContextSetters, JournalOutput},
|
context::{result::HaltReason, ContextSetters},
|
||||||
context_interface::{
|
context_interface::{
|
||||||
result::{EVMError, ExecutionResult, ResultAndState},
|
result::{EVMError, ExecutionResult, ResultAndState},
|
||||||
Cfg, ContextTr, Database, JournalTr,
|
Cfg, ContextTr, Database, JournalTr,
|
||||||
},
|
},
|
||||||
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
|
handler::{instructions::EthInstructions, PrecompileProvider},
|
||||||
inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt},
|
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
|
||||||
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
||||||
|
state::EvmState,
|
||||||
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
|
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Type alias for HL context
|
// Type alias for HL context
|
||||||
pub trait HlContextTr:
|
pub trait HlContextTr:
|
||||||
ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
|
ContextTr<Journal: JournalTr<State = EvmState>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> HlContextTr for T where
|
impl<T> HlContextTr for T where
|
||||||
T: ContextTr<
|
T: ContextTr<Journal: JournalTr<State = EvmState>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
|
||||||
Journal: JournalTr<FinalOutput = JournalOutput>,
|
|
||||||
Tx: HlTxTr,
|
|
||||||
Cfg: Cfg<Spec = HlSpecId>,
|
|
||||||
>
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,23 +33,32 @@ where
|
|||||||
CTX: HlContextTr + ContextSetters,
|
CTX: HlContextTr + ContextSetters,
|
||||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||||
{
|
{
|
||||||
type Output = Result<ResultAndState, HlError<CTX>>;
|
type ExecutionResult = ExecutionResult<HaltReason>;
|
||||||
|
type State = EvmState;
|
||||||
|
type Error = HlError<CTX>;
|
||||||
|
|
||||||
type Tx = <CTX as ContextTr>::Tx;
|
type Tx = <CTX as ContextTr>::Tx;
|
||||||
|
|
||||||
type Block = <CTX as ContextTr>::Block;
|
type Block = <CTX as ContextTr>::Block;
|
||||||
|
|
||||||
fn set_tx(&mut self, tx: Self::Tx) {
|
#[inline]
|
||||||
self.0.ctx.set_tx(tx);
|
fn transact_one(&mut self, tx: Self::Tx) -> Result<Self::ExecutionResult, Self::Error> {
|
||||||
|
self.0.transact_one(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn finalize(&mut self) -> Self::State {
|
||||||
|
self.0.finalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn set_block(&mut self, block: Self::Block) {
|
fn set_block(&mut self, block: Self::Block) {
|
||||||
self.0.ctx.set_block(block);
|
self.0.set_block(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replay(&mut self) -> Self::Output {
|
#[inline]
|
||||||
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
|
fn replay(&mut self) -> Result<ResultAndState<HaltReason>, Self::Error> {
|
||||||
h.run(self)
|
self.0.replay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,13 +68,8 @@ where
|
|||||||
CTX: HlContextTr<Db: DatabaseCommit> + ContextSetters,
|
CTX: HlContextTr<Db: DatabaseCommit> + ContextSetters,
|
||||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||||
{
|
{
|
||||||
type CommitOutput = Result<ExecutionResult, HlError<CTX>>;
|
fn commit(&mut self, state: Self::State) {
|
||||||
|
self.0.commit(state);
|
||||||
fn replay_commit(&mut self) -> Self::CommitOutput {
|
|
||||||
self.replay().map(|r| {
|
|
||||||
self.ctx().db().commit(r.state);
|
|
||||||
r.result
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,12 +83,11 @@ where
|
|||||||
type Inspector = INSP;
|
type Inspector = INSP;
|
||||||
|
|
||||||
fn set_inspector(&mut self, inspector: Self::Inspector) {
|
fn set_inspector(&mut self, inspector: Self::Inspector) {
|
||||||
self.0.inspector = inspector;
|
self.0.set_inspector(inspector);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inspect_replay(&mut self) -> Self::Output {
|
fn inspect_one_tx(&mut self, tx: Self::Tx) -> Result<Self::ExecutionResult, Self::Error> {
|
||||||
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
|
self.0.inspect_one_tx(tx)
|
||||||
h.inspect_run(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
use revm::{
|
use revm::{
|
||||||
context::{ContextSetters, Evm as EvmCtx},
|
context::{ContextSetters, Evm, FrameStack},
|
||||||
context_interface::ContextTr,
|
context_interface::ContextTr,
|
||||||
handler::{
|
handler::{
|
||||||
|
evm::{ContextDbError, FrameInitResult},
|
||||||
instructions::{EthInstructions, InstructionProvider},
|
instructions::{EthInstructions, InstructionProvider},
|
||||||
EthPrecompiles, EvmTr, PrecompileProvider,
|
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, PrecompileProvider,
|
||||||
},
|
},
|
||||||
inspector::{InspectorEvmTr, JournalExt},
|
inspector::{InspectorEvmTr, JournalExt},
|
||||||
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterAction, InterpreterTypes},
|
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
||||||
Inspector,
|
Inspector,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -14,19 +15,23 @@ pub mod builder;
|
|||||||
pub mod ctx;
|
pub mod ctx;
|
||||||
mod exec;
|
mod exec;
|
||||||
|
|
||||||
pub struct HlEvmInner<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = EthPrecompiles>(
|
pub struct HlEvmInner<
|
||||||
pub EvmCtx<CTX, INSP, I, P>,
|
CTX: ContextTr,
|
||||||
);
|
INSP,
|
||||||
|
I = EthInstructions<EthInterpreter, CTX>,
|
||||||
|
P = EthPrecompiles,
|
||||||
|
>(pub Evm<CTX, INSP, I, P, EthFrame<EthInterpreter>>);
|
||||||
|
|
||||||
impl<CTX: ContextTr, INSP>
|
impl<CTX: ContextTr, INSP>
|
||||||
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>
|
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>
|
||||||
{
|
{
|
||||||
pub fn new(ctx: CTX, inspector: INSP) -> Self {
|
pub fn new(ctx: CTX, inspector: INSP) -> Self {
|
||||||
Self(EvmCtx {
|
Self(Evm {
|
||||||
ctx,
|
ctx,
|
||||||
inspector,
|
inspector,
|
||||||
instruction: EthInstructions::new_mainnet(),
|
instruction: EthInstructions::new_mainnet(),
|
||||||
precompiles: EthPrecompiles::default(),
|
precompiles: EthPrecompiles::default(),
|
||||||
|
frame_stack: FrameStack::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +47,9 @@ impl<CTX: ContextTr, INSP>
|
|||||||
impl<CTX, INSP, I, P> InspectorEvmTr for HlEvmInner<CTX, INSP, I, P>
|
impl<CTX, INSP, I, P> InspectorEvmTr for HlEvmInner<CTX, INSP, I, P>
|
||||||
where
|
where
|
||||||
CTX: ContextTr<Journal: JournalExt> + ContextSetters,
|
CTX: ContextTr<Journal: JournalExt> + ContextSetters,
|
||||||
I: InstructionProvider<
|
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
|
||||||
Context = CTX,
|
|
||||||
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
|
|
||||||
>,
|
|
||||||
INSP: Inspector<CTX, I::InterpreterTypes>,
|
INSP: Inspector<CTX, I::InterpreterTypes>,
|
||||||
P: PrecompileProvider<CTX>,
|
P: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||||
{
|
{
|
||||||
type Inspector = INSP;
|
type Inspector = INSP;
|
||||||
|
|
||||||
@ -59,41 +61,29 @@ where
|
|||||||
(&mut self.0.ctx, &mut self.0.inspector)
|
(&mut self.0.ctx, &mut self.0.inspector)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_inspect_interpreter(
|
fn ctx_inspector_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
interpreter: &mut Interpreter<
|
) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame) {
|
||||||
<Self::Instructions as InstructionProvider>::InterpreterTypes,
|
(&mut self.0.ctx, &mut self.0.inspector, self.0.frame_stack.get())
|
||||||
>,
|
}
|
||||||
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
|
|
||||||
{
|
fn ctx_inspector_frame_instructions(
|
||||||
self.0.run_inspect_interpreter(interpreter)
|
&mut self,
|
||||||
|
) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame, &mut Self::Instructions) {
|
||||||
|
(&mut self.0.ctx, &mut self.0.inspector, self.0.frame_stack.get(), &mut self.0.instruction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX, INSP, I, P> EvmTr for HlEvmInner<CTX, INSP, I, P>
|
impl<CTX, INSP, I, P> EvmTr for HlEvmInner<CTX, INSP, I, P>
|
||||||
where
|
where
|
||||||
CTX: ContextTr,
|
CTX: ContextTr,
|
||||||
I: InstructionProvider<
|
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
|
||||||
Context = CTX,
|
P: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||||
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
|
|
||||||
>,
|
|
||||||
P: PrecompileProvider<CTX>,
|
|
||||||
{
|
{
|
||||||
type Context = CTX;
|
type Context = CTX;
|
||||||
type Instructions = I;
|
type Instructions = I;
|
||||||
type Precompiles = P;
|
type Precompiles = P;
|
||||||
|
type Frame = EthFrame<EthInterpreter>;
|
||||||
fn run_interpreter(
|
|
||||||
&mut self,
|
|
||||||
interpreter: &mut Interpreter<
|
|
||||||
<Self::Instructions as InstructionProvider>::InterpreterTypes,
|
|
||||||
>,
|
|
||||||
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
|
|
||||||
{
|
|
||||||
let context = &mut self.0.ctx;
|
|
||||||
let instructions = &mut self.0.instruction;
|
|
||||||
interpreter.run_plain(instructions.instruction_table(), context)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ctx(&mut self) -> &mut Self::Context {
|
fn ctx(&mut self) -> &mut Self::Context {
|
||||||
&mut self.0.ctx
|
&mut self.0.ctx
|
||||||
@ -110,6 +100,30 @@ where
|
|||||||
fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
|
fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
|
||||||
(&mut self.0.ctx, &mut self.0.precompiles)
|
(&mut self.0.ctx, &mut self.0.precompiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn frame_stack(&mut self) -> &mut FrameStack<Self::Frame> {
|
||||||
|
&mut self.0.frame_stack
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame_init(
|
||||||
|
&mut self,
|
||||||
|
frame_input: <Self::Frame as FrameTr>::FrameInit,
|
||||||
|
) -> Result<FrameInitResult<'_, Self::Frame>, ContextDbError<Self::Context>> {
|
||||||
|
self.0.frame_init(frame_input)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame_run(
|
||||||
|
&mut self,
|
||||||
|
) -> Result<FrameInitOrResult<Self::Frame>, ContextDbError<Self::Context>> {
|
||||||
|
self.0.frame_run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame_return_result(
|
||||||
|
&mut self,
|
||||||
|
result: <Self::Frame as FrameTr>::FrameResult,
|
||||||
|
) -> Result<Option<<Self::Frame as FrameTr>::FrameResult>, ContextDbError<Self::Context>> {
|
||||||
|
self.0.frame_return_result(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
|
|||||||
@ -135,7 +135,9 @@ impl<ChainSpec: EthChainSpec + HlHardforks> Consensus<HlBlock> for HlConsensus<C
|
|||||||
|
|
||||||
mod reth_copy;
|
mod reth_copy;
|
||||||
|
|
||||||
impl<ChainSpec: EthChainSpec + HlHardforks> FullConsensus<HlPrimitives> for HlConsensus<ChainSpec> {
|
impl<ChainSpec: EthChainSpec<Header = alloy_consensus::Header> + HlHardforks>
|
||||||
|
FullConsensus<HlPrimitives> for HlConsensus<ChainSpec>
|
||||||
|
{
|
||||||
fn validate_block_post_execution(
|
fn validate_block_post_execution(
|
||||||
&self,
|
&self,
|
||||||
block: &RecoveredBlock<HlBlock>,
|
block: &RecoveredBlock<HlBlock>,
|
||||||
|
|||||||
@ -14,7 +14,6 @@ use alloy_consensus::{BlockHeader, Header, Transaction as _, TxReceipt, EMPTY_OM
|
|||||||
use alloy_eips::merge::BEACON_NONCE;
|
use alloy_eips::merge::BEACON_NONCE;
|
||||||
use alloy_primitives::{Log, U256};
|
use alloy_primitives::{Log, U256};
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
|
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
|
||||||
use reth_ethereum_forks::EthereumHardfork;
|
|
||||||
use reth_evm::{
|
use reth_evm::{
|
||||||
block::{BlockExecutionError, BlockExecutorFactory, BlockExecutorFor},
|
block::{BlockExecutionError, BlockExecutorFactory, BlockExecutorFor},
|
||||||
eth::{receipt_builder::ReceiptBuilder, EthBlockExecutionCtx},
|
eth::{receipt_builder::ReceiptBuilder, EthBlockExecutionCtx},
|
||||||
@ -67,7 +66,7 @@ where
|
|||||||
..
|
..
|
||||||
} = input;
|
} = input;
|
||||||
|
|
||||||
let timestamp = evm_env.block_env.timestamp;
|
let timestamp = evm_env.block_env.timestamp.saturating_to();
|
||||||
|
|
||||||
// Filter out system tx receipts
|
// Filter out system tx receipts
|
||||||
let transactions_for_root: Vec<TransactionSigned> =
|
let transactions_for_root: Vec<TransactionSigned> =
|
||||||
@ -122,7 +121,7 @@ where
|
|||||||
mix_hash: evm_env.block_env.prevrandao.unwrap_or_default(),
|
mix_hash: evm_env.block_env.prevrandao.unwrap_or_default(),
|
||||||
nonce: BEACON_NONCE.into(),
|
nonce: BEACON_NONCE.into(),
|
||||||
base_fee_per_gas: Some(evm_env.block_env.basefee),
|
base_fee_per_gas: Some(evm_env.block_env.basefee),
|
||||||
number: evm_env.block_env.number,
|
number: evm_env.block_env.number.saturating_to(),
|
||||||
gas_limit: evm_env.block_env.gas_limit,
|
gas_limit: evm_env.block_env.gas_limit,
|
||||||
difficulty: evm_env.block_env.difficulty,
|
difficulty: evm_env.block_env.difficulty,
|
||||||
gas_used: *gas_used,
|
gas_used: *gas_used,
|
||||||
@ -264,8 +263,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const EIP1559_INITIAL_BASE_FEE: u64 = 0;
|
|
||||||
|
|
||||||
impl ConfigureEvm for HlEvmConfig
|
impl ConfigureEvm for HlEvmConfig
|
||||||
where
|
where
|
||||||
Self: Send + Sync + Unpin + Clone + 'static,
|
Self: Send + Sync + Unpin + Clone + 'static,
|
||||||
@ -297,7 +294,7 @@ where
|
|||||||
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec);
|
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec);
|
||||||
|
|
||||||
if let Some(blob_params) = &blob_params {
|
if let Some(blob_params) = &blob_params {
|
||||||
cfg_env.set_blob_max_count(blob_params.max_blob_count);
|
cfg_env.set_max_blobs_per_tx(blob_params.max_blobs_per_tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: enable only for system transactions
|
// TODO: enable only for system transactions
|
||||||
@ -315,9 +312,9 @@ where
|
|||||||
let eth_spec = spec.into_eth_spec();
|
let eth_spec = spec.into_eth_spec();
|
||||||
|
|
||||||
let block_env = BlockEnv {
|
let block_env = BlockEnv {
|
||||||
number: header.number(),
|
number: U256::from(header.number()),
|
||||||
beneficiary: header.beneficiary(),
|
beneficiary: header.beneficiary(),
|
||||||
timestamp: header.timestamp(),
|
timestamp: U256::from(header.timestamp()),
|
||||||
difficulty: if eth_spec >= SpecId::MERGE { U256::ZERO } else { header.difficulty() },
|
difficulty: if eth_spec >= SpecId::MERGE { U256::ZERO } else { header.difficulty() },
|
||||||
prevrandao: if eth_spec >= SpecId::MERGE { header.mix_hash() } else { None },
|
prevrandao: if eth_spec >= SpecId::MERGE { header.mix_hash() } else { None },
|
||||||
gas_limit: header.gas_limit(),
|
gas_limit: header.gas_limit(),
|
||||||
@ -346,43 +343,19 @@ where
|
|||||||
|
|
||||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
// 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(0)
|
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||||
let blob_excess_gas_and_price = parent
|
let blob_excess_gas_and_price = spec_id
|
||||||
.maybe_next_block_excess_blob_gas(
|
.into_eth_spec()
|
||||||
self.chain_spec().blob_params_at_timestamp(attributes.timestamp),
|
.is_enabled_in(SpecId::CANCUN)
|
||||||
)
|
.then_some(BlobExcessGasAndPrice { excess_blob_gas: 0, blob_gasprice: 0 });
|
||||||
.or_else(|| (spec_id.into_eth_spec().is_enabled_in(SpecId::CANCUN)).then_some(0))
|
|
||||||
.map(|gas| BlobExcessGasAndPrice::new(gas, false));
|
|
||||||
|
|
||||||
let mut basefee = parent.next_block_base_fee(
|
let basefee = parent.next_block_base_fee(
|
||||||
self.chain_spec().base_fee_params_at_timestamp(attributes.timestamp),
|
self.chain_spec().base_fee_params_at_timestamp(attributes.timestamp),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut gas_limit = U256::from(parent.gas_limit);
|
|
||||||
|
|
||||||
// If we are on the London fork boundary, we need to multiply the parent's gas limit by the
|
|
||||||
// elasticity multiplier to get the new gas limit.
|
|
||||||
if self
|
|
||||||
.chain_spec()
|
|
||||||
.inner
|
|
||||||
.fork(EthereumHardfork::London)
|
|
||||||
.transitions_at_block(parent.number + 1)
|
|
||||||
{
|
|
||||||
let elasticity_multiplier = self
|
|
||||||
.chain_spec()
|
|
||||||
.base_fee_params_at_timestamp(attributes.timestamp)
|
|
||||||
.elasticity_multiplier;
|
|
||||||
|
|
||||||
// multiply the gas limit by the elasticity multiplier
|
|
||||||
gas_limit *= U256::from(elasticity_multiplier);
|
|
||||||
|
|
||||||
// set the base fee to the initial base fee from the EIP-1559 spec
|
|
||||||
basefee = Some(EIP1559_INITIAL_BASE_FEE)
|
|
||||||
}
|
|
||||||
|
|
||||||
let block_env = BlockEnv {
|
let block_env = BlockEnv {
|
||||||
number: parent.number() + 1,
|
number: U256::from(parent.number() + 1),
|
||||||
beneficiary: attributes.suggested_fee_recipient,
|
beneficiary: attributes.suggested_fee_recipient,
|
||||||
timestamp: attributes.timestamp,
|
timestamp: U256::from(attributes.timestamp),
|
||||||
difficulty: U256::ZERO,
|
difficulty: U256::ZERO,
|
||||||
prevrandao: Some(attributes.prev_randao),
|
prevrandao: Some(attributes.prev_randao),
|
||||||
gas_limit: attributes.gas_limit,
|
gas_limit: attributes.gas_limit,
|
||||||
|
|||||||
@ -16,8 +16,8 @@ use reth_evm::{
|
|||||||
block::{BlockValidationError, CommitChanges},
|
block::{BlockValidationError, CommitChanges},
|
||||||
eth::receipt_builder::ReceiptBuilder,
|
eth::receipt_builder::ReceiptBuilder,
|
||||||
execute::{BlockExecutionError, BlockExecutor},
|
execute::{BlockExecutionError, BlockExecutor},
|
||||||
precompiles::{DynPrecompile, PrecompilesMap},
|
precompiles::{DynPrecompile, PrecompileInput, PrecompilesMap},
|
||||||
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook, RecoveredTx,
|
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook,
|
||||||
};
|
};
|
||||||
use reth_provider::BlockExecutionResult;
|
use reth_provider::BlockExecutionResult;
|
||||||
use reth_revm::State;
|
use reth_revm::State;
|
||||||
@ -227,8 +227,8 @@ where
|
|||||||
for (address, precompile) in ctx.read_precompile_calls.iter() {
|
for (address, precompile) in ctx.read_precompile_calls.iter() {
|
||||||
let precompile = precompile.clone();
|
let precompile = precompile.clone();
|
||||||
precompiles_mut.apply_precompile(address, |_| {
|
precompiles_mut.apply_precompile(address, |_| {
|
||||||
Some(DynPrecompile::from(move |data: &[u8], gas: u64| {
|
Some(DynPrecompile::from(move |input: PrecompileInput| -> PrecompileResult {
|
||||||
run_precompile(&precompile, data, gas)
|
run_precompile(&precompile, input.data, input.gas)
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@ use crate::evm::{
|
|||||||
spec::HlSpecId,
|
spec::HlSpecId,
|
||||||
transaction::HlTxEnv,
|
transaction::HlTxEnv,
|
||||||
};
|
};
|
||||||
use reth_evm::{precompiles::PrecompilesMap, EvmEnv, EvmFactory};
|
use reth_evm::{precompiles::PrecompilesMap, Database, EvmEnv, EvmFactory};
|
||||||
use reth_revm::{Context, Database};
|
use reth_revm::Context;
|
||||||
use revm::{
|
use revm::{
|
||||||
context::{
|
context::{
|
||||||
result::{EVMError, HaltReason},
|
result::{EVMError, HaltReason},
|
||||||
@ -25,16 +25,15 @@ use revm::{
|
|||||||
pub struct HlEvmFactory;
|
pub struct HlEvmFactory;
|
||||||
|
|
||||||
impl EvmFactory for HlEvmFactory {
|
impl EvmFactory for HlEvmFactory {
|
||||||
type Evm<DB: Database<Error: Send + Sync + 'static>, I: Inspector<HlContext<DB>>> =
|
type Evm<DB: Database, I: Inspector<HlContext<DB>>> = HlEvm<DB, I, Self::Precompiles>;
|
||||||
HlEvm<DB, I, Self::Precompiles>;
|
type Context<DB: Database> = HlContext<DB>;
|
||||||
type Context<DB: Database<Error: Send + Sync + 'static>> = HlContext<DB>;
|
|
||||||
type Tx = HlTxEnv<TxEnv>;
|
type Tx = HlTxEnv<TxEnv>;
|
||||||
type Error<DBError: core::error::Error + Send + Sync + 'static> = EVMError<DBError>;
|
type Error<DBError: core::error::Error + Send + Sync + 'static> = EVMError<DBError>;
|
||||||
type HaltReason = HaltReason;
|
type HaltReason = HaltReason;
|
||||||
type Spec = HlSpecId;
|
type Spec = HlSpecId;
|
||||||
type Precompiles = PrecompilesMap;
|
type Precompiles = PrecompilesMap;
|
||||||
|
|
||||||
fn create_evm<DB: Database<Error: Send + Sync + 'static>>(
|
fn create_evm<DB: Database>(
|
||||||
&self,
|
&self,
|
||||||
db: DB,
|
db: DB,
|
||||||
input: EvmEnv<HlSpecId>,
|
input: EvmEnv<HlSpecId>,
|
||||||
|
|||||||
@ -97,8 +97,7 @@ where
|
|||||||
tx: Self::Tx,
|
tx: Self::Tx,
|
||||||
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
|
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
|
||||||
if self.inspect {
|
if self.inspect {
|
||||||
self.inner.set_tx(tx);
|
self.inner.inspect_tx(tx)
|
||||||
self.inner.inspect_replay()
|
|
||||||
} else {
|
} else {
|
||||||
self.inner.transact(tx)
|
self.inner.transact(tx)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ use crate::{
|
|||||||
node::{
|
node::{
|
||||||
primitives::TransactionSigned,
|
primitives::TransactionSigned,
|
||||||
rpc::{HlEthApi, HlNodeCore},
|
rpc::{HlEthApi, HlNodeCore},
|
||||||
HlBlock, HlPrimitives,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use alloy_consensus::{BlockHeader, ReceiptEnvelope, TxType};
|
use alloy_consensus::{BlockHeader, ReceiptEnvelope, TxType};
|
||||||
@ -16,8 +15,7 @@ use reth::{
|
|||||||
rpc::{
|
rpc::{
|
||||||
eth::EthApiTypes,
|
eth::EthApiTypes,
|
||||||
server_types::eth::{
|
server_types::eth::{
|
||||||
error::FromEvmError, receipt::build_receipt, EthApiError, EthReceiptBuilder,
|
error::FromEvmError, receipt::build_receipt, EthApiError, PendingBlock,
|
||||||
PendingBlock,
|
|
||||||
},
|
},
|
||||||
types::{BlockId, TransactionReceipt},
|
types::{BlockId, TransactionReceipt},
|
||||||
},
|
},
|
||||||
@ -25,7 +23,8 @@ use reth::{
|
|||||||
};
|
};
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||||
use reth_evm::{ConfigureEvm, NextBlockEnvAttributes};
|
use reth_evm::{ConfigureEvm, NextBlockEnvAttributes};
|
||||||
use reth_primitives_traits::BlockBody as _;
|
use reth_primitives::NodePrimitives;
|
||||||
|
use reth_primitives_traits::{BlockBody as _, SignedTransaction as _};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
BlockReader, ChainSpecProvider, HeaderProvider, ProviderBlock, ProviderReceipt, ProviderTx,
|
BlockReader, ChainSpecProvider, HeaderProvider, ProviderBlock, ProviderReceipt, ProviderTx,
|
||||||
StateProviderFactory,
|
StateProviderFactory,
|
||||||
@ -33,7 +32,7 @@ use reth_provider::{
|
|||||||
use reth_rpc_eth_api::{
|
use reth_rpc_eth_api::{
|
||||||
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
|
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
|
||||||
types::RpcTypes,
|
types::RpcTypes,
|
||||||
FromEthApiError, RpcNodeCore, RpcNodeCoreExt, RpcReceipt,
|
FromEthApiError, RpcConvert, RpcNodeCore, RpcNodeCoreExt, RpcReceipt,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<N> EthBlocks for HlEthApi<N>
|
impl<N> EthBlocks for HlEthApi<N>
|
||||||
@ -68,7 +67,7 @@ where
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, (tx, receipt))| {
|
.map(|(idx, (tx, receipt))| {
|
||||||
let meta = TransactionMeta {
|
let meta = TransactionMeta {
|
||||||
tx_hash: *tx.0.tx_hash(),
|
tx_hash: *tx.tx_hash(),
|
||||||
index: idx as u64,
|
index: idx as u64,
|
||||||
block_hash,
|
block_hash,
|
||||||
block_number,
|
block_number,
|
||||||
@ -76,8 +75,15 @@ where
|
|||||||
excess_blob_gas,
|
excess_blob_gas,
|
||||||
timestamp,
|
timestamp,
|
||||||
};
|
};
|
||||||
EthReceiptBuilder::new(&tx.0, meta, receipt, &receipts, blob_params)
|
build_receipt(tx, meta, receipt, &receipts, blob_params, |receipt_with_bloom| {
|
||||||
.map(|builder| builder.build())
|
match receipt.tx_type {
|
||||||
|
TxType::Legacy => ReceiptEnvelope::Legacy(receipt_with_bloom),
|
||||||
|
TxType::Eip2930 => ReceiptEnvelope::Eip2930(receipt_with_bloom),
|
||||||
|
TxType::Eip1559 => ReceiptEnvelope::Eip1559(receipt_with_bloom),
|
||||||
|
TxType::Eip4844 => ReceiptEnvelope::Eip4844(receipt_with_bloom),
|
||||||
|
TxType::Eip7702 => ReceiptEnvelope::Eip7702(receipt_with_bloom),
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, Self::Error>>()
|
.collect::<Result<Vec<_>, Self::Error>>()
|
||||||
.map(Some);
|
.map(Some);
|
||||||
@ -108,17 +114,23 @@ where
|
|||||||
Header = alloy_rpc_types_eth::Header<ProviderHeader<Self::Provider>>,
|
Header = alloy_rpc_types_eth::Header<ProviderHeader<Self::Provider>>,
|
||||||
>,
|
>,
|
||||||
Error: FromEvmError<Self::Evm>,
|
Error: FromEvmError<Self::Evm>,
|
||||||
|
RpcConvert: RpcConvert<Network = Self::NetworkTypes>,
|
||||||
>,
|
>,
|
||||||
N: RpcNodeCore<
|
N: RpcNodeCore<
|
||||||
Provider: BlockReaderIdExt<
|
Provider: BlockReaderIdExt
|
||||||
Transaction = TransactionSigned,
|
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
||||||
Block = HlBlock,
|
|
||||||
Receipt = Receipt,
|
|
||||||
Header = alloy_consensus::Header,
|
|
||||||
> + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
|
||||||
+ StateProviderFactory,
|
+ StateProviderFactory,
|
||||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = ProviderTx<N::Provider>>>,
|
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = ProviderTx<N::Provider>>>,
|
||||||
Evm: ConfigureEvm<Primitives = HlPrimitives, NextBlockEnvCtx = NextBlockEnvAttributes>,
|
Evm: ConfigureEvm<
|
||||||
|
Primitives = <Self as RpcNodeCore>::Primitives,
|
||||||
|
NextBlockEnvCtx: From<NextBlockEnvAttributes>,
|
||||||
|
>,
|
||||||
|
Primitives: NodePrimitives<
|
||||||
|
BlockHeader = ProviderHeader<Self::Provider>,
|
||||||
|
SignedTx = ProviderTx<Self::Provider>,
|
||||||
|
Receipt = ProviderReceipt<Self::Provider>,
|
||||||
|
Block = ProviderBlock<Self::Provider>,
|
||||||
|
>,
|
||||||
>,
|
>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -141,7 +153,8 @@ where
|
|||||||
gas_limit: parent.gas_limit(),
|
gas_limit: parent.gas_limit(),
|
||||||
parent_beacon_block_root: parent.parent_beacon_block_root(),
|
parent_beacon_block_root: parent.parent_beacon_block_root(),
|
||||||
withdrawals: None,
|
withdrawals: None,
|
||||||
})
|
}
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user