mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Merge pull request #1 from sprites0/upgrade/1.5.0
chore: Upgrade to reth 1.5.0
This commit is contained in:
1489
Cargo.lock
generated
1489
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
114
Cargo.toml
114
Cargo.toml
@ -12,61 +12,61 @@ name = "reth-hl"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reth = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-cli = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-cli = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-cli-commands = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-cli-commands = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-basic-payload-builder = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-basic-payload-builder = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-db = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-db = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-db-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-db-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-chainspec = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-chainspec = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-cli-util = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-cli-util = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-discv4 = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-discv4 = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-engine-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-engine-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-ethereum-forks = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-ethereum-forks = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-ethereum-payload-builder = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-ethereum-payload-builder = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-ethereum-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-ethereum-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-eth-wire = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-eth-wire = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-eth-wire-types = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-eth-wire-types = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-evm = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-evm = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-evm-ethereum = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-evm-ethereum = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-node-core = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-node-core = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-revm = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-revm = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-network = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-network = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-network-p2p = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-network-p2p = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-network-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-network-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-node-ethereum = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-node-ethereum = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-network-peers = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-network-peers = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-optimism-rpc = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-optimism-rpc = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-payload-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-payload-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-primitives = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-primitives = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-primitives-traits = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-primitives-traits = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-provider = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4", features = ["test-utils"] }
|
reth-provider = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc", features = ["test-utils"] }
|
||||||
reth-rpc-eth-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-rpc-eth-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-rpc-engine-api = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-rpc-engine-api = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-tracing = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-tracing = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-trie-common = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-trie-common = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-trie-db = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-trie-db = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-codecs = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-codecs = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
reth-transaction-pool = { git = "https://github.com/sprites0/reth", rev = "131c608706ed662f16112eabaad9e8a5a0471ef4" }
|
reth-transaction-pool = { git = "https://github.com/sprites0/reth", rev = "fc754e5983f055365325dc9a04632d5ba2c4a8bc" }
|
||||||
revm = { version = "24.0.1" }
|
revm = { version = "26.0.1" }
|
||||||
|
|
||||||
# alloy dependencies
|
# alloy dependencies
|
||||||
alloy-genesis = "1.0.9"
|
alloy-genesis = "1.0.13"
|
||||||
alloy-consensus = { version = "1.0.9", features = ["serde"] }
|
alloy-consensus = { version = "1.0.13", features = ["serde"] }
|
||||||
alloy-chains = "0.2.0"
|
alloy-chains = "0.2.0"
|
||||||
alloy-eips = "1.0.9"
|
alloy-eips = "1.0.13"
|
||||||
alloy-evm = "0.10"
|
alloy-evm = "0.12"
|
||||||
alloy-json-abi = { version = "1.0.0", default-features = false }
|
alloy-json-abi = { version = "1.0.0", default-features = false }
|
||||||
alloy-dyn-abi = "1.1.0"
|
alloy-dyn-abi = "1.2.0"
|
||||||
alloy-network = "1.0.9"
|
alloy-network = "1.0.13"
|
||||||
alloy-primitives = { version = "1.1.0", default-features = false, features = ["map-foldhash"] }
|
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-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] }
|
||||||
alloy-rpc-types = { version = "1.0.9", features = ["engine"] }
|
alloy-rpc-types = { version = "1.0.13", features = ["engine"] }
|
||||||
alloy-rpc-types-eth = "1.0.9"
|
alloy-rpc-types-eth = "1.0.13"
|
||||||
alloy-rpc-types-engine = "1.0.9"
|
alloy-rpc-types-engine = "1.0.13"
|
||||||
alloy-signer = "1.0.9"
|
alloy-signer = "1.0.13"
|
||||||
alloy-sol-macro = "1.1.0"
|
alloy-sol-macro = "1.2.0"
|
||||||
alloy-sol-types = { version = "1.1.0", default-features = false }
|
alloy-sol-types = { version = "1.2.0", default-features = false }
|
||||||
|
|
||||||
jsonrpsee = "0.25.1"
|
jsonrpsee = "0.25.1"
|
||||||
jsonrpsee-core = { version = "0.25.1" }
|
jsonrpsee-core = { version = "0.25.1" }
|
||||||
@ -76,9 +76,9 @@ jsonrpsee-types = "0.25.1"
|
|||||||
auto_impl = "1"
|
auto_impl = "1"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
bytes = "1.5"
|
bytes = "1.5"
|
||||||
clap = { version = "4.4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
cfg-if = { version = "1.0", default-features = false }
|
cfg-if = { version = "1.0", default-features = false }
|
||||||
derive_more = "0.99"
|
derive_more = { version = "2", default-features = false, features = ["full"] }
|
||||||
eyre = "0.6"
|
eyre = "0.6"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
@ -86,16 +86,16 @@ once_cell = { version = "1.19", default-features = false, features = ["alloc"] }
|
|||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
serde = { version = "1.0", features = ["derive"], default-features = false }
|
serde = { version = "1.0", features = ["derive"], default-features = false }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = { version = "2.0.0", default-features = false }
|
||||||
tokio = { version = "1.36", features = ["full"] }
|
tokio = { version = "1.44.2", features = ["full"] }
|
||||||
tokio-stream = "0.1"
|
tokio-stream = "0.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
rmp-serde = "1.0.0"
|
rmp-serde = "1.3"
|
||||||
lz4_flex = "0.11.3"
|
lz4_flex = "0.11"
|
||||||
ureq = "3.0.12"
|
ureq = "3.0.12"
|
||||||
aws-sdk-s3 = "1.93.0"
|
aws-sdk-s3 = "1.93.0"
|
||||||
aws-config = "1.8.0"
|
aws-config = "1.8.0"
|
||||||
rayon = "1.10.0"
|
rayon = "1.7"
|
||||||
time = "0.3.41"
|
time = "0.3.41"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +98,4 @@ where
|
|||||||
INSP: Inspector<CTX, EthInterpreter>,
|
INSP: Inspector<CTX, EthInterpreter>,
|
||||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)]
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -130,7 +130,7 @@ impl FromRecoveredTx<TransactionSigned> for HlTxEnv<TxEnv> {
|
|||||||
|
|
||||||
impl FromTxWithEncoded<TransactionSigned> for HlTxEnv<TxEnv> {
|
impl FromTxWithEncoded<TransactionSigned> for HlTxEnv<TxEnv> {
|
||||||
fn from_encoded_tx(tx: &TransactionSigned, sender: Address, _encoded: Bytes) -> Self {
|
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::Legacy(tx) => TxEnv::from_recovered_tx(&tx, sender),
|
||||||
reth_primitives::Transaction::Eip2930(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),
|
reth_primitives::Transaction::Eip1559(tx) => TxEnv::from_recovered_tx(&tx, sender),
|
||||||
|
|||||||
@ -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;
|
||||||
@ -133,24 +133,13 @@ where
|
|||||||
|
|
||||||
fn execute_transaction_with_commit_condition(
|
fn execute_transaction_with_commit_condition(
|
||||||
&mut self,
|
&mut self,
|
||||||
_tx: impl ExecutableTx<Self>,
|
tx: impl ExecutableTx<Self>,
|
||||||
_f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
|
f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
|
||||||
) -> Result<Option<u64>, BlockExecutionError> {
|
) -> Result<Option<u64>, BlockExecutionError> {
|
||||||
Ok(Some(0))
|
// 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.
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
|
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
|
||||||
|
|
||||||
if tx.tx().gas_limit() > block_available_gas {
|
if tx.tx().gas_limit() > block_available_gas {
|
||||||
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||||
transaction_gas_limit: tx.tx().gas_limit(),
|
transaction_gas_limit: tx.tx().gas_limit(),
|
||||||
@ -158,25 +147,33 @@ where
|
|||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
let result_and_state = self
|
|
||||||
|
// Execute transaction.
|
||||||
|
let ResultAndState { result, mut state } = self
|
||||||
.evm
|
.evm
|
||||||
.transact(tx)
|
.transact(tx)
|
||||||
.map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?;
|
.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();
|
let gas_used = result.gas_used();
|
||||||
|
|
||||||
|
// append gas used
|
||||||
if !is_system_transaction(tx.tx()) {
|
if !is_system_transaction(tx.tx()) {
|
||||||
self.gas_used += gas_used;
|
self.gas_used += gas_used;
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply patches after
|
// apply patches after
|
||||||
patch_mainnet_after_tx(
|
patch_mainnet_after_tx(
|
||||||
self.evm.block().number,
|
self.evm.block().number.saturating_to(),
|
||||||
self.receipts.len() as u64,
|
self.receipts.len() as u64,
|
||||||
is_system_transaction(tx.tx()),
|
is_system_transaction(tx.tx()),
|
||||||
&mut state,
|
&mut state,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// Push transaction changeset and calculate header bloom filter for receipt.
|
||||||
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
||||||
tx: tx.tx(),
|
tx: tx.tx(),
|
||||||
evm: &self.evm,
|
evm: &self.evm,
|
||||||
@ -185,9 +182,10 @@ where
|
|||||||
cumulative_gas_used: self.gas_used,
|
cumulative_gas_used: self.gas_used,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Commit the state changes.
|
||||||
self.evm.db_mut().commit(state);
|
self.evm.db_mut().commit(state);
|
||||||
|
|
||||||
Ok(gas_used)
|
Ok(Some(gas_used))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
|
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
|
||||||
@ -229,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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,7 +139,7 @@ where
|
|||||||
inner: BlockBody {
|
inner: BlockBody {
|
||||||
transactions: transactions
|
transactions: transactions
|
||||||
.into_transactions()
|
.into_transactions()
|
||||||
.map(|tx| TransactionSigned(tx.inner.into_inner().into()))
|
.map(|tx| TransactionSigned::Default(tx.inner.into_inner().into()))
|
||||||
.collect(),
|
.collect(),
|
||||||
ommers: Default::default(),
|
ommers: Default::default(),
|
||||||
withdrawals,
|
withdrawals,
|
||||||
|
|||||||
@ -1,18 +1,13 @@
|
|||||||
//! HlNodePrimitives::TransactionSigned; it's the same as ethereum transaction type,
|
//! HlNodePrimitives::TransactionSigned; it's the same as ethereum transaction type,
|
||||||
//! except that it supports pseudo signer for system transactions.
|
//! except that it supports pseudo signer for system transactions.
|
||||||
use std::hash::Hasher;
|
|
||||||
|
|
||||||
use alloy_consensus::{
|
use alloy_consensus::{
|
||||||
crypto::RecoveryError, EthereumTxEnvelope, Signed, Transaction as TransactionTrait, TxEip1559,
|
crypto::RecoveryError, error::ValueError, EthereumTxEnvelope, SignableTransaction, Signed,
|
||||||
TxEip2930, TxEip4844, TxEip4844WithSidecar, TxEip7702, TxEnvelope, TxLegacy, TxType,
|
Transaction as TransactionTrait, TransactionEnvelope, TxEip1559, TxEip2930, TxEip4844,
|
||||||
TypedTransaction,
|
TxEip4844WithSidecar, TxEip7702, TxLegacy, TxType, TypedTransaction,
|
||||||
};
|
};
|
||||||
use alloy_eips::{
|
use alloy_eips::{eip7594::BlobTransactionSidecarVariant, Encodable2718};
|
||||||
eip2718::Eip2718Result, eip7594::BlobTransactionSidecarVariant, eip7702::SignedAuthorization,
|
use alloy_primitives::{address, Address, TxHash, U256};
|
||||||
Decodable2718, Encodable2718, Typed2718,
|
use alloy_rpc_types::{Transaction, TransactionInfo, TransactionRequest};
|
||||||
};
|
|
||||||
use alloy_primitives::{address, Address, Bytes, TxHash, TxKind, Uint, B256, U256};
|
|
||||||
use alloy_rpc_types::AccessList;
|
|
||||||
use alloy_signer::Signature;
|
use alloy_signer::Signature;
|
||||||
use reth_codecs::alloy::transaction::FromTxCompact;
|
use reth_codecs::alloy::transaction::FromTxCompact;
|
||||||
use reth_db::{
|
use reth_db::{
|
||||||
@ -24,13 +19,22 @@ use reth_primitives::Recovered;
|
|||||||
use reth_primitives_traits::{
|
use reth_primitives_traits::{
|
||||||
serde_bincode_compat::SerdeBincodeCompat, InMemorySize, SignedTransaction, SignerRecoverable,
|
serde_bincode_compat::SerdeBincodeCompat, InMemorySize, SignedTransaction, SignerRecoverable,
|
||||||
};
|
};
|
||||||
use revm::context::TxEnv;
|
use reth_rpc_eth_api::{
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
transaction::{FromConsensusTx, TryIntoTxEnv},
|
||||||
|
EthTxEnvError, TryIntoSimTx,
|
||||||
|
};
|
||||||
|
use revm::context::{BlockEnv, CfgEnv, TxEnv};
|
||||||
|
|
||||||
|
use crate::evm::transaction::HlTxEnv;
|
||||||
|
|
||||||
type InnerType = alloy_consensus::EthereumTxEnvelope<TxEip4844>;
|
type InnerType = alloy_consensus::EthereumTxEnvelope<TxEip4844>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq)]
|
#[derive(Debug, Clone, TransactionEnvelope)]
|
||||||
pub struct TransactionSigned(pub InnerType);
|
#[envelope(tx_type_name = HlTxType)]
|
||||||
|
pub enum TransactionSigned {
|
||||||
|
#[envelope(flatten)]
|
||||||
|
Default(InnerType),
|
||||||
|
}
|
||||||
|
|
||||||
fn s_to_address(s: U256) -> Address {
|
fn s_to_address(s: U256) -> Address {
|
||||||
if s == U256::ONE {
|
if s == U256::ONE {
|
||||||
@ -46,20 +50,20 @@ impl SignerRecoverable for TransactionSigned {
|
|||||||
if self.is_system_transaction() {
|
if self.is_system_transaction() {
|
||||||
return Ok(s_to_address(self.signature().s()));
|
return Ok(s_to_address(self.signature().s()));
|
||||||
}
|
}
|
||||||
self.0.recover_signer()
|
self.inner().recover_signer()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recover_signer_unchecked(&self) -> Result<Address, RecoveryError> {
|
fn recover_signer_unchecked(&self) -> Result<Address, RecoveryError> {
|
||||||
if self.is_system_transaction() {
|
if self.is_system_transaction() {
|
||||||
return Ok(s_to_address(self.signature().s()));
|
return Ok(s_to_address(self.signature().s()));
|
||||||
}
|
}
|
||||||
self.0.recover_signer_unchecked()
|
self.inner().recover_signer_unchecked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SignedTransaction for TransactionSigned {
|
impl SignedTransaction for TransactionSigned {
|
||||||
fn tx_hash(&self) -> &TxHash {
|
fn tx_hash(&self) -> &TxHash {
|
||||||
self.0.tx_hash()
|
self.inner().tx_hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recover_signer_unchecked_with_buf(
|
fn recover_signer_unchecked_with_buf(
|
||||||
@ -69,8 +73,7 @@ impl SignedTransaction for TransactionSigned {
|
|||||||
if self.is_system_transaction() {
|
if self.is_system_transaction() {
|
||||||
return Ok(s_to_address(self.signature().s()));
|
return Ok(s_to_address(self.signature().s()));
|
||||||
}
|
}
|
||||||
|
self.inner().recover_signer_unchecked_with_buf(buf)
|
||||||
self.0.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.
|
// 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 {
|
macro_rules! impl_from_signed {
|
||||||
($($tx:ident),*) => {
|
($($tx:ident),*) => {
|
||||||
$(
|
$(
|
||||||
impl From<Signed<$tx>> for TransactionSigned {
|
impl From<Signed<$tx>> for TransactionSigned {
|
||||||
fn from(value: Signed<$tx>) -> Self {
|
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 {
|
impl InMemorySize for TransactionSigned {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.0.size()
|
self.inner().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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,23 +107,23 @@ impl reth_codecs::Compact for TransactionSigned {
|
|||||||
where
|
where
|
||||||
B: bytes::BufMut + AsMut<[u8]>,
|
B: bytes::BufMut + AsMut<[u8]>,
|
||||||
{
|
{
|
||||||
self.0.to_compact(buf)
|
self.inner().to_compact(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) {
|
fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) {
|
||||||
let (tx, hash) = InnerType::from_compact(buf, _len);
|
let (tx, hash) = InnerType::from_compact(buf, _len);
|
||||||
(Self(tx), hash)
|
(Self::Default(tx), hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_recovered(value: Recovered<TransactionSigned>) -> Recovered<InnerType> {
|
pub fn convert_recovered(value: Recovered<TransactionSigned>) -> Recovered<InnerType> {
|
||||||
let (tx, signer) = value.into_parts();
|
let (tx, signer) = value.into_parts();
|
||||||
Recovered::new_unchecked(tx.0, signer)
|
Recovered::new_unchecked(tx.into_inner(), signer)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromRecoveredTx<TransactionSigned> for TxEnv {
|
impl FromRecoveredTx<TransactionSigned> for TxEnv {
|
||||||
fn from_recovered_tx(tx: &TransactionSigned, sender: Address) -> Self {
|
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,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let (tx, buf) = InnerType::from_tx_compact(buf, tx_type, signature);
|
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 {
|
impl reth_codecs::alloy::transaction::Envelope for TransactionSigned {
|
||||||
fn signature(&self) -> &Signature {
|
fn signature(&self) -> &Signature {
|
||||||
self.0.signature()
|
self.inner().signature()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tx_type(&self) -> Self::TxType {
|
fn tx_type(&self) -> Self::TxType {
|
||||||
self.0.tx_type()
|
self.inner().tx_type()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransactionSigned {
|
impl TransactionSigned {
|
||||||
pub const fn signature(&self) -> &Signature {
|
#[inline]
|
||||||
self.0.signature()
|
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 {
|
pub const fn tx_type(&self) -> TxType {
|
||||||
self.0.tx_type()
|
self.inner().tx_type()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_system_transaction(&self) -> bool {
|
pub fn is_system_transaction(&self) -> bool {
|
||||||
@ -329,7 +196,7 @@ pub type BlockBody = alloy_consensus::BlockBody<TransactionSigned>;
|
|||||||
|
|
||||||
impl From<TransactionSigned> for EthereumTxEnvelope<TxEip4844> {
|
impl From<TransactionSigned> for EthereumTxEnvelope<TxEip4844> {
|
||||||
fn from(value: TransactionSigned) -> Self {
|
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;
|
type Error = <InnerType as TryInto<EthereumTxEnvelope<TxEip4844WithSidecar>>>::Error;
|
||||||
|
|
||||||
fn try_from(value: TransactionSigned) -> Result<Self, Self::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;
|
>>::Error;
|
||||||
|
|
||||||
fn try_from(value: TransactionSigned) -> Result<Self, Self::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(
|
fn from(
|
||||||
value: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>>,
|
value: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self(value.into())
|
Self::Default(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,23 +234,23 @@ impl Compress for TransactionSigned {
|
|||||||
type Compressed = Vec<u8>;
|
type Compressed = Vec<u8>;
|
||||||
|
|
||||||
fn compress(self) -> Self::Compressed {
|
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) {
|
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 {
|
impl Decompress for TransactionSigned {
|
||||||
fn decompress(value: &[u8]) -> Result<Self, DatabaseError> {
|
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> {
|
pub fn convert_to_eth_block_body(value: BlockBody) -> alloy_consensus::BlockBody<InnerType> {
|
||||||
alloy_consensus::BlockBody {
|
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,
|
ommers: value.ommers,
|
||||||
withdrawals: value.withdrawals,
|
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 {
|
pub fn convert_to_hl_block_body(value: alloy_consensus::BlockBody<InnerType>) -> BlockBody {
|
||||||
BlockBody {
|
BlockBody {
|
||||||
transactions: value.transactions.into_iter().map(TransactionSigned).collect(),
|
transactions: value.transactions.into_iter().map(TransactionSigned::Default).collect(),
|
||||||
ommers: value.ommers,
|
ommers: value.ommers,
|
||||||
withdrawals: value.withdrawals,
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +1,15 @@
|
|||||||
use super::{HlEthApi, HlNodeCore};
|
use super::{HlEthApi, HlNodeCore};
|
||||||
use crate::evm::transaction::HlTxEnv;
|
use crate::evm::transaction::HlTxEnv;
|
||||||
use alloy_consensus::TxType;
|
|
||||||
use alloy_primitives::{TxKind, U256};
|
|
||||||
use alloy_rpc_types::TransactionRequest;
|
use alloy_rpc_types::TransactionRequest;
|
||||||
use alloy_signer::Either;
|
use reth::rpc::server_types::eth::EthApiError;
|
||||||
use reth::rpc::server_types::eth::{revm_utils::CallFees, EthApiError, RpcInvalidTransactionError};
|
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmFactory, TxEnvFor};
|
||||||
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmEnv, EvmFactory, SpecFor};
|
|
||||||
use reth_primitives::NodePrimitives;
|
use reth_primitives::NodePrimitives;
|
||||||
use reth_provider::{ProviderHeader, ProviderTx};
|
use reth_provider::{ProviderError, ProviderHeader, ProviderTx};
|
||||||
use reth_rpc_eth_api::{
|
use reth_rpc_eth_api::{
|
||||||
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
|
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
|
||||||
FromEthApiError, FromEvmError, FullEthApiTypes, IntoEthApiError,
|
FromEvmError, FullEthApiTypes, RpcConvert, RpcTypes,
|
||||||
};
|
|
||||||
use revm::{
|
|
||||||
context::{Block as _, TxEnv},
|
|
||||||
Database,
|
|
||||||
};
|
};
|
||||||
|
use revm::context::TxEnv;
|
||||||
|
|
||||||
impl<N> EthCall for HlEthApi<N>
|
impl<N> EthCall for HlEthApi<N>
|
||||||
where
|
where
|
||||||
@ -44,7 +38,11 @@ where
|
|||||||
EvmFactory: EvmFactory<Tx = HlTxEnv<TxEnv>>,
|
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,
|
> + SpawnBlocking,
|
||||||
Self::Error: From<EthApiError>,
|
Self::Error: From<EthApiError>,
|
||||||
N: HlNodeCore,
|
N: HlNodeCore,
|
||||||
@ -58,107 +56,4 @@ where
|
|||||||
fn max_simulate_blocks(&self) -> u64 {
|
fn max_simulate_blocks(&self) -> u64 {
|
||||||
self.inner.eth_api.max_simulate_blocks()
|
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,6 @@ use reth::{
|
|||||||
};
|
};
|
||||||
use reth_evm::ConfigureEvm;
|
use reth_evm::ConfigureEvm;
|
||||||
use reth_network::NetworkInfo;
|
use reth_network::NetworkInfo;
|
||||||
use reth_optimism_rpc::eth::EthApiNodeBackend;
|
|
||||||
use reth_primitives::NodePrimitives;
|
use reth_primitives::NodePrimitives;
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt,
|
BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt,
|
||||||
@ -31,11 +30,11 @@ use reth_rpc_eth_api::{
|
|||||||
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
|
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
|
||||||
SpawnBlocking, Trace,
|
SpawnBlocking, Trace,
|
||||||
},
|
},
|
||||||
EthApiTypes, FromEvmError, RpcNodeCore, RpcNodeCoreExt,
|
EthApiTypes, FromEvmError, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
|
||||||
};
|
};
|
||||||
use std::{fmt, sync::Arc};
|
use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
use crate::HlPrimitives;
|
use reth_optimism_rpc::eth::EthApiNodeBackend;
|
||||||
|
|
||||||
mod block;
|
mod block;
|
||||||
mod call;
|
mod call;
|
||||||
@ -57,6 +56,8 @@ pub(crate) struct HlEthApiInner<N: HlNodeCore> {
|
|||||||
pub struct HlEthApi<N: HlNodeCore> {
|
pub struct HlEthApi<N: HlNodeCore> {
|
||||||
/// Gateway to node's core components.
|
/// Gateway to node's core components.
|
||||||
pub(crate) inner: Arc<HlEthApiInner<N>>,
|
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> {
|
impl<N: HlNodeCore> fmt::Debug for HlEthApi<N> {
|
||||||
@ -69,13 +70,14 @@ impl<N> EthApiTypes for HlEthApi<N>
|
|||||||
where
|
where
|
||||||
Self: Send + Sync,
|
Self: Send + Sync,
|
||||||
N: HlNodeCore,
|
N: HlNodeCore,
|
||||||
|
N::Evm: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
type Error = EthApiError;
|
type Error = EthApiError;
|
||||||
type NetworkTypes = Ethereum;
|
type NetworkTypes = Ethereum;
|
||||||
type TransactionCompat = Self;
|
type RpcConvert = RpcConverter<Ethereum, N::Evm, EthApiError, ()>;
|
||||||
|
|
||||||
fn tx_resp_builder(&self) -> &Self::TransactionCompat {
|
fn tx_resp_builder(&self) -> &Self::RpcConvert {
|
||||||
self
|
&self.tx_resp_builder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +85,7 @@ impl<N> RpcNodeCore for HlEthApi<N>
|
|||||||
where
|
where
|
||||||
N: HlNodeCore,
|
N: HlNodeCore,
|
||||||
{
|
{
|
||||||
type Primitives = HlPrimitives;
|
type Primitives = N::Primitives;
|
||||||
type Provider = N::Provider;
|
type Provider = N::Provider;
|
||||||
type Pool = N::Pool;
|
type Pool = N::Pool;
|
||||||
type Evm = <N as RpcNodeCore>::Evm;
|
type Evm = <N as RpcNodeCore>::Evm;
|
||||||
@ -152,6 +154,7 @@ impl<N> SpawnBlocking for HlEthApi<N>
|
|||||||
where
|
where
|
||||||
Self: Send + Sync + Clone + 'static,
|
Self: Send + Sync + Clone + 'static,
|
||||||
N: HlNodeCore,
|
N: HlNodeCore,
|
||||||
|
N::Evm: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn io_task_spawner(&self) -> impl TaskSpawner {
|
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<
|
N: HlNodeCore<
|
||||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||||
Pool: TransactionPool,
|
Pool: TransactionPool,
|
||||||
>
|
>,
|
||||||
|
N::Evm: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +215,11 @@ where
|
|||||||
|
|
||||||
impl<N> EthFees for HlEthApi<N>
|
impl<N> EthFees for HlEthApi<N>
|
||||||
where
|
where
|
||||||
Self: LoadFee,
|
Self: LoadFee<
|
||||||
|
Provider: ChainSpecProvider<
|
||||||
|
ChainSpec: EthChainSpec<Header = ProviderHeader<Self::Provider>>,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
N: HlNodeCore,
|
N: HlNodeCore,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -268,6 +277,9 @@ where
|
|||||||
.proof_permits(ctx.config.proof_permits)
|
.proof_permits(ctx.config.proof_permits)
|
||||||
.build_inner();
|
.build_inner();
|
||||||
|
|
||||||
Ok(HlEthApi { inner: Arc::new(HlEthApiInner { eth_api }) })
|
Ok(HlEthApi {
|
||||||
|
inner: Arc::new(HlEthApiInner { eth_api }),
|
||||||
|
tx_resp_builder: Default::default(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,14 @@
|
|||||||
use super::HlNodeCore;
|
use super::HlNodeCore;
|
||||||
use crate::{
|
use crate::node::rpc::HlEthApi;
|
||||||
node::{
|
use alloy_primitives::{Bytes, B256};
|
||||||
primitives::{tx_wrapper::convert_recovered, TransactionSigned},
|
|
||||||
rpc::HlEthApi,
|
|
||||||
},
|
|
||||||
HlPrimitives,
|
|
||||||
};
|
|
||||||
use alloy_network::{Ethereum, Network};
|
|
||||||
use alloy_primitives::{Bytes, Signature, B256};
|
|
||||||
use reth::{
|
use reth::{
|
||||||
builder::FullNodeComponents,
|
rpc::server_types::eth::utils::recover_raw_transaction,
|
||||||
primitives::{Receipt, Recovered},
|
|
||||||
providers::ReceiptProvider,
|
|
||||||
rpc::{
|
|
||||||
eth::helpers::types::EthRpcConverter,
|
|
||||||
server_types::eth::{utils::recover_raw_transaction, EthApiError},
|
|
||||||
types::{TransactionInfo, TransactionRequest},
|
|
||||||
},
|
|
||||||
transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool},
|
transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool},
|
||||||
};
|
};
|
||||||
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
|
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
|
||||||
use reth_rpc_eth_api::{
|
use reth_rpc_eth_api::{
|
||||||
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
|
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
|
||||||
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt, TransactionCompat,
|
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<N> LoadTransaction for HlEthApi<N>
|
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>
|
impl<N> EthTransactions for HlEthApi<N>
|
||||||
where
|
where
|
||||||
Self: LoadTransaction<Provider: BlockReaderIdExt>,
|
Self: LoadTransaction<Provider: BlockReaderIdExt>,
|
||||||
|
|||||||
@ -139,7 +139,7 @@ where
|
|||||||
inputs
|
inputs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(header, transactions)| {
|
.map(|(header, transactions)| {
|
||||||
(header, transactions.into_iter().map(|tx| tx.0).collect())
|
(header, transactions.into_iter().map(|tx| tx.into_inner()).collect())
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@ -47,19 +47,19 @@ impl TransactionSigned {
|
|||||||
fn to_reth_transaction(&self) -> TxSigned {
|
fn to_reth_transaction(&self) -> TxSigned {
|
||||||
match self.transaction.clone() {
|
match self.transaction.clone() {
|
||||||
Transaction::Legacy(tx) => {
|
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) => {
|
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) => {
|
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) => {
|
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) => {
|
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);
|
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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user