Merge pull request #1 from sprites0/upgrade/1.5.0

chore: Upgrade to reth 1.5.0
This commit is contained in:
sprites0
2025-07-03 09:27:55 -04:00
committed by GitHub
20 changed files with 1161 additions and 1402 deletions

1489
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,61 +12,61 @@ name = "reth-hl"
path = "src/main.rs"
[dependencies]
reth = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-cli = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-cli-commands = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-basic-payload-builder = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-db = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-db-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-chainspec = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-cli-util = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-discv4 = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-engine-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-ethereum-forks = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-ethereum-payload-builder = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-ethereum-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-eth-wire = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-eth-wire-types = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-evm = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-evm-ethereum = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-node-core = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-revm = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-network = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-network-p2p = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-network-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-node-ethereum = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-network-peers = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-optimism-rpc = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-payload-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-primitives-traits = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-provider = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4", features = ["test-utils"] }
reth-rpc-eth-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-rpc-engine-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-tracing = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-trie-common = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-trie-db = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-codecs = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
reth-transaction-pool = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
revm = { version = "24.0.1" }
reth = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-cli = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-cli-commands = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-basic-payload-builder = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-db = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-db-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-chainspec = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-cli-util = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-discv4 = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-engine-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-ethereum-forks = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-ethereum-payload-builder = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-ethereum-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-eth-wire = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-eth-wire-types = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-evm = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-evm-ethereum = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-node-core = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-revm = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-network = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-network-p2p = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-network-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-node-ethereum = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-network-peers = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-optimism-rpc = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-payload-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-primitives-traits = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-provider = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc", features = ["test-utils"] }
reth-rpc-eth-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-rpc-engine-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-tracing = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-trie-common = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-trie-db = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-codecs = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
reth-transaction-pool = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
revm = { version = "26.0.1" }
# alloy dependencies
alloy-genesis = "1.0.9"
alloy-consensus = { version = "1.0.9", features = ["serde"] }
alloy-genesis = "1.0.13"
alloy-consensus = { version = "1.0.13", features = ["serde"] }
alloy-chains = "0.2.0"
alloy-eips = "1.0.9"
alloy-evm = "0.10"
alloy-eips = "1.0.13"
alloy-evm = "0.12"
alloy-json-abi = { version = "1.0.0", default-features = false }
alloy-dyn-abi = "1.1.0"
alloy-network = "1.0.9"
alloy-primitives = { version = "1.1.0", default-features = false, features = ["map-foldhash"] }
alloy-dyn-abi = "1.2.0"
alloy-network = "1.0.13"
alloy-primitives = { version = "1.2.0", default-features = false, features = ["map-foldhash"] }
alloy-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] }
alloy-rpc-types = { version = "1.0.9", features = ["engine"] }
alloy-rpc-types-eth = "1.0.9"
alloy-rpc-types-engine = "1.0.9"
alloy-signer = "1.0.9"
alloy-sol-macro = "1.1.0"
alloy-sol-types = { version = "1.1.0", default-features = false }
alloy-rpc-types = { version = "1.0.13", features = ["engine"] }
alloy-rpc-types-eth = "1.0.13"
alloy-rpc-types-engine = "1.0.13"
alloy-signer = "1.0.13"
alloy-sol-macro = "1.2.0"
alloy-sol-types = { version = "1.2.0", default-features = false }
jsonrpsee = "0.25.1"
jsonrpsee-core = { version = "0.25.1" }
@ -76,9 +76,9 @@ jsonrpsee-types = "0.25.1"
auto_impl = "1"
async-trait = "0.1"
bytes = "1.5"
clap = { version = "4.4", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
cfg-if = { version = "1.0", default-features = false }
derive_more = "0.99"
derive_more = { version = "2", default-features = false, features = ["full"] }
eyre = "0.6"
futures = "0.3"
lazy_static = "1.4.0"
@ -86,16 +86,16 @@ once_cell = { version = "1.19", default-features = false, features = ["alloc"] }
parking_lot = "0.12"
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.36", features = ["full"] }
thiserror = { version = "2.0.0", default-features = false }
tokio = { version = "1.44.2", features = ["full"] }
tokio-stream = "0.1"
tracing = "0.1"
rmp-serde = "1.0.0"
lz4_flex = "0.11.3"
rmp-serde = "1.3"
lz4_flex = "0.11"
ureq = "3.0.12"
aws-sdk-s3 = "1.93.0"
aws-config = "1.8.0"
rayon = "1.10.0"
rayon = "1.7"
time = "0.3.41"

View File

@ -1,17 +1,15 @@
use super::HlEvmInner;
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use reth_revm::context::ContextTr;
use revm::{
context::{Cfg, JournalOutput},
context_interface::{Block, JournalTr},
handler::instructions::EthInstructions,
interpreter::interpreter::EthInterpreter,
Context, Database,
context::Cfg, context_interface::Block, handler::instructions::EthInstructions,
interpreter::interpreter::EthInterpreter, Context, Database,
};
/// Trait that allows for hl HlEvm to be built.
pub trait HlBuilder: Sized {
/// Type of the context.
type Context;
type Context: ContextTr;
/// Build the hl with an inspector.
fn build_hl_with_inspector<INSP>(
@ -20,13 +18,12 @@ pub trait HlBuilder: Sized {
) -> 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
BLOCK: Block,
TX: HlTxTr,
CFG: Cfg<Spec = HlSpecId>,
DB: Database,
JOURNAL: JournalTr<Database = DB, FinalOutput = JournalOutput>,
{
type Context = Self;

View File

@ -1,29 +1,26 @@
use super::HlEvmInner;
use crate::evm::{handler::HlHandler, spec::HlSpecId, transaction::HlTxTr};
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use revm::{
context::{ContextSetters, JournalOutput},
context::{result::HaltReason, ContextSetters},
context_interface::{
result::{EVMError, ExecutionResult, ResultAndState},
Cfg, ContextTr, Database, JournalTr,
},
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt},
handler::{instructions::EthInstructions, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
state::EvmState,
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
};
// Type alias for HL context
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
T: ContextTr<
Journal: JournalTr<FinalOutput = JournalOutput>,
Tx: HlTxTr,
Cfg: Cfg<Spec = HlSpecId>,
>
T: ContextTr<Journal: JournalTr<State = EvmState>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
{
}
@ -36,23 +33,32 @@ where
CTX: HlContextTr + ContextSetters,
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 Block = <CTX as ContextTr>::Block;
fn set_tx(&mut self, tx: Self::Tx) {
self.0.ctx.set_tx(tx);
#[inline]
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) {
self.0.ctx.set_block(block);
self.0.set_block(block);
}
fn replay(&mut self) -> Self::Output {
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
h.run(self)
#[inline]
fn replay(&mut self) -> Result<ResultAndState<HaltReason>, Self::Error> {
self.0.replay()
}
}
@ -62,13 +68,8 @@ where
CTX: HlContextTr<Db: DatabaseCommit> + ContextSetters,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type CommitOutput = Result<ExecutionResult, HlError<CTX>>;
fn replay_commit(&mut self) -> Self::CommitOutput {
self.replay().map(|r| {
self.ctx().db().commit(r.state);
r.result
})
fn commit(&mut self, state: Self::State) {
self.0.commit(state);
}
}
@ -82,12 +83,11 @@ where
type Inspector = INSP;
fn set_inspector(&mut self, inspector: Self::Inspector) {
self.0.inspector = inspector;
self.0.set_inspector(inspector);
}
fn inspect_replay(&mut self) -> Self::Output {
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
h.inspect_run(self)
fn inspect_one_tx(&mut self, tx: Self::Tx) -> Result<Self::ExecutionResult, Self::Error> {
self.0.inspect_one_tx(tx)
}
}
@ -98,10 +98,4 @@ where
INSP: Inspector<CTX, EthInterpreter>,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
fn inspect_replay_commit(&mut self) -> Self::CommitOutput {
self.inspect_replay().map(|r| {
self.ctx().db().commit(r.state);
r.result
})
}
}

View File

@ -1,12 +1,13 @@
use revm::{
context::{ContextSetters, Evm as EvmCtx},
context::{ContextSetters, Evm, FrameStack},
context_interface::ContextTr,
handler::{
evm::{ContextDbError, FrameInitResult},
instructions::{EthInstructions, InstructionProvider},
EthPrecompiles, EvmTr, PrecompileProvider,
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, PrecompileProvider,
},
inspector::{InspectorEvmTr, JournalExt},
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterAction, InterpreterTypes},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
Inspector,
};
@ -14,19 +15,23 @@ pub mod builder;
pub mod ctx;
mod exec;
pub struct HlEvmInner<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = EthPrecompiles>(
pub EvmCtx<CTX, INSP, I, P>,
);
pub struct HlEvmInner<
CTX: ContextTr,
INSP,
I = EthInstructions<EthInterpreter, CTX>,
P = EthPrecompiles,
>(pub Evm<CTX, INSP, I, P, EthFrame<EthInterpreter>>);
impl<CTX: ContextTr, INSP>
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>
{
pub fn new(ctx: CTX, inspector: INSP) -> Self {
Self(EvmCtx {
Self(Evm {
ctx,
inspector,
instruction: EthInstructions::new_mainnet(),
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>
where
CTX: ContextTr<Journal: JournalExt> + ContextSetters,
I: InstructionProvider<
Context = CTX,
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
>,
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
INSP: Inspector<CTX, I::InterpreterTypes>,
P: PrecompileProvider<CTX>,
P: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type Inspector = INSP;
@ -59,41 +61,29 @@ where
(&mut self.0.ctx, &mut self.0.inspector)
}
fn run_inspect_interpreter(
fn ctx_inspector_frame(
&mut self,
interpreter: &mut Interpreter<
<Self::Instructions as InstructionProvider>::InterpreterTypes,
>,
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
{
self.0.run_inspect_interpreter(interpreter)
) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame) {
(&mut self.0.ctx, &mut self.0.inspector, self.0.frame_stack.get())
}
fn ctx_inspector_frame_instructions(
&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>
where
CTX: ContextTr,
I: InstructionProvider<
Context = CTX,
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
>,
P: PrecompileProvider<CTX>,
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
P: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type Context = CTX;
type Instructions = I;
type Precompiles = P;
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)
}
type Frame = EthFrame<EthInterpreter>;
fn ctx(&mut self) -> &mut Self::Context {
&mut self.0.ctx
@ -110,6 +100,30 @@ where
fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::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)]

View File

@ -1,122 +1 @@
//! EVM Handler related to Hl chain
use super::{spec::HlSpecId, transaction::HlTxTr};
use revm::{
context::{
result::{ExecutionResult, HaltReason},
Cfg, ContextTr, JournalOutput, LocalContextTr,
},
context_interface::{result::ResultAndState, JournalTr},
handler::{handler::EvmTrError, EvmTr, Frame, FrameResult, Handler, MainnetHandler},
inspector::{Inspector, InspectorEvmTr, InspectorFrame, InspectorHandler},
interpreter::{interpreter::EthInterpreter, FrameInput, SuccessOrHalt},
};
pub struct HlHandler<EVM, ERROR, FRAME> {
pub mainnet: MainnetHandler<EVM, ERROR, FRAME>,
}
impl<EVM, ERROR, FRAME> HlHandler<EVM, ERROR, FRAME> {
pub fn new() -> Self {
Self { mainnet: MainnetHandler::default() }
}
}
impl<EVM, ERROR, FRAME> Default for HlHandler<EVM, ERROR, FRAME> {
fn default() -> Self {
Self::new()
}
}
pub trait HlContextTr:
ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
{
}
impl<T> HlContextTr for T where
T: ContextTr<
Journal: JournalTr<FinalOutput = JournalOutput>,
Tx: HlTxTr,
Cfg: Cfg<Spec = HlSpecId>,
>
{
}
impl<EVM, ERROR, FRAME> Handler for HlHandler<EVM, ERROR, FRAME>
where
EVM: EvmTr<Context: HlContextTr>,
ERROR: EvmTrError<EVM>,
FRAME: Frame<Evm = EVM, Error = ERROR, FrameResult = FrameResult, FrameInit = FrameInput>,
{
type Evm = EVM;
type Error = ERROR;
type Frame = FRAME;
type HaltReason = HaltReason;
fn validate_initial_tx_gas(
&self,
evm: &Self::Evm,
) -> Result<revm::interpreter::InitialAndFloorGas, Self::Error> {
self.mainnet.validate_initial_tx_gas(evm)
}
fn output(
&self,
evm: &mut Self::Evm,
result: <Self::Frame as Frame>::FrameResult,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
let ctx = evm.ctx();
ctx.error();
// used gas with refund calculated.
let gas_refunded = result.gas().refunded() as u64;
let final_gas_used = result.gas().spent() - gas_refunded;
let output = result.output();
let instruction_result = result.into_interpreter_result();
// Reset journal and return present state.
let JournalOutput { state, logs } = evm.ctx().journal().finalize();
let result = match SuccessOrHalt::from(instruction_result.result) {
SuccessOrHalt::Success(reason) => ExecutionResult::Success {
reason,
gas_used: final_gas_used,
gas_refunded,
logs,
output,
},
SuccessOrHalt::Revert => {
ExecutionResult::Revert { gas_used: final_gas_used, output: output.into_data() }
}
SuccessOrHalt::Halt(reason) => {
ExecutionResult::Halt { reason, gas_used: final_gas_used }
}
// Only two internal return flags.
flag @ (SuccessOrHalt::FatalExternalError | SuccessOrHalt::Internal(_)) => {
panic!(
"Encountered unexpected internal return flag: {flag:?} with instruction result: {instruction_result:?}"
)
}
};
// Clear local context
evm.ctx().local().clear();
// Clear journal
evm.ctx().journal().clear();
Ok(ResultAndState { result, state })
}
}
impl<EVM, ERROR, FRAME> InspectorHandler for HlHandler<EVM, ERROR, FRAME>
where
EVM: InspectorEvmTr<
Context: HlContextTr,
Inspector: Inspector<<<Self as Handler>::Evm as EvmTr>::Context, EthInterpreter>,
>,
ERROR: EvmTrError<EVM>,
FRAME: Frame<Evm = EVM, Error = ERROR, FrameResult = FrameResult, FrameInit = FrameInput>
+ InspectorFrame<IT = EthInterpreter>,
{
type IT = EthInterpreter;
}

View File

@ -130,7 +130,7 @@ impl FromRecoveredTx<TransactionSigned> for HlTxEnv<TxEnv> {
impl FromTxWithEncoded<TransactionSigned> for HlTxEnv<TxEnv> {
fn from_encoded_tx(tx: &TransactionSigned, sender: Address, _encoded: Bytes) -> Self {
let base = match tx.clone().0.into_typed_transaction() {
let base = match tx.clone().into_inner().into_typed_transaction() {
reth_primitives::Transaction::Legacy(tx) => TxEnv::from_recovered_tx(&tx, sender),
reth_primitives::Transaction::Eip2930(tx) => TxEnv::from_recovered_tx(&tx, sender),
reth_primitives::Transaction::Eip1559(tx) => TxEnv::from_recovered_tx(&tx, sender),

View File

@ -135,7 +135,9 @@ impl<ChainSpec: EthChainSpec + HlHardforks> Consensus<HlBlock> for HlConsensus<C
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(
&self,
block: &RecoveredBlock<HlBlock>,

View File

@ -14,7 +14,6 @@ use alloy_consensus::{BlockHeader, Header, Transaction as _, TxReceipt, EMPTY_OM
use alloy_eips::merge::BEACON_NONCE;
use alloy_primitives::{Log, U256};
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_ethereum_forks::EthereumHardfork;
use reth_evm::{
block::{BlockExecutionError, BlockExecutorFactory, BlockExecutorFor},
eth::{receipt_builder::ReceiptBuilder, EthBlockExecutionCtx},
@ -67,7 +66,7 @@ where
..
} = input;
let timestamp = evm_env.block_env.timestamp;
let timestamp = evm_env.block_env.timestamp.saturating_to();
// Filter out system tx receipts
let transactions_for_root: Vec<TransactionSigned> =
@ -122,7 +121,7 @@ where
mix_hash: evm_env.block_env.prevrandao.unwrap_or_default(),
nonce: BEACON_NONCE.into(),
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,
difficulty: evm_env.block_env.difficulty,
gas_used: *gas_used,
@ -264,8 +263,6 @@ where
}
}
const EIP1559_INITIAL_BASE_FEE: u64 = 0;
impl ConfigureEvm for HlEvmConfig
where
Self: Send + Sync + Unpin + Clone + 'static,
@ -297,7 +294,7 @@ where
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec);
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
@ -315,9 +312,9 @@ where
let eth_spec = spec.into_eth_spec();
let block_env = BlockEnv {
number: header.number(),
number: U256::from(header.number()),
beneficiary: header.beneficiary(),
timestamp: header.timestamp(),
timestamp: U256::from(header.timestamp()),
difficulty: if eth_spec >= SpecId::MERGE { U256::ZERO } else { header.difficulty() },
prevrandao: if eth_spec >= SpecId::MERGE { header.mix_hash() } else { None },
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
// cancun now, we need to set the excess blob gas to the default value(0)
let blob_excess_gas_and_price = parent
.maybe_next_block_excess_blob_gas(
self.chain_spec().blob_params_at_timestamp(attributes.timestamp),
)
.or_else(|| (spec_id.into_eth_spec().is_enabled_in(SpecId::CANCUN)).then_some(0))
.map(|gas| BlobExcessGasAndPrice::new(gas, false));
let blob_excess_gas_and_price = spec_id
.into_eth_spec()
.is_enabled_in(SpecId::CANCUN)
.then_some(BlobExcessGasAndPrice { excess_blob_gas: 0, blob_gasprice: 0 });
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),
);
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 {
number: parent.number() + 1,
number: U256::from(parent.number() + 1),
beneficiary: attributes.suggested_fee_recipient,
timestamp: attributes.timestamp,
timestamp: U256::from(attributes.timestamp),
difficulty: U256::ZERO,
prevrandao: Some(attributes.prev_randao),
gas_limit: attributes.gas_limit,

View File

@ -16,8 +16,8 @@ use reth_evm::{
block::{BlockValidationError, CommitChanges},
eth::receipt_builder::ReceiptBuilder,
execute::{BlockExecutionError, BlockExecutor},
precompiles::{DynPrecompile, PrecompilesMap},
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook, RecoveredTx,
precompiles::{DynPrecompile, PrecompileInput, PrecompilesMap},
Database, Evm, FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, OnStateHook,
};
use reth_provider::BlockExecutionResult;
use reth_revm::State;
@ -133,24 +133,13 @@ where
fn execute_transaction_with_commit_condition(
&mut self,
_tx: impl ExecutableTx<Self>,
_f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
tx: impl ExecutableTx<Self>,
f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
) -> Result<Option<u64>, BlockExecutionError> {
Ok(Some(0))
}
fn execute_transaction_with_result_closure(
&mut self,
tx: impl ExecutableTx<Self>
+ IntoTxEnv<<E as alloy_evm::Evm>::Tx>
+ RecoveredTx<TransactionSigned>,
f: impl for<'b> FnOnce(&'b ExecutionResult<<E as alloy_evm::Evm>::HaltReason>),
) -> Result<u64, BlockExecutionError> {
// Check if it's a system transaction
// let signer = tx.signer();
// let is_system_transaction = is_system_transaction(tx.tx());
// The sum of the transaction's gas limit, Tg, and the gas utilized in this block prior,
// must be no greater than the block's gasLimit.
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
if tx.tx().gas_limit() > block_available_gas {
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
transaction_gas_limit: tx.tx().gas_limit(),
@ -158,25 +147,33 @@ where
}
.into());
}
let result_and_state = self
// Execute transaction.
let ResultAndState { result, mut state } = self
.evm
.transact(tx)
.map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?;
let ResultAndState { result, mut state } = result_and_state;
f(&result);
if !f(&result).should_commit() {
return Ok(None);
}
let gas_used = result.gas_used();
// append gas used
if !is_system_transaction(tx.tx()) {
self.gas_used += gas_used;
}
// apply patches after
patch_mainnet_after_tx(
self.evm.block().number,
self.evm.block().number.saturating_to(),
self.receipts.len() as u64,
is_system_transaction(tx.tx()),
&mut state,
)?;
// Push transaction changeset and calculate header bloom filter for receipt.
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
tx: tx.tx(),
evm: &self.evm,
@ -185,9 +182,10 @@ where
cumulative_gas_used: self.gas_used,
}));
// Commit the state changes.
self.evm.db_mut().commit(state);
Ok(gas_used)
Ok(Some(gas_used))
}
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
@ -229,8 +227,8 @@ where
for (address, precompile) in ctx.read_precompile_calls.iter() {
let precompile = precompile.clone();
precompiles_mut.apply_precompile(address, |_| {
Some(DynPrecompile::from(move |data: &[u8], gas: u64| {
run_precompile(&precompile, data, gas)
Some(DynPrecompile::from(move |input: PrecompileInput| -> PrecompileResult {
run_precompile(&precompile, input.data, input.gas)
}))
});
}

View File

@ -7,8 +7,8 @@ use crate::evm::{
spec::HlSpecId,
transaction::HlTxEnv,
};
use reth_evm::{precompiles::PrecompilesMap, EvmEnv, EvmFactory};
use reth_revm::{Context, Database};
use reth_evm::{precompiles::PrecompilesMap, Database, EvmEnv, EvmFactory};
use reth_revm::Context;
use revm::{
context::{
result::{EVMError, HaltReason},
@ -25,16 +25,15 @@ use revm::{
pub struct HlEvmFactory;
impl EvmFactory for HlEvmFactory {
type Evm<DB: Database<Error: Send + Sync + 'static>, I: Inspector<HlContext<DB>>> =
HlEvm<DB, I, Self::Precompiles>;
type Context<DB: Database<Error: Send + Sync + 'static>> = HlContext<DB>;
type Evm<DB: Database, I: Inspector<HlContext<DB>>> = HlEvm<DB, I, Self::Precompiles>;
type Context<DB: Database> = HlContext<DB>;
type Tx = HlTxEnv<TxEnv>;
type Error<DBError: core::error::Error + Send + Sync + 'static> = EVMError<DBError>;
type HaltReason = HaltReason;
type Spec = HlSpecId;
type Precompiles = PrecompilesMap;
fn create_evm<DB: Database<Error: Send + Sync + 'static>>(
fn create_evm<DB: Database>(
&self,
db: DB,
input: EvmEnv<HlSpecId>,

View File

@ -97,8 +97,7 @@ where
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
if self.inspect {
self.inner.set_tx(tx);
self.inner.inspect_replay()
self.inner.inspect_tx(tx)
} else {
self.inner.transact(tx)
}

View File

@ -139,7 +139,7 @@ where
inner: BlockBody {
transactions: transactions
.into_transactions()
.map(|tx| TransactionSigned(tx.inner.into_inner().into()))
.map(|tx| TransactionSigned::Default(tx.inner.into_inner().into()))
.collect(),
ommers: Default::default(),
withdrawals,

View File

@ -1,18 +1,13 @@
//! HlNodePrimitives::TransactionSigned; it's the same as ethereum transaction type,
//! except that it supports pseudo signer for system transactions.
use std::hash::Hasher;
use alloy_consensus::{
crypto::RecoveryError, EthereumTxEnvelope, Signed, Transaction as TransactionTrait, TxEip1559,
TxEip2930, TxEip4844, TxEip4844WithSidecar, TxEip7702, TxEnvelope, TxLegacy, TxType,
TypedTransaction,
crypto::RecoveryError, error::ValueError, EthereumTxEnvelope, SignableTransaction, Signed,
Transaction as TransactionTrait, TransactionEnvelope, TxEip1559, TxEip2930, TxEip4844,
TxEip4844WithSidecar, TxEip7702, TxLegacy, TxType, TypedTransaction,
};
use alloy_eips::{
eip2718::Eip2718Result, eip7594::BlobTransactionSidecarVariant, eip7702::SignedAuthorization,
Decodable2718, Encodable2718, Typed2718,
};
use alloy_primitives::{address, Address, Bytes, TxHash, TxKind, Uint, B256, U256};
use alloy_rpc_types::AccessList;
use alloy_eips::{eip7594::BlobTransactionSidecarVariant, Encodable2718};
use alloy_primitives::{address, Address, TxHash, U256};
use alloy_rpc_types::{Transaction, TransactionInfo, TransactionRequest};
use alloy_signer::Signature;
use reth_codecs::alloy::transaction::FromTxCompact;
use reth_db::{
@ -24,13 +19,22 @@ use reth_primitives::Recovered;
use reth_primitives_traits::{
serde_bincode_compat::SerdeBincodeCompat, InMemorySize, SignedTransaction, SignerRecoverable,
};
use revm::context::TxEnv;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use reth_rpc_eth_api::{
transaction::{FromConsensusTx, TryIntoTxEnv},
EthTxEnvError, TryIntoSimTx,
};
use revm::context::{BlockEnv, CfgEnv, TxEnv};
use crate::evm::transaction::HlTxEnv;
type InnerType = alloy_consensus::EthereumTxEnvelope<TxEip4844>;
#[derive(Debug, Clone, Eq)]
pub struct TransactionSigned(pub InnerType);
#[derive(Debug, Clone, TransactionEnvelope)]
#[envelope(tx_type_name = HlTxType)]
pub enum TransactionSigned {
#[envelope(flatten)]
Default(InnerType),
}
fn s_to_address(s: U256) -> Address {
if s == U256::ONE {
@ -46,20 +50,20 @@ impl SignerRecoverable for TransactionSigned {
if self.is_system_transaction() {
return Ok(s_to_address(self.signature().s()));
}
self.0.recover_signer()
self.inner().recover_signer()
}
fn recover_signer_unchecked(&self) -> Result<Address, RecoveryError> {
if self.is_system_transaction() {
return Ok(s_to_address(self.signature().s()));
}
self.0.recover_signer_unchecked()
self.inner().recover_signer_unchecked()
}
}
impl SignedTransaction for TransactionSigned {
fn tx_hash(&self) -> &TxHash {
self.0.tx_hash()
self.inner().tx_hash()
}
fn recover_signer_unchecked_with_buf(
@ -69,8 +73,7 @@ impl SignedTransaction for TransactionSigned {
if self.is_system_transaction() {
return Ok(s_to_address(self.signature().s()));
}
self.0.recover_signer_unchecked_with_buf(buf)
self.inner().recover_signer_unchecked_with_buf(buf)
}
}
@ -78,30 +81,12 @@ impl SignedTransaction for TransactionSigned {
// NOTE: All lines below are just wrappers for the inner type.
// ------------------------------------------------------------
impl Serialize for TransactionSigned {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}
impl<'de> Deserialize<'de> for TransactionSigned {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Ok(Self(InnerType::deserialize(deserializer)?))
}
}
macro_rules! impl_from_signed {
($($tx:ident),*) => {
$(
impl From<Signed<$tx>> for TransactionSigned {
fn from(value: Signed<$tx>) -> Self {
Self(value.into())
Self::Default(value.into())
}
}
)*
@ -113,139 +98,7 @@ impl_from_signed!(TxLegacy, TxEip2930, TxEip1559, TxEip7702, TypedTransaction);
impl InMemorySize for TransactionSigned {
#[inline]
fn size(&self) -> usize {
self.0.size()
}
}
impl alloy_rlp::Encodable for TransactionSigned {
fn encode(&self, out: &mut dyn alloy_rlp::bytes::BufMut) {
self.0.encode(out);
}
fn length(&self) -> usize {
self.0.length()
}
}
impl alloy_rlp::Decodable for TransactionSigned {
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
Ok(Self(TxEnvelope::decode(buf)?.into()))
}
}
impl Encodable2718 for TransactionSigned {
fn type_flag(&self) -> Option<u8> {
self.0.type_flag()
}
fn encode_2718_len(&self) -> usize {
self.0.encode_2718_len()
}
fn encode_2718(&self, out: &mut dyn alloy_rlp::BufMut) {
self.0.encode_2718(out)
}
}
impl Decodable2718 for TransactionSigned {
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self> {
Ok(Self(TxEnvelope::typed_decode(ty, buf)?.into()))
}
fn fallback_decode(buf: &mut &[u8]) -> Eip2718Result<Self> {
Ok(Self(TxEnvelope::fallback_decode(buf)?.into()))
}
}
impl Typed2718 for TransactionSigned {
fn ty(&self) -> u8 {
self.0.ty()
}
}
impl PartialEq for TransactionSigned {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl core::hash::Hash for TransactionSigned {
fn hash<H: Hasher>(&self, state: &mut H) {
core::hash::Hash::hash(&self.0, state);
}
}
impl TransactionTrait for TransactionSigned {
fn chain_id(&self) -> Option<u64> {
self.0.chain_id()
}
fn nonce(&self) -> u64 {
self.0.nonce()
}
fn gas_limit(&self) -> u64 {
self.0.gas_limit()
}
fn gas_price(&self) -> Option<u128> {
self.0.gas_price()
}
fn max_fee_per_gas(&self) -> u128 {
self.0.max_fee_per_gas()
}
fn max_priority_fee_per_gas(&self) -> Option<u128> {
self.0.max_priority_fee_per_gas()
}
fn max_fee_per_blob_gas(&self) -> Option<u128> {
self.0.max_fee_per_blob_gas()
}
fn priority_fee_or_price(&self) -> u128 {
self.0.priority_fee_or_price()
}
fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
self.0.effective_gas_price(base_fee)
}
fn effective_tip_per_gas(&self, base_fee: u64) -> Option<u128> {
self.0.effective_tip_per_gas(base_fee)
}
fn is_dynamic_fee(&self) -> bool {
self.0.is_dynamic_fee()
}
fn kind(&self) -> TxKind {
self.0.kind()
}
fn is_create(&self) -> bool {
self.0.is_create()
}
fn value(&self) -> Uint<256, 4> {
self.0.value()
}
fn input(&self) -> &Bytes {
self.0.input()
}
fn access_list(&self) -> Option<&AccessList> {
self.0.access_list()
}
fn blob_versioned_hashes(&self) -> Option<&[B256]> {
self.0.blob_versioned_hashes()
}
fn authorization_list(&self) -> Option<&[SignedAuthorization]> {
self.0.authorization_list()
self.inner().size()
}
}
@ -254,23 +107,23 @@ impl reth_codecs::Compact for TransactionSigned {
where
B: bytes::BufMut + AsMut<[u8]>,
{
self.0.to_compact(buf)
self.inner().to_compact(buf)
}
fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) {
let (tx, hash) = InnerType::from_compact(buf, _len);
(Self(tx), hash)
(Self::Default(tx), hash)
}
}
pub fn convert_recovered(value: Recovered<TransactionSigned>) -> Recovered<InnerType> {
let (tx, signer) = value.into_parts();
Recovered::new_unchecked(tx.0, signer)
Recovered::new_unchecked(tx.into_inner(), signer)
}
impl FromRecoveredTx<TransactionSigned> for TxEnv {
fn from_recovered_tx(tx: &TransactionSigned, sender: Address) -> Self {
TxEnv::from_recovered_tx(&tx.0, sender)
TxEnv::from_recovered_tx(&tx.inner(), sender)
}
}
@ -282,27 +135,41 @@ impl FromTxCompact for TransactionSigned {
Self: Sized,
{
let (tx, buf) = InnerType::from_tx_compact(buf, tx_type, signature);
(Self(tx), buf)
(Self::Default(tx), buf)
}
}
impl reth_codecs::alloy::transaction::Envelope for TransactionSigned {
fn signature(&self) -> &Signature {
self.0.signature()
self.inner().signature()
}
fn tx_type(&self) -> Self::TxType {
self.0.tx_type()
self.inner().tx_type()
}
}
impl TransactionSigned {
pub const fn signature(&self) -> &Signature {
self.0.signature()
#[inline]
pub fn into_inner(self) -> InnerType {
match self {
Self::Default(tx) => tx,
}
}
#[inline]
pub const fn inner(&self) -> &InnerType {
match self {
Self::Default(tx) => tx,
}
}
pub fn signature(&self) -> &Signature {
self.inner().signature()
}
pub const fn tx_type(&self) -> TxType {
self.0.tx_type()
self.inner().tx_type()
}
pub fn is_system_transaction(&self) -> bool {
@ -329,7 +196,7 @@ pub type BlockBody = alloy_consensus::BlockBody<TransactionSigned>;
impl From<TransactionSigned> for EthereumTxEnvelope<TxEip4844> {
fn from(value: TransactionSigned) -> Self {
value.0
value.into_inner()
}
}
@ -337,7 +204,7 @@ impl TryFrom<TransactionSigned> for EthereumTxEnvelope<TxEip4844WithSidecar> {
type Error = <InnerType as TryInto<EthereumTxEnvelope<TxEip4844WithSidecar>>>::Error;
fn try_from(value: TransactionSigned) -> Result<Self, Self::Error> {
value.0.try_into()
value.into_inner().try_into()
}
}
@ -349,7 +216,7 @@ impl TryFrom<TransactionSigned>
>>::Error;
fn try_from(value: TransactionSigned) -> Result<Self, Self::Error> {
value.0.try_into()
value.into_inner().try_into()
}
}
@ -359,7 +226,7 @@ impl From<EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>
fn from(
value: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>>,
) -> Self {
Self(value.into())
Self::Default(value.into())
}
}
@ -367,23 +234,23 @@ impl Compress for TransactionSigned {
type Compressed = Vec<u8>;
fn compress(self) -> Self::Compressed {
self.0.compress()
self.into_inner().compress()
}
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
self.0.compress_to_buf(buf);
self.inner().compress_to_buf(buf);
}
}
impl Decompress for TransactionSigned {
fn decompress(value: &[u8]) -> Result<Self, DatabaseError> {
Ok(Self(InnerType::decompress(value)?))
Ok(Self::Default(InnerType::decompress(value)?))
}
}
pub fn convert_to_eth_block_body(value: BlockBody) -> alloy_consensus::BlockBody<InnerType> {
alloy_consensus::BlockBody {
transactions: value.transactions.into_iter().map(|tx| tx.0).collect(),
transactions: value.transactions.into_iter().map(|tx| tx.into_inner()).collect(),
ommers: value.ommers,
withdrawals: value.withdrawals,
}
@ -391,8 +258,41 @@ pub fn convert_to_eth_block_body(value: BlockBody) -> alloy_consensus::BlockBody
pub fn convert_to_hl_block_body(value: alloy_consensus::BlockBody<InnerType>) -> BlockBody {
BlockBody {
transactions: value.transactions.into_iter().map(TransactionSigned).collect(),
transactions: value.transactions.into_iter().map(TransactionSigned::Default).collect(),
ommers: value.ommers,
withdrawals: value.withdrawals,
}
}
impl TryIntoSimTx<TransactionSigned> for TransactionRequest {
fn try_into_sim_tx(self) -> Result<TransactionSigned, ValueError<Self>> {
let tx = self
.build_typed_tx()
.map_err(|request| ValueError::new(request, "Required fields missing"))?;
// Create an empty signature for the transaction.
let signature = Signature::new(Default::default(), Default::default(), false);
Ok(tx.into_signed(signature).into())
}
}
impl TryIntoTxEnv<HlTxEnv<TxEnv>> for TransactionRequest {
type Err = EthTxEnvError;
fn try_into_tx_env<Spec>(
self,
cfg_env: &CfgEnv<Spec>,
block_env: &BlockEnv,
) -> Result<HlTxEnv<TxEnv>, Self::Err> {
Ok(HlTxEnv::new(self.clone().try_into_tx_env(cfg_env, block_env)?))
}
}
impl FromConsensusTx<TransactionSigned> for Transaction {
type TxInfo = TransactionInfo;
fn from_consensus_tx(tx: TransactionSigned, signer: Address, tx_info: Self::TxInfo) -> Self {
Self::from_transaction(Recovered::new_unchecked(tx.into_inner().into(), signer), tx_info)
}
}

View File

@ -3,7 +3,6 @@ use crate::{
node::{
primitives::TransactionSigned,
rpc::{HlEthApi, HlNodeCore},
HlBlock, HlPrimitives,
},
};
use alloy_consensus::{BlockHeader, ReceiptEnvelope, TxType};
@ -16,8 +15,7 @@ use reth::{
rpc::{
eth::EthApiTypes,
server_types::eth::{
error::FromEvmError, receipt::build_receipt, EthApiError, EthReceiptBuilder,
PendingBlock,
error::FromEvmError, receipt::build_receipt, EthApiError, PendingBlock,
},
types::{BlockId, TransactionReceipt},
},
@ -25,7 +23,8 @@ use reth::{
};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
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::{
BlockReader, ChainSpecProvider, HeaderProvider, ProviderBlock, ProviderReceipt, ProviderTx,
StateProviderFactory,
@ -33,7 +32,7 @@ use reth_provider::{
use reth_rpc_eth_api::{
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
types::RpcTypes,
FromEthApiError, RpcNodeCore, RpcNodeCoreExt, RpcReceipt,
FromEthApiError, RpcConvert, RpcNodeCore, RpcNodeCoreExt, RpcReceipt,
};
impl<N> EthBlocks for HlEthApi<N>
@ -68,7 +67,7 @@ where
.enumerate()
.map(|(idx, (tx, receipt))| {
let meta = TransactionMeta {
tx_hash: *tx.0.tx_hash(),
tx_hash: *tx.tx_hash(),
index: idx as u64,
block_hash,
block_number,
@ -76,8 +75,15 @@ where
excess_blob_gas,
timestamp,
};
EthReceiptBuilder::new(&tx.0, meta, receipt, &receipts, blob_params)
.map(|builder| builder.build())
build_receipt(tx, meta, receipt, &receipts, blob_params, |receipt_with_bloom| {
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>>()
.map(Some);
@ -108,17 +114,23 @@ where
Header = alloy_rpc_types_eth::Header<ProviderHeader<Self::Provider>>,
>,
Error: FromEvmError<Self::Evm>,
RpcConvert: RpcConvert<Network = Self::NetworkTypes>,
>,
N: RpcNodeCore<
Provider: BlockReaderIdExt<
Transaction = TransactionSigned,
Block = HlBlock,
Receipt = Receipt,
Header = alloy_consensus::Header,
> + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
Provider: BlockReaderIdExt
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
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]
@ -141,7 +153,8 @@ where
gas_limit: parent.gas_limit(),
parent_beacon_block_root: parent.parent_beacon_block_root(),
withdrawals: None,
})
}
.into())
}
}

View File

@ -1,21 +1,15 @@
use super::{HlEthApi, HlNodeCore};
use crate::evm::transaction::HlTxEnv;
use alloy_consensus::TxType;
use alloy_primitives::{TxKind, U256};
use alloy_rpc_types::TransactionRequest;
use alloy_signer::Either;
use reth::rpc::server_types::eth::{revm_utils::CallFees, EthApiError, RpcInvalidTransactionError};
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmEnv, EvmFactory, SpecFor};
use reth::rpc::server_types::eth::EthApiError;
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmFactory, TxEnvFor};
use reth_primitives::NodePrimitives;
use reth_provider::{ProviderHeader, ProviderTx};
use reth_provider::{ProviderError, ProviderHeader, ProviderTx};
use reth_rpc_eth_api::{
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
FromEthApiError, FromEvmError, FullEthApiTypes, IntoEthApiError,
};
use revm::{
context::{Block as _, TxEnv},
Database,
FromEvmError, FullEthApiTypes, RpcConvert, RpcTypes,
};
use revm::context::TxEnv;
impl<N> EthCall for HlEthApi<N>
where
@ -44,7 +38,11 @@ where
EvmFactory: EvmFactory<Tx = HlTxEnv<TxEnv>>,
>,
>,
Error: FromEvmError<Self::Evm>,
RpcConvert: RpcConvert<TxEnv = TxEnvFor<Self::Evm>, Network = Self::NetworkTypes>,
NetworkTypes: RpcTypes<TransactionRequest: From<TransactionRequest>>,
Error: FromEvmError<Self::Evm>
+ From<<Self::RpcConvert as RpcConvert>::Error>
+ From<ProviderError>,
> + SpawnBlocking,
Self::Error: From<EthApiError>,
N: HlNodeCore,
@ -58,107 +56,4 @@ where
fn max_simulate_blocks(&self) -> u64 {
self.inner.eth_api.max_simulate_blocks()
}
fn create_txn_env(
&self,
evm_env: &EvmEnv<SpecFor<Self::Evm>>,
request: TransactionRequest,
mut db: impl Database<Error: Into<EthApiError>>,
) -> Result<HlTxEnv<TxEnv>, Self::Error> {
// Ensure that if versioned hashes are set, they're not empty
if request.blob_versioned_hashes.as_ref().is_some_and(|hashes| hashes.is_empty()) {
return Err(RpcInvalidTransactionError::BlobTransactionMissingBlobHashes.into_eth_err());
}
let tx_type = if request.authorization_list.is_some() {
TxType::Eip7702
} else if request.sidecar.is_some() || request.max_fee_per_blob_gas.is_some() {
TxType::Eip4844
} else if request.max_fee_per_gas.is_some() || request.max_priority_fee_per_gas.is_some() {
TxType::Eip1559
} else if request.access_list.is_some() {
TxType::Eip2930
} else {
TxType::Legacy
} as u8;
let TransactionRequest {
from,
to,
gas_price,
max_fee_per_gas,
max_priority_fee_per_gas,
gas,
value,
input,
nonce,
access_list,
chain_id,
blob_versioned_hashes,
max_fee_per_blob_gas,
authorization_list,
transaction_type: _,
sidecar: _,
} = request;
let CallFees { max_priority_fee_per_gas, gas_price, max_fee_per_blob_gas } =
CallFees::ensure_fees(
gas_price.map(U256::from),
max_fee_per_gas.map(U256::from),
max_priority_fee_per_gas.map(U256::from),
U256::from(evm_env.block_env.basefee),
blob_versioned_hashes.as_deref(),
max_fee_per_blob_gas.map(U256::from),
evm_env.block_env.blob_gasprice().map(U256::from),
)?;
let gas_limit = gas.unwrap_or(
// Use maximum allowed gas limit. The reason for this
// is that both Erigon and Geth use pre-configured gas cap even if
// it's possible to derive the gas limit from the block:
// <https://github.com/ledgerwatch/erigon/blob/eae2d9a79cb70dbe30b3a6b79c436872e4605458/cmd/rpcdaemon/commands/trace_adhoc.go#L956
// https://github.com/ledgerwatch/erigon/blob/eae2d9a79cb70dbe30b3a6b79c436872e4605458/eth/ethconfig/config.go#L94>
evm_env.block_env.gas_limit,
);
let chain_id = chain_id.unwrap_or(evm_env.cfg_env.chain_id);
let caller = from.unwrap_or_default();
let nonce = if let Some(nonce) = nonce {
nonce
} else {
db.basic(caller).map_err(Into::into)?.map(|acc| acc.nonce).unwrap_or_default()
};
let env = TxEnv {
tx_type,
gas_limit,
nonce,
caller,
gas_price: gas_price.saturating_to(),
gas_priority_fee: max_priority_fee_per_gas.map(|v| v.saturating_to()),
kind: to.unwrap_or(TxKind::Create),
value: value.unwrap_or_default(),
data: input
.try_into_unique_input()
.map_err(Self::Error::from_eth_err)?
.unwrap_or_default(),
chain_id: Some(chain_id),
access_list: access_list.unwrap_or_default(),
// EIP-4844 fields
blob_hashes: blob_versioned_hashes.unwrap_or_default(),
max_fee_per_blob_gas: max_fee_per_blob_gas
.map(|v| v.saturating_to())
.unwrap_or_default(),
// EIP-7702 fields
authorization_list: authorization_list
.unwrap_or_default()
.into_iter()
.map(Either::Left)
.collect(),
};
Ok(HlTxEnv::new(env))
}
}

View File

@ -20,7 +20,6 @@ use reth::{
};
use reth_evm::ConfigureEvm;
use reth_network::NetworkInfo;
use reth_optimism_rpc::eth::EthApiNodeBackend;
use reth_primitives::NodePrimitives;
use reth_provider::{
BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt,
@ -31,11 +30,11 @@ use reth_rpc_eth_api::{
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
SpawnBlocking, Trace,
},
EthApiTypes, FromEvmError, RpcNodeCore, RpcNodeCoreExt,
EthApiTypes, FromEvmError, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
};
use std::{fmt, sync::Arc};
use crate::HlPrimitives;
use reth_optimism_rpc::eth::EthApiNodeBackend;
mod block;
mod call;
@ -57,6 +56,8 @@ pub(crate) struct HlEthApiInner<N: HlNodeCore> {
pub struct HlEthApi<N: HlNodeCore> {
/// Gateway to node's core components.
pub(crate) inner: Arc<HlEthApiInner<N>>,
/// Converter for RPC types.
tx_resp_builder: RpcConverter<Ethereum, N::Evm, EthApiError, ()>,
}
impl<N: HlNodeCore> fmt::Debug for HlEthApi<N> {
@ -69,13 +70,14 @@ impl<N> EthApiTypes for HlEthApi<N>
where
Self: Send + Sync,
N: HlNodeCore,
N::Evm: std::fmt::Debug,
{
type Error = EthApiError;
type NetworkTypes = Ethereum;
type TransactionCompat = Self;
type RpcConvert = RpcConverter<Ethereum, N::Evm, EthApiError, ()>;
fn tx_resp_builder(&self) -> &Self::TransactionCompat {
self
fn tx_resp_builder(&self) -> &Self::RpcConvert {
&self.tx_resp_builder
}
}
@ -83,7 +85,7 @@ impl<N> RpcNodeCore for HlEthApi<N>
where
N: HlNodeCore,
{
type Primitives = HlPrimitives;
type Primitives = N::Primitives;
type Provider = N::Provider;
type Pool = N::Pool;
type Evm = <N as RpcNodeCore>::Evm;
@ -152,6 +154,7 @@ impl<N> SpawnBlocking for HlEthApi<N>
where
Self: Send + Sync + Clone + 'static,
N: HlNodeCore,
N::Evm: std::fmt::Debug,
{
#[inline]
fn io_task_spawner(&self) -> impl TaskSpawner {
@ -189,11 +192,13 @@ where
}
}
impl<N> LoadState for HlEthApi<N> where
impl<N> LoadState for HlEthApi<N>
where
N: HlNodeCore<
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
Pool: TransactionPool,
>
>,
N::Evm: std::fmt::Debug,
{
}
@ -210,7 +215,11 @@ where
impl<N> EthFees for HlEthApi<N>
where
Self: LoadFee,
Self: LoadFee<
Provider: ChainSpecProvider<
ChainSpec: EthChainSpec<Header = ProviderHeader<Self::Provider>>,
>,
>,
N: HlNodeCore,
{
}
@ -268,6 +277,9 @@ where
.proof_permits(ctx.config.proof_permits)
.build_inner();
Ok(HlEthApi { inner: Arc::new(HlEthApiInner { eth_api }) })
Ok(HlEthApi {
inner: Arc::new(HlEthApiInner { eth_api }),
tx_resp_builder: Default::default(),
})
}
}

View File

@ -1,28 +1,14 @@
use super::HlNodeCore;
use crate::{
node::{
primitives::{tx_wrapper::convert_recovered, TransactionSigned},
rpc::HlEthApi,
},
HlPrimitives,
};
use alloy_network::{Ethereum, Network};
use alloy_primitives::{Bytes, Signature, B256};
use crate::node::rpc::HlEthApi;
use alloy_primitives::{Bytes, B256};
use reth::{
builder::FullNodeComponents,
primitives::{Receipt, Recovered},
providers::ReceiptProvider,
rpc::{
eth::helpers::types::EthRpcConverter,
server_types::eth::{utils::recover_raw_transaction, EthApiError},
types::{TransactionInfo, TransactionRequest},
},
rpc::server_types::eth::utils::recover_raw_transaction,
transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool},
};
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt, TransactionCompat,
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
};
impl<N> LoadTransaction for HlEthApi<N>
@ -33,41 +19,6 @@ where
{
}
impl<N> TransactionCompat for HlEthApi<N>
where
N: FullNodeComponents<Provider: ReceiptProvider<Receipt = Receipt>>,
{
type Primitives = HlPrimitives;
type Transaction = <Ethereum as Network>::TransactionResponse;
type Error = EthApiError;
fn fill(
&self,
tx: Recovered<TransactionSigned>,
tx_info: TransactionInfo,
) -> Result<Self::Transaction, Self::Error> {
let builder = EthRpcConverter::default();
builder.fill(convert_recovered(tx), tx_info)
}
fn build_simulate_v1_transaction(
&self,
request: TransactionRequest,
) -> Result<TransactionSigned, Self::Error> {
let Ok(tx) = request.build_typed_tx() else {
return Err(EthApiError::TransactionConversionError);
};
// Create an empty signature for the transaction.
let signature = Signature::new(Default::default(), Default::default(), false);
Ok(TransactionSigned(reth_primitives::TransactionSigned::new_unhashed(
tx.into(),
signature,
)))
}
}
impl<N> EthTransactions for HlEthApi<N>
where
Self: LoadTransaction<Provider: BlockReaderIdExt>,

View File

@ -139,7 +139,7 @@ where
inputs
.into_iter()
.map(|(header, transactions)| {
(header, transactions.into_iter().map(|tx| tx.0).collect())
(header, transactions.into_iter().map(|tx| tx.into_inner()).collect())
})
.collect(),
)?;

View File

@ -47,19 +47,19 @@ impl TransactionSigned {
fn to_reth_transaction(&self) -> TxSigned {
match self.transaction.clone() {
Transaction::Legacy(tx) => {
TxSigned(RethTxSigned::Legacy(Signed::new_unhashed(tx, self.signature)))
TxSigned::Default(RethTxSigned::Legacy(Signed::new_unhashed(tx, self.signature)))
}
Transaction::Eip2930(tx) => {
TxSigned(RethTxSigned::Eip2930(Signed::new_unhashed(tx, self.signature)))
TxSigned::Default(RethTxSigned::Eip2930(Signed::new_unhashed(tx, self.signature)))
}
Transaction::Eip1559(tx) => {
TxSigned(RethTxSigned::Eip1559(Signed::new_unhashed(tx, self.signature)))
TxSigned::Default(RethTxSigned::Eip1559(Signed::new_unhashed(tx, self.signature)))
}
Transaction::Eip4844(tx) => {
TxSigned(RethTxSigned::Eip4844(Signed::new_unhashed(tx, self.signature)))
TxSigned::Default(RethTxSigned::Eip4844(Signed::new_unhashed(tx, self.signature)))
}
Transaction::Eip7702(tx) => {
TxSigned(RethTxSigned::Eip7702(Signed::new_unhashed(tx, self.signature)))
TxSigned::Default(RethTxSigned::Eip7702(Signed::new_unhashed(tx, self.signature)))
}
}
}
@ -104,7 +104,7 @@ fn system_tx_to_reth_transaction(transaction: &SystemTx, chain_id: u64) -> TxSig
}
};
let signature = Signature::new(U256::from(0x1), s, true);
TxSigned(RethTxSigned::Legacy(Signed::new_unhashed(tx.clone(), signature)))
TxSigned::Default(RethTxSigned::Legacy(Signed::new_unhashed(tx.clone(), signature)))
}
}