Skip to content

Commit 563651f

Browse files
committed
migrate rollup
1 parent eb1aebd commit 563651f

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

Cargo.lock

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

rollup/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license.workspace = true
88
[dependencies]
99
# reth
1010
reth-chainspec.workspace = true
11+
reth-evm.workspace = true
1112
reth-execution-errors.workspace = true
1213
reth-execution-types.workspace = true
1314
reth-exex.workspace = true

rollup/src/execution.rs

+36-30
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ use alloy_consensus::{Blob, SidecarCoder, SimpleCoder, Transaction};
33
use alloy_eips::{
44
eip1559::INITIAL_BASE_FEE, eip2718::Decodable2718, eip4844::kzg_to_versioned_hash,
55
};
6-
use alloy_primitives::{keccak256, Address, Bytes, B256, U256};
6+
use alloy_primitives::{keccak256, Bytes, B256, U256};
77
use alloy_rlp::Decodable as _;
88
use reth::{
99
api::Block as _, core::primitives::SignedTransaction, transaction_pool::TransactionPool,
1010
};
11+
use reth_evm::Evm;
1112
use reth_execution_errors::BlockValidationError;
1213
use reth_node_api::ConfigureEvm;
1314
use reth_node_ethereum::{evm::EthEvm, EthEvmConfig};
1415
use reth_primitives::{
15-
Block, BlockBody, EthereumHardfork, Header, Receipt, RecoveredBlock, TransactionSigned, TxType,
16+
Block, BlockBody, EthereumHardfork, Header, Receipt, Recovered, RecoveredBlock,
17+
TransactionSigned, TxType,
1618
};
1719
use reth_revm::{
18-
context::result::{ExecutionResult, ResultAndState},
20+
context::result::{EVMError, ExecutionResult, ResultAndState},
1921
db::{states::bundle_state::BundleRetention, BundleState, StateBuilder},
2022
inspector::NoOpInspector,
21-
DatabaseCommit, Inspector, State,
23+
DatabaseCommit, State,
2224
};
2325
use reth_tracing::tracing::debug;
24-
use std::ops::DerefMut;
2526

