Skip to content

Commit 63c5b1f

Browse files
committed
fix(node): adapt to reth v2.0.0 breaking changes
- Remove reth-primitives dependency (deleted upstream) - Remove PayloadBuilderAttributes trait (merged into PayloadAttributes) - Refactor EvolveEnginePayloadBuilderAttributes to impl PayloadAttributes - Change PayloadBuilder::Attributes to EvolveEnginePayloadAttributes - Migrate PayloadConfig to include payload_id field - Migrate BuildArguments to include execution_cache and trie_handle - Rename TransactionEnv to TransactionEnvMut (alloy-evm) - Update TryIntoTxEnv to new 3-generic-param signature - Add consensus_ref to PoolTransaction impl - Fix build_with_tasks generic args (3 → 2) - Add slot_num field to BlockEnv initializers - Remove set_state_clear_flag (handled by EVM spec) - Update BlockBuilder::finish to accept precomputed state root - Fix receipt conversion (replace into_rpc with map_logs) - Fix Withdrawals/Cow type mismatches - Rename extra_data_bytes to extra_data - Fix reth_primitives imports to alloy_consensus/reth_primitives_traits - Update BlockExecutorFactory::create_executor to use StateDB bound - Also remove reth-primitives from tests/Cargo.toml
1 parent efaf0fc commit 63c5b1f

11 files changed

Lines changed: 1217 additions & 146 deletions

File tree

Cargo.lock

Lines changed: 1052 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ reth-ethereum = { workspace = true, features = ["node", "cli", "pool"] }
2323
reth-ethereum-forks.workspace = true
2424
reth-ethereum-payload-builder.workspace = true
2525
reth-payload-primitives.workspace = true
26-
reth-primitives.workspace = true
2726
reth-primitives-traits.workspace = true
2827
reth-node-api.workspace = true
2928
reth-provider = { workspace = true, features = ["test-utils"] }

crates/node/src/attributes.rs

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
use alloy_consensus::BlockHeader;
2-
use alloy_eips::{eip4895::Withdrawals, Decodable2718};
2+
use alloy_eips::Decodable2718;
33
use alloy_primitives::{Address, Bytes, B256};
44
use alloy_rpc_types::{
55
engine::{PayloadAttributes as RpcPayloadAttributes, PayloadId},
66
Withdrawal,
77
};
88
use reth_chainspec::EthereumHardforks;
99
use reth_engine_local::payload::LocalPayloadAttributesBuilder;
10-
use reth_ethereum::node::api::payload::{PayloadAttributes, PayloadBuilderAttributes};
11-
use reth_payload_builder::EthPayloadBuilderAttributes;
12-
use reth_payload_primitives::PayloadAttributesBuilder;
10+
use reth_ethereum::node::api::payload::PayloadAttributes;
11+
use reth_payload_primitives::{payload_id, PayloadAttributesBuilder};
1312
use reth_primitives_traits::SealedHeader;
1413
use serde::{Deserialize, Serialize};
1514

16-
use crate::tracing_ext::RecordDurationOnDrop;
17-
use tracing::{info, instrument};
18-
1915
use crate::error::EvolveEngineError;
16+
use crate::tracing_ext::RecordDurationOnDrop;
2017
use ev_primitives::TransactionSigned;
18+
use tracing::{info, instrument};
2119

2220
/// Evolve payload attributes that support passing transactions via Engine API.
2321
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -33,6 +31,10 @@ pub struct EvolveEnginePayloadAttributes {
3331
}
3432

