Skip to content

Commit 8efe441

Browse files
authored
feat: use reth-ethereum-primitives (paradigmxyz#13830)
1 parent 7e972ea commit 8efe441

File tree

67 files changed

+941
-3025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+941
-3025
lines changed

Cargo.lock

+8-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/reth-bench/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ min-info-logs = ["tracing/release_max_level_info"]
9696
min-debug-logs = ["tracing/release_max_level_debug"]
9797
min-trace-logs = ["tracing/release_max_level_trace"]
9898

99-
optimism = ["reth-primitives/optimism", "reth-node-core/optimism"]
99+
optimism = ["reth-node-core/optimism"]
100100

101101
# no-op feature flag for switching between the `optimism` and default functionality in CI matrices
102102
ethereum = []

bin/reth/src/commands/debug_cmd/build_block.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ use reth_execution_types::ExecutionOutcome;
2424
use reth_fs_util as fs;
2525
use reth_node_api::{BlockTy, EngineApiMessageVersion, PayloadBuilderAttributes};
2626
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthEvmConfig, EthExecutorProvider};
27-
use reth_primitives::{EthPrimitives, SealedBlock, SealedHeader, Transaction, TransactionSigned};
28-
use reth_primitives_traits::Block as _;
27+
use reth_primitives::{
28+
transaction::SignedTransactionIntoRecoveredExt, EthPrimitives, SealedBlock, SealedHeader,
29+
Transaction, TransactionSigned,
30+
};
31+
use reth_primitives_traits::{Block as _, SignedTransaction};
2932
use reth_provider::{
3033
providers::{BlockchainProvider, ProviderNodeTypes},
3134
BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, ProviderFactory,
@@ -163,7 +166,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
163166
for tx_bytes in &self.transactions {
164167
debug!(target: "reth::cli", bytes = ?tx_bytes, "Decoding transaction");
165168
let transaction = TransactionSigned::decode(&mut &Bytes::from_str(tx_bytes)?[..])?
166-
.into_ecrecovered()
169+
.try_ecrecovered()
167170
.ok_or_else(|| eyre::eyre!("failed to recover tx"))?;
168171

169172
let encoded_length = match &transaction.transaction {
@@ -183,7 +186,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
183186
let encoded_length = pooled.encode_2718_len();
184187

185188
// insert the blob into the store
186-
blob_store.insert(transaction.hash(), sidecar)?;
189+
blob_store.insert(*transaction.tx_hash(), sidecar)?;
187190

188191
encoded_length
189192
}

crates/chain-state/src/test_utils.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::{
44
in_memory::ExecutedBlock, CanonStateNotification, CanonStateNotifications,
55
CanonStateSubscriptions,
66
};
7-
use alloy_consensus::{Header, Transaction as _, TxEip1559, EMPTY_ROOT_HASH};
7+
use alloy_consensus::{
8+
Header, SignableTransaction, Transaction as _, TxEip1559, TxReceipt, EMPTY_ROOT_HASH,
9+
};
810
use alloy_eips::{
911
eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, INITIAL_BASE_FEE},
1012
eip7685::Requests,
@@ -17,6 +19,7 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
1719
use reth_execution_types::{Chain, ExecutionOutcome};
1820
use reth_primitives::{
1921
proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root},
22+
transaction::SignedTransactionIntoRecoveredExt,
2023
BlockBody, EthPrimitives, NodePrimitives, Receipt, Receipts, RecoveredBlock, RecoveredTx,
2124
SealedBlock, SealedHeader, Transaction, TransactionSigned,
2225
};
@@ -131,7 +134,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
131134
cumulative_gas_used: (idx as u64 + 1) * MIN_TRANSACTION_GAS,
132135
..Default::default()
133136
}
134-
.with_bloom()
137+
.into_with_bloom()
135138
})
136139
.collect::<Vec<_>>();
137140

crates/engine/util/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ tracing.workspace = true
5252

5353
[features]
5454
optimism = [
55-
"reth-primitives/optimism",
5655
"reth-provider/optimism",
5756
"revm-primitives/optimism",
5857
]