2627
/// Execute a rollup block and return (block with recovered senders)[RecoveredBlock], (bundle
2728
/// state)[BundleState] and list of (receipts)[Receipt].
@@ -56,7 +57,7 @@ pub async fn execute_block<Pool: TransactionPool>(
5657
Block { header, body: BlockBody { transactions: executed_txs, ..Default::default() } }
5758
.try_into_recovered()?;
5859

59-
let bundle = evm.deref_mut().db_mut().take_bundle();
60+
let bundle = evm.db_mut().take_bundle();
6061

6162
Ok((block, bundle, receipts, results))
6263
}
@@ -104,7 +105,7 @@ async fn decode_transactions<Pool: TransactionPool>(
104105
tx: &TransactionSigned,
105106
block_data: Bytes,
106107
block_data_hash: B256,
107-
) -> eyre::Result<Vec<(TransactionSigned, Address)>> {
108+
) -> eyre::Result<Vec<Recovered<TransactionSigned>>> {
108109
// Get raw transactions either from the blobs, or directly from the block data
109110
let raw_transactions = if matches!(tx.tx_type(), TxType::Eip4844) {
110111
let blobs: Vec<_> = if let Some(sidecar) = pool.get_blob(*tx.hash())? {
@@ -161,7 +162,7 @@ async fn decode_transactions<Pool: TransactionPool>(
161162
let tx = TransactionSigned::decode_2718(&mut &raw_transaction[..])?;
162163
if tx.chain_id() == Some(CHAIN_ID) {
163164
let sender = tx.recover_signer()?;
164-
transactions.push((tx, sender));
165+
transactions.push(tx.with_signer(sender));
165166
}
166167
}
167168

@@ -170,10 +171,10 @@ async fn decode_transactions<Pool: TransactionPool>(
170171

171172
/// Execute transactions and return the list of executed transactions, receipts and
172173
/// execution results.
173-
fn execute_transactions<DB: reth_revm::Database>(
174+
fn execute_transactions<DB: reth_evm::Database>(
174175
evm: &mut EthEvm<State<DB>, NoOpInspector>,
175176
header: &Header,
176-
transactions: Vec<(TransactionSigned, Address)>,
177+
transactions: Vec<Recovered<TransactionSigned>>,
177178
) -> eyre::Result<(Vec<TransactionSigned>, Vec<Receipt>, Vec<ExecutionResult>)>
178179
where
179180
DB::Error: Send,
@@ -183,7 +184,7 @@ where
183184
let mut results = Vec::with_capacity(transactions.len());
184185
if !transactions.is_empty() {
185186
let mut cumulative_gas_used = 0;
186-
for (transaction, sender) in transactions {
187+
for transaction in transactions {
187188
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
188189
// must be no greater than the block’s gasLimit.
189190
let block_available_gas = header.gas_limit - cumulative_gas_used;
@@ -195,10 +196,7 @@ where
195196
.into());
196197
}
197198
// Execute transaction.
198-
// Fill revm structure.
199-
*evm.tx_mut() = EthEvmConfig::new(CHAIN_SPEC.clone()).tx_env(&transaction, sender);
200-
201-
let ResultAndState { result, state } = match evm.transact() {
199+
let ResultAndState { result, state } = match evm.transact(&transaction) {
202200
Ok(result) => result,
203201
Err(err) => {
204202
match err {
@@ -233,7 +231,7 @@ where
233231
});
234232

235233
// append transaction to the list of executed transactions
236-
executed_txs.push(transaction);
234+
executed_txs.push(transaction.into_inner());
237235
results.push(result);
238236
}
239237

@@ -246,15 +244,21 @@ where
246244
#[cfg(test)]
247245
mod tests {
248246
use crate::{
249-
db::Database, execute_block, Zenith::BlockHeader, CHAIN_ID, ROLLUP_SUBMITTER_ADDRESS,
247+
db::Database, execute_block, Zenith::BlockHeader, CHAIN_ID, CHAIN_SPEC,
248+
ROLLUP_SUBMITTER_ADDRESS,
250249
};
251250
use alloy_consensus::{constants::ETH_TO_WEI, SidecarBuilder, SimpleCoder, TxEip2930};
252251
use alloy_eips::eip2718::Encodable2718;
253252
use alloy_primitives::{bytes, keccak256, BlockNumber, TxKind, U256};
254253
use alloy_sol_types::{sol, SolCall};
254+
use reth_evm::{ConfigureEvm, Evm};
255+
use reth_node_ethereum::EthEvmConfig;
255256
use reth_primitives::{public_key_to_address, Block, Receipt, RecoveredBlock, Transaction};
256257
use reth_revm::{
257-
context::result::{ExecutionResult, Output},
258+
context::{
259+
result::{ExecutionResult, Output},
260+
TxEnv,
261+
},
258262
state::AccountInfo,
259263
};
260264
use reth_testing_utils::generators::{self, sign_tx_with_key_pair};
@@ -298,6 +302,7 @@ mod tests {
298302
reth_tracing::init_test_tracing();
299303

300304
let mut database = Database::new(Connection::open_in_memory()?)?;
305+
let evm_config = EthEvmConfig::new(CHAIN_SPEC.clone());
301306

302307
// Create key pair
303308
let secp = Secp256k1::new();
@@ -354,17 +359,17 @@ mod tests {
354359
.await?;
355360

356361
// Verify WETH balance
357-
let mut evm = Evm::builder()
358-
.with_db(&mut database)
359-
.with_tx_env(TxEnv {
362+
let mut evm = evm_config.evm_with_env(&mut database, Default::default());
363+
let result = evm
364+
.transact(TxEnv {
360365
caller: sender_address,
361366
gas_limit: 50_000_000,
362-
transact_to: TxKind::Call(weth_address),
367+
kind: TxKind::Call(weth_address),
363368
data: WETH::balanceOfCall::new((sender_address,)).abi_encode().into(),
364369
..Default::default()
365370
})
366-
.build();
367-
let result = evm.transact().map_err(|err| eyre::eyre!(err))?.result;
371+
.map_err(|err| eyre::eyre!(err))?
372+
.result;
368373
assert_eq!(
369374
result.output(),
370375
Some(&U256::from(0.5 * ETH_TO_WEI as f64).to_be_bytes_vec().into())
@@ -379,17 +384,18 @@ mod tests {
379384
database.revert_tip_block(U256::from(1))?;
380385

381386
// Verify WETH balance after revert
382-
let mut evm = Evm::builder()
383-
.with_db(&mut database)
384-
.with_tx_env(TxEnv {
387+
let mut evm = evm_config.evm_with_env(&mut database, Default::default());
388+
let result = evm
389+
.transact(TxEnv {
385390
caller: sender_address,
386391
gas_limit: 50_000_000,
387-
transact_to: TxKind::Call(weth_address),
392+
kind: TxKind::Call(weth_address),
388393
data: WETH::balanceOfCall::new((sender_address,)).abi_encode().into(),
389394
..Default::default()
390395
})
391-
.build();
392-
let result = evm.transact().map_err(|err| eyre::eyre!(err))?.result;
396+
.map_err(|err| eyre::eyre!(err))?
397+
.result;
398+
393399
assert_eq!(result.output(), Some(&U256::ZERO.to_be_bytes_vec().into()));
394400
drop(evm);
395401

0 commit comments

Comments
 (0)