3533
impl PayloadAttributes for EvolveEnginePayloadAttributes {
34+
fn payload_id(&self, parent_hash: &B256) -> PayloadId {
35+
payload_id(parent_hash, &self.inner)
36+
}
37+
3638
fn timestamp(&self) -> u64 {
3739
self.inner.timestamp()
3840
}
@@ -57,33 +59,37 @@ impl From<RpcPayloadAttributes> for EvolveEnginePayloadAttributes {
5759
}
5860

5961
/// Evolve payload builder attributes.
60-
#[derive(Clone, Debug, PartialEq, Eq)]
62+
///
63+
/// In reth v2.0.0, `PayloadBuilderAttributes` was removed. This type now implements
64+
/// `PayloadAttributes` directly and stores the decoded transactions from the Engine API.
65+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6166
pub struct EvolveEnginePayloadBuilderAttributes {
62-
/// Ethereum payload builder attributes.
63-
pub ethereum_attributes: EthPayloadBuilderAttributes,
67+
/// The inner RPC payload attributes.
68+
#[serde(flatten)]
69+
pub inner: RpcPayloadAttributes,
70+
/// Parent block hash.
71+
pub parent: B256,
6472
/// Decoded transactions from the Engine API.
73+
#[serde(skip)]
6574
pub transactions: Vec<TransactionSigned>,
6675
/// Gas limit for the payload.
76+
#[serde(rename = "gasLimit")]
6777
pub gas_limit: Option<u64>,
6878
}
6979

70-
impl PayloadBuilderAttributes for EvolveEnginePayloadBuilderAttributes {
71-
type RpcPayloadAttributes = EvolveEnginePayloadAttributes;
72-
type Error = EvolveEngineError;
73-
74-
#[instrument(skip(parent, attributes, _version), fields(
80+
impl EvolveEnginePayloadBuilderAttributes {
81+
/// Creates builder attributes from RPC attributes with decoded transactions.
82+
#[instrument(skip(parent, attributes), fields(
7583
parent_hash = %parent,
7684
raw_tx_count = attributes.transactions.as_ref().map_or(0, |t| t.len()),
7785
gas_limit = ?attributes.gas_limit,
7886
duration_ms = tracing::field::Empty,
7987
))]
80-
fn try_new(
88+
pub fn try_new(
8189
parent: B256,
8290
attributes: EvolveEnginePayloadAttributes,
83-
_version: u8,
84-
) -> Result<Self, Self::Error> {
91+
) -> Result<Self, EvolveEngineError> {
8592
let _duration = RecordDurationOnDrop::new();
86-
let ethereum_attributes = EthPayloadBuilderAttributes::new(parent, attributes.inner);
8793

8894
// Decode transactions from bytes if provided.
8995
let transactions = attributes
@@ -102,47 +108,54 @@ impl PayloadBuilderAttributes for EvolveEnginePayloadBuilderAttributes {
102108
);
103109

104110
Ok(Self {
105-
ethereum_attributes,
111+
inner: attributes.inner,
112+
parent,
106113
transactions,
107114
gas_limit: attributes.gas_limit,
108115
})
109116
}
110117

111-
fn payload_id(&self) -> PayloadId {
112-
self.ethereum_attributes.id
118+
/// Returns the parent block hash.
119+
pub fn parent(&self) -> B256 {
120+
self.parent
113121
}
114122

115-
fn parent(&self) -> B256 {
116-
self.ethereum_attributes.parent
123+
/// Returns the suggested fee recipient.
124+
pub fn suggested_fee_recipient(&self) -> Address {
125+
self.inner.suggested_fee_recipient
117126
}
118127

119-
fn timestamp(&self) -> u64 {
120-
self.ethereum_attributes.timestamp
128+
/// Returns the prev randao value.
129+
pub fn prev_randao(&self) -> B256 {
130+
self.inner.prev_randao
121131
}
132+
}
122133

123-
fn parent_beacon_block_root(&self) -> Option<B256> {
124-
self.ethereum_attributes.parent_beacon_block_root
134+
impl PayloadAttributes for EvolveEnginePayloadBuilderAttributes {
135+
fn payload_id(&self, parent_hash: &B256) -> PayloadId {
136+
payload_id(parent_hash, &self.inner)
125137
}
126138

127-
fn suggested_fee_recipient(&self) -> Address {
128-
self.ethereum_attributes.suggested_fee_recipient
139+
fn timestamp(&self) -> u64 {
140+
self.inner.timestamp
129141
}
130142

131-
fn prev_randao(&self) -> B256 {
132-
self.ethereum_attributes.prev_randao
143+
fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
144+
self.inner.withdrawals.as_ref()
133145
}
134146

135-
fn withdrawals(&self) -> &Withdrawals {
136-
&self.ethereum_attributes.withdrawals
147+
fn parent_beacon_block_root(&self) -> Option<B256> {
148+
self.inner.parent_beacon_block_root
137149
}
138150
}
139151

140-
impl From<EthPayloadBuilderAttributes> for EvolveEnginePayloadBuilderAttributes {
141-
fn from(eth: EthPayloadBuilderAttributes) -> Self {
152+
impl From<EvolveEnginePayloadAttributes> for EvolveEnginePayloadBuilderAttributes {
153+
fn from(attrs: EvolveEnginePayloadAttributes) -> Self {
142154
Self {
143-
ethereum_attributes: eth,
155+
inner: attrs.inner,
156+
parent: B256::ZERO,
144157
transactions: Vec::new(),
145-
gas_limit: None,
158+
gas_limit: attrs.gas_limit,
146159
}
147160
}
148161
}
@@ -206,7 +219,7 @@ mod tests {
206219
};
207220

208221
// we only care that the span was created with the right fields.
209-
let _ = EvolveEnginePayloadBuilderAttributes::try_new(parent, attrs, 3);
222+
let _ = EvolveEnginePayloadBuilderAttributes::try_new(parent, attrs);
210223

211224
let span = collector
212225
.find_span("try_new")

crates/node/src/builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use reth_evm::{
1212
ConfigureEvm, NextBlockEnvAttributes,
1313
};
1414
use reth_payload_builder_primitives::PayloadBuilderError;
15-
use reth_primitives::{transaction::SignedTransaction, Header, SealedHeader};
15+
use alloy_consensus::Header;
16+
use reth_primitives_traits::{SealedHeader, SignedTransaction};
1617
use reth_primitives_traits::SealedBlock;
1718
use reth_provider::{HeaderProvider, StateProviderFactory};
1819
use reth_revm::{database::StateProviderDatabase, State};
@@ -182,7 +183,7 @@ where
182183
trie_updates: _,
183184
block,
184185
} = builder
185-
.finish(&state_provider)
186+
.finish(&state_provider, None)
186187
.map_err(PayloadBuilderError::other)?;
187188

188189
let sealed_block = block.sealed_block().clone();
@@ -240,7 +241,7 @@ mod tests {
240241
use alloy_primitives::B256;
241242
use evolve_ev_reth::EvolvePayloadAttributes;
242243
use reth_chainspec::ChainSpecBuilder;
243-
use reth_primitives::Header;
244+
use alloy_consensus::Header;
244245
use reth_provider::test_utils::MockEthProvider;
245246

246247
#[tokio::test]
@@ -373,7 +374,7 @@ mod tests {
373374
input: Bytes::default(),
374375
};
375376
let signed = alloy_consensus::Signed::new_unhashed(
376-
reth_primitives::Transaction::Legacy(legacy_tx),
377+
reth_ethereum_primitives::Transaction::Legacy(legacy_tx),
377378
Signature::test_signature(),
378379
);
379380
let tx = EvTxEnvelope::Ethereum(reth_ethereum_primitives::TransactionSigned::from(signed));

crates/node/src/evm_executor.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use alloy_evm::{
1515
spec::{EthExecutorSpec, EthSpec},
1616
EthBlockExecutionCtx,
1717
},
18-
Database, EthEvmFactory, Evm, EvmFactory, FromRecoveredTx, FromTxWithEncoded, RecoveredTx,
18+
EthEvmFactory, Evm, EvmFactory, FromRecoveredTx, FromTxWithEncoded, RecoveredTx,
1919
};
2020
use alloy_primitives::Log;
2121
use ev_primitives::{Receipt, TransactionSigned};
2222
use reth_ethereum_forks::EthereumHardfork;
2323
use reth_revm::{
2424
context_interface::block::Block as BlockEnvTr,
2525
database_interface::DatabaseCommitExt,
26-
revm::{context_interface::result::ResultAndState, database::State, DatabaseCommit, Inspector},
26+
revm::{context_interface::result::ResultAndState, DatabaseCommit, Inspector},
2727
};
2828

2929
/// Execution result wrapper used by the EV block executor.
@@ -46,6 +46,10 @@ impl<H, T> alloy_evm::block::TxResult for EvTxResult<H, T> {
4646
fn result(&self) -> &ResultAndState<Self::HaltReason> {
4747
&self.result
4848
}
49+
50+
fn into_result(self) -> ResultAndState<Self::HaltReason> {
51+
self.result
52+
}
4953
}
5054

5155
/// Receipt builder that works with Ev transaction envelopes.
@@ -110,11 +114,10 @@ where
110114
}
111115
}
112116

113-
impl<'db, DB, E, Spec, R> BlockExecutor for EvBlockExecutor<'_, E, Spec, R>
117+
impl<E, Spec, R> BlockExecutor for EvBlockExecutor<'_, E, Spec, R>
114118
where
115-
DB: Database + 'db,
116119
E: Evm<
117-
DB = &'db mut State<DB>,
120+
DB: alloy_evm::block::state::StateDB,
118121
Tx: FromRecoveredTx<R::Transaction> + FromTxWithEncoded<R::Transaction>,
119122
>,
120123
Spec: EthExecutorSpec,
@@ -127,11 +130,6 @@ where
127130
EvTxResult<<Self::Evm as Evm>::HaltReason, <R::Transaction as TransactionEnvelope>::TxType>;
128131

129132
fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError> {
130-
let state_clear_flag = self
131-
.spec
132-
.is_spurious_dragon_active_at_block(self.evm.block().number().saturating_to());
133-
self.evm.db_mut().set_state_clear_flag(state_clear_flag);
134-
135133
self.system_caller
136134
.apply_blockhashes_contract_call(self.ctx.parent_hash, &mut self.evm)?;
137135
self.system_caller
@@ -350,12 +348,12 @@ where
350348

351349
fn create_executor<'a, DB, I>(
352350
&'a self,
353-
evm: EvmF::Evm<&'a mut State<DB>, I>,
351+
evm: EvmF::Evm<DB, I>,
354352
ctx: Self::ExecutionCtx<'a>,
355353
) -> impl BlockExecutorFor<'a, Self, DB, I>
356354
where
357-
DB: Database + 'a,
358-
I: Inspector<EvmF::Context<&'a mut State<DB>>> + 'a,
355+
DB: alloy_evm::block::state::StateDB + 'a,
356+
I: Inspector<EvmF::Context<DB>> + 'a,
359357
{
360358
EvBlockExecutor::new(evm, ctx, self.spec.clone(), self.receipt_builder.clone())
361359
}

crates/node/src/executor.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use reth_ethereum::{
2121
use reth_ethereum_forks::Hardforks;
2222
use reth_evm::{
2323
ConfigureEngineEvm, ConfigureEvm, EvmEnv, EvmEnvFor, ExecutableTxIterator, ExecutionCtxFor,
24-
NextBlockEnvAttributes, TransactionEnv,
24+
NextBlockEnvAttributes, TransactionEnvMut,
2525
};
2626
use reth_node_builder::PayloadBuilderConfig;
2727
use reth_primitives_traits::{
@@ -96,7 +96,7 @@ impl<ChainSpec, EvmF> ConfigureEvm for EvEvmConfig<ChainSpec, EvmF>
9696
where
9797
ChainSpec: EthExecutorSpec + EthChainSpec<Header = Header> + Hardforks + 'static,
9898
EvmF: reth_evm::EvmFactory<
99-
Tx: TransactionEnv,
99+
Tx: TransactionEnvMut,
100100
Spec = SpecId,
101101
BlockEnv = BlockEnv,
102102
Precompiles = reth_evm::precompiles::PrecompilesMap,
@@ -171,6 +171,7 @@ where
171171
gas_limit: header.gas_limit,
172172
basefee: header.base_fee_per_gas.unwrap_or_default(),
173173
blob_excess_gas_and_price,
174+
slot_num: 0,
174175
};
175176

176177
Ok(EvmEnv { cfg_env, block_env })
@@ -247,6 +248,7 @@ where
247248
gas_limit,
248249
basefee: basefee.unwrap_or_default(),
249250
blob_excess_gas_and_price,
251+
slot_num: 0,
250252
};
251253

252254
Ok(EvmEnv {
@@ -268,7 +270,7 @@ where
268270
.body()
269271
.withdrawals
270272
.as_ref()
271-
.map(std::borrow::Cow::Borrowed),
273+
.map(|w| std::borrow::Cow::Borrowed(w.as_slice())),
272274
extra_data: block.header().extra_data.clone(),
273275
})
274276
}
@@ -283,7 +285,9 @@ where
283285
parent_hash: parent.hash(),
284286
parent_beacon_block_root: attributes.parent_beacon_block_root,
285287
ommers: &[],
286-
withdrawals: attributes.withdrawals.map(std::borrow::Cow::Owned),
288+
withdrawals: attributes
289+
.withdrawals
290+
.map(|w| std::borrow::Cow::Owned(w.into_inner())),
287291
extra_data: attributes.extra_data,
288292
})
289293
}
@@ -293,7 +297,7 @@ impl<ChainSpec, EvmF> ConfigureEngineEvm<ExecutionData> for EvEvmConfig<ChainSpe
293297
where
294298
ChainSpec: EthExecutorSpec + EthChainSpec<Header = Header> + Hardforks + 'static,
295299
EvmF: reth_evm::EvmFactory<
296-
Tx: TransactionEnv + FromRecoveredTx<EvTxEnvelope> + FromTxWithEncoded<EvTxEnvelope>,
300+
Tx: TransactionEnvMut + FromRecoveredTx<EvTxEnvelope> + FromTxWithEncoded<EvTxEnvelope>,
297301
Spec = SpecId,
298302
BlockEnv = BlockEnv,
299303
Precompiles = reth_evm::precompiles::PrecompilesMap,
@@ -350,6 +354,7 @@ where
350354
gas_limit: payload.payload.gas_limit(),
351355
basefee: payload.payload.saturated_base_fee_per_gas(),
352356
blob_excess_gas_and_price,
357+
slot_num: 0,
353358
};
354359