crates/engine/util/src/reorg.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use reth_payload_validator::ExecutionPayloadValidator;
2121
use reth_primitives::{
2222
proofs, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts,
2323
};
24-
use reth_primitives_traits::block::Block as _;
24+
use reth_primitives_traits::{block::Block as _, SignedTransaction};
2525
use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory};
2626
use reth_revm::{
2727
database::StateProviderDatabase,
@@ -329,19 +329,19 @@ where
329329
let exec_result = match evm.transact() {
330330
Ok(result) => result,
331331
error @ Err(EVMError::Transaction(_) | EVMError::Header(_)) => {
332-
trace!(target: "engine::stream::reorg", hash = %tx.hash(), ?error, "Error executing transaction from next block");
332+
trace!(target: "engine::stream::reorg", hash = %tx.tx_hash(), ?error, "Error executing transaction from next block");
333333
continue
334334
}
335335
// Treat error as fatal
336336
Err(error) => {
337337
return Err(RethError::Execution(BlockExecutionError::Validation(
338-
BlockValidationError::EVM { hash: tx.hash(), error: Box::new(error) },
338+
BlockValidationError::EVM { hash: *tx.tx_hash(), error: Box::new(error) },
339339
)))
340340
}
341341
};
342342
evm.db_mut().commit(exec_result.state);
343343

344-
if let Some(blob_tx) = tx.transaction.as_eip4844() {
344+
if let Some(blob_tx) = tx.as_eip4844() {
345345
sum_blob_gas_used += blob_tx.blob_gas();
346346
versioned_hashes.extend(blob_tx.blob_versioned_hashes.clone());
347347
}

crates/ethereum/evm/src/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use reth_evm::{
2222
ConfigureEvm, TxEnvOverrides,
2323
};
2424
use reth_primitives::{EthPrimitives, Receipt, RecoveredBlock};
25-
use reth_primitives_traits::BlockBody;
25+
use reth_primitives_traits::{BlockBody, SignedTransaction};
2626
use reth_revm::db::State;
2727
use revm_primitives::{
2828
db::{Database, DatabaseCommit},

crates/ethereum/payload/src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1010
#![allow(clippy::useless_let_if_seq)]
1111

12-
use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
12+
use alloy_consensus::{Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH};
1313
use alloy_eips::{
1414
eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, eip7840::BlobParams,
1515
merge::BEACON_NONCE,
@@ -33,7 +33,7 @@ use reth_primitives::{
3333
Block, BlockBody, EthereumHardforks, InvalidTransactionError, Receipt, RecoveredBlock,
3434
TransactionSigned,
3535
};
36-
use reth_primitives_traits::Block as _;
36+
use reth_primitives_traits::{Block as _, SignedTransaction};
3737
use reth_revm::database::StateProviderDatabase;
3838
use reth_storage_api::StateProviderFactory;
3939
use reth_transaction_pool::{
@@ -250,7 +250,7 @@ where
250250

251251
// There's only limited amount of blob space available per block, so we need to check if
252252
// the EIP-4844 can still fit in the block
253-
if let Some(blob_tx) = tx.transaction.as_eip4844() {
253+
if let Some(blob_tx) = tx.as_eip4844() {
254254
let tx_blob_gas = blob_tx.blob_gas();
255255
if sum_blob_gas_used + tx_blob_gas > MAX_DATA_GAS_PER_BLOCK {
256256
// we can't fit this _blob_ transaction into the block, so we mark it as
@@ -306,7 +306,7 @@ where
306306
evm.db_mut().commit(state);
307307

308308
// add to the total blob gas used if the transaction successfully executed
309-
if let Some(blob_tx) = tx.transaction.as_eip4844() {
309+
if let Some(blob_tx) = tx.as_eip4844() {
310310
let tx_blob_gas = blob_tx.blob_gas();
311311
sum_blob_gas_used += tx_blob_gas;
312312

@@ -332,9 +332,8 @@ where
332332
}));
333333

334334
// update add to total fees
335-
let miner_fee = tx
336-
.effective_tip_per_gas(Some(base_fee))
337-
.expect("fee is always valid; execution succeeded");
335+
let miner_fee =
336+
tx.effective_tip_per_gas(base_fee).expect("fee is always valid; execution succeeded");
338337
total_fees += U256::from(miner_fee) * U256::from(gas_used);
339338

340339
// append sender and transaction to the respective lists
@@ -419,7 +418,7 @@ where
419418
// grab the blob sidecars from the executed txs
420419
blob_sidecars = pool
421420
.get_all_blobs_exact(
422-
executed_txs.iter().filter(|tx| tx.is_eip4844()).map(|tx| tx.hash()).collect(),
421+
executed_txs.iter().filter(|tx| tx.is_eip4844()).map(|tx| *tx.tx_hash()).collect(),
423422
)
424423
.map_err(PayloadBuilderError::other)?;
425424

crates/ethereum/primitives/Cargo.toml

+22-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ reth-zstd-compressors = { workspace = true, optional = true }
2020
# ethereum
2121
alloy-eips.workspace = true
2222
alloy-primitives.workspace = true
23+
alloy-network = { workspace = true, optional = true }
2324
alloy-consensus = { workspace = true, features = ["serde"] }
25+
alloy-serde = { workspace = true, optional = true }
2426
alloy-rlp.workspace = true
27+
alloy-rpc-types = { workspace = true, optional = true }
28+
revm-primitives.workspace = true
2529

2630
# misc
2731
arbitrary = { workspace = true, optional = true, features = ["derive"] }
@@ -34,16 +38,20 @@ serde.workspace = true
3438

3539
[dev-dependencies]
3640
arbitrary.workspace = true
41+
bincode.workspace = true
3742
proptest.workspace = true
3843
proptest-arbitrary-interop.workspace = true
3944
rand.workspace = true
40-
reth-codecs.workspace = true
45+
reth-codecs = { workspace = true, features = ["test-utils"] }
46+
reth-testing-utils.workspace = true
4147
reth-zstd-compressors.workspace = true
42-
secp256k1.workspace = true
48+
secp256k1 = { workspace = true, features = ["rand"] }
4349
test-fuzz.workspace = true
50+
alloy-consensus = { workspace = true, features = ["serde", "arbitrary"] }
4451

4552
[features]
4653
default = ["std"]
54+
alloy-compat = ["dep:alloy-network", "dep:alloy-serde", "dep:alloy-rpc-types"]
4755
std = [
4856
"alloy-consensus/std",
4957
"alloy-primitives/std",
@@ -54,7 +62,9 @@ std = [
5462
"alloy-eips/std",
5563
"derive_more/std",
5664
"secp256k1?/std",
57-
"once_cell/std"
65+
"once_cell/std",
66+
"revm-primitives/std",
67+
"alloy-serde?/std"
5868
]
5969
reth-codec = [
6070
"std",
@@ -70,5 +80,13 @@ arbitrary = [
7080
"alloy-primitives/arbitrary",
7181
"reth-codecs?/arbitrary",
7282
"reth-primitives-traits/arbitrary",
73-
"alloy-eips/arbitrary"
83+
"alloy-eips/arbitrary",
84+
"revm-primitives/arbitrary",
85+
"alloy-rpc-types?/arbitrary",
86+
"alloy-serde?/arbitrary"
87+
]
88+
serde-bincode-compat = [
89+
"alloy-consensus/serde-bincode-compat",
90+
"alloy-eips/serde-bincode-compat",
91+
"reth-primitives-traits/serde-bincode-compat"
7492
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! Common conversions from alloy types.
2+
3+
use crate::{Transaction, TransactionSigned};
4+
use alloc::string::ToString;
5+
use alloy_consensus::TxEnvelope;
6+
use alloy_network::{AnyRpcTransaction, AnyTxEnvelope};
7+
use alloy_serde::WithOtherFields;
8+
9+
impl TryFrom<AnyRpcTransaction> for TransactionSigned {
10+
type Error = alloy_rpc_types::ConversionError;
11+
12+
fn try_from(tx: AnyRpcTransaction) -> Result<Self, Self::Error> {
13+
use alloy_rpc_types::ConversionError;
14+
15+
let WithOtherFields { inner: tx, other: _ } = tx;
16+
17+
#[allow(unreachable_patterns)]
18+
let (transaction, signature, hash) = match tx.inner {
19+
AnyTxEnvelope::Ethereum(TxEnvelope::Legacy(tx)) => {
20+
let (tx, signature, hash) = tx.into_parts();
21+
(Transaction::Legacy(tx), signature, hash)
22+
}
23+
AnyTxEnvelope::Ethereum(TxEnvelope::Eip2930(tx)) => {
24+
let (tx, signature, hash) = tx.into_parts();
25+
(Transaction::Eip2930(tx), signature, hash)
26+
}
27+
AnyTxEnvelope::Ethereum(TxEnvelope::Eip1559(tx)) => {
28+
let (tx, signature, hash) = tx.into_parts();
29+
(Transaction::Eip1559(tx), signature, hash)
30+
}
31+
AnyTxEnvelope::Ethereum(TxEnvelope::Eip4844(tx)) => {
32+
let (tx, signature, hash) = tx.into_parts();
33+
(Transaction::Eip4844(tx.into()), signature, hash)
34+
}
35+
AnyTxEnvelope::Ethereum(TxEnvelope::Eip7702(tx)) => {
36+
let (tx, signature, hash) = tx.into_parts();
37+
(Transaction::Eip7702(tx), signature, hash)
38+
}
39+
_ => return Err(ConversionError::Custom("unknown transaction type".to_string())),
40+
};
41+
42+
Ok(Self { transaction, signature, hash: hash.into() })
43+
}
44+
}

crates/ethereum/primitives/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ pub use receipt::*;
1616

1717
mod transaction;
1818
pub use transaction::*;
19+
20+
#[cfg(feature = "alloy-compat")]
21+
mod alloy_compat;

0 commit comments

Comments
 (0)