355360
Ok(EvmEnv { cfg_env, block_env })
@@ -448,7 +453,7 @@ where
448453
);
449454

450455
Ok(EvEvmConfig::new_with_evm_factory(chain_spec, factory)
451-
.with_extra_data(ctx.payload_builder_config().extra_data_bytes()))
456+
.with_extra_data(ctx.payload_builder_config().extra_data()))
452457
}
453458

454459
/// Thin wrapper so we can plug the EV executor into the node components builder.

crates/node/src/node.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::sync::Arc;
2626
use tracing::info;
2727

2828
use crate::{
29-
attributes::{EvolveEnginePayloadAttributes, EvolveEnginePayloadBuilderAttributes},
29+
attributes::EvolveEnginePayloadAttributes,
3030
executor::EvolveExecutorBuilder,
3131
payload_service::EvolvePayloadBuilderBuilder,
3232
payload_types::EvBuiltPayload,
@@ -44,7 +44,6 @@ impl PayloadTypes for EvolveEngineTypes {
4444
type ExecutionData = ExecutionData;
4545
type BuiltPayload = EvBuiltPayload;
4646
type PayloadAttributes = EvolveEnginePayloadAttributes;
47-
type PayloadBuilderAttributes = EvolveEnginePayloadBuilderAttributes;
4847

4948
fn block_to_payload(
5049
block: SealedBlock<

0 commit comments

Comments
 (0)