Skip to content

Commit 091a53f

Browse files
authored
chore: update reth (#416)
1 parent 49a0fe5 commit 091a53f

32 files changed

Lines changed: 2327 additions & 2105 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 88 additions & 94 deletions
Large diffs are not rendered by default.

crates/flashblocks/builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ op-alloy-network.workspace = true
7575
alloy-signer-local.workspace = true
7676
alloy-sol-types.workspace = true
7777
alloy-trie.workspace = true
78-
bon.workspace = true
78+
bon.workspace = true

crates/flashblocks/builder/src/access_list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ impl FlashblockAccessListConstruction {
7272
where
7373
F: FnOnce(&mut AccountChangesConstruction),
7474
{
75-
let mut entry = self
76-
.changes
77-
.entry(address)
78-
.or_insert_with(AccountChangesConstruction::default);
75+
let mut entry = self.changes.entry(address).or_default();
7976

8077
f(&mut entry);
8178
}

crates/flashblocks/builder/src/bal_executor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ where
396396
.executed_block()
397397
.ok_or(BalExecutorError::MissingExecutedBlock)?
398398
.execution_output
399-
.bundle
399+
.state
400400
.clone();
401401

402402
let fees = value.fees();
@@ -410,9 +410,9 @@ where
410410

411411
let receipts: Vec<_> = executed_block
412412
.execution_output
413-
.receipts()
413+
.result
414+
.receipts
414415
.iter()
415-
.flatten()
416416
.cloned()
417417
.enumerate()
418418
.map(|(index, r)| (index as BlockAccessIndex, r))

crates/flashblocks/builder/src/bal_validator.rs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use flashblocks_primitives::{
1313
primitives::ExecutionPayloadFlashblockDeltaV1,
1414
};
1515
use op_alloy_consensus::OpReceipt;
16-
use rayon::iter::{IntoParallelIterator, ParallelIterator};
16+
use rayon::iter::IntoParallelIterator;
1717
use reth::revm::database::StateProviderDatabase;
1818
use reth_primitives::transaction::SignedTransaction;
1919

@@ -31,7 +31,7 @@ use reth_optimism_evm::{OpBlockAssembler, OpEvmConfig, OpRethReceiptBuilder};
3131
use reth_optimism_node::OpBuiltPayload;
3232
use reth_optimism_primitives::{OpPrimitives, OpTransactionSigned};
3333
use reth_primitives::{Recovered, RecoveredBlock, SealedHeader};
34-
use reth_provider::{ExecutionOutcome, StateProvider};
34+
use reth_provider::{BlockExecutionOutput, StateProvider, StateProviderFactory};
3535
use reth_trie_common::{HashedPostState, KeccakKeyHasher, updates::TrieUpdates};
3636
use revm::{
3737
DatabaseRef,
@@ -72,7 +72,7 @@ where
7272
{
7373
pub fn validate(
7474
&self,
75-
state_provider: Arc<dyn StateProvider>,
75+
client: impl StateProviderFactory + Clone,
7676
diff: ExecutionPayloadFlashblockDeltaV1,
7777
parent: &SealedHeader<Header>,
7878
payload_id: PayloadId,
@@ -86,7 +86,10 @@ where
8686
.map_err(BalExecutorError::from)?;
8787

8888
// 1. Setup database layers for the base evm/executor
89-
let state_provider_database = StateProviderDatabase::new(state_provider.clone());
89+
let state_provider_ref = client
90+
.state_by_block_hash(parent.hash())
91+
.map_err(BalExecutorError::other)?;
92+
let state_provider_database = StateProviderDatabase::new(state_provider_ref.as_ref());
9093
let block_access_index = access_list.min_tx_index;
9194

9295
// 2. Create channel for state root computation
@@ -112,11 +115,14 @@ where
112115
database.set_index(block_access_index);
113116

114117
let bundle_clone = bundle_state.clone();
115-
let state_provider_clone = state_provider.clone();
118+
119+
let state_provider = client
120+
.state_by_block_hash(parent.hash())
121+
.map_err(BalExecutorError::other)?;
116122

117123
// 3. Spawn the state root computation in a separate thread
118124
rayon::spawn(move || {
119-
let result = compute_state_root(state_provider_clone.clone(), &bundle_clone.state);
125+
let result = compute_state_root(state_provider.into(), &bundle_clone.state);
120126
let _ = state_root_sender.send(result);
121127
});
122128

@@ -139,15 +145,19 @@ where
139145
bundle_state.clone().into(),
140146
self.committed_state.transactions_iter().cloned().collect(),
141147
self.chain_spec.clone(),
142-
temporal_db_factory,
148+
&temporal_db_factory,
143149
state_root_receiver,
144150
self.evm_env.clone(),
145151
(access_list.min_tx_index, access_list.max_tx_index),
146152
);
147153

154+
let state_provider = client
155+
.state_by_block_hash(parent.hash())
156+
.map_err(BalExecutorError::other)?;
157+
148158
// 4. Compute the block using BAL in parallel
149159
let (outcome, fees): (BlockBuilderOutcome<OpPrimitives>, u128) =
150-
validator.execute_block(state_provider.clone(), self.executor_transactions.clone())?;
160+
validator.execute_block(state_provider.as_ref(), self.executor_transactions.clone())?;
151161

152162
let computed_access_list = access_list_receiver
153163
.recv()
@@ -242,16 +252,14 @@ where
242252

243253
let sealed_block = Arc::new(block.sealed_block().clone());
244254

245-
let execution_outcome = ExecutionOutcome::new(
246-
bundle_state.clone(),
247-
vec![execution_result.receipts.clone()],
248-
block.number(),
249-
Vec::new(),
250-
);
255+
let execution_output = BlockExecutionOutput {
256+
state: bundle_state.clone(),
257+
result: execution_result,
258+
};
251259

252260
let executed_block: BuiltPayloadExecutedBlock<OpPrimitives> = BuiltPayloadExecutedBlock {
253261
recovered_block: Arc::new(block),
254-
execution_output: Arc::new(execution_outcome),
262+
execution_output: Arc::new(execution_output),
255263
hashed_state: either::Left(Arc::new(hashed_state)),
256264
trie_updates: either::Left(Arc::new(trie_updates)),
257265
};
@@ -285,7 +293,7 @@ pub struct ParalleExecutionResult {
285293
}
286294

287295
/// A wrapper around the [`BasicBlockBuilder`] for flashblocks.
288-
pub struct BalBlockValidator<'a, DbRef: DatabaseRef + 'static, R: OpReceiptBuilder, Evm> {
296+
pub struct BalBlockValidator<'a, DbRef: DatabaseRef + 'a, R: OpReceiptBuilder, Evm> {
289297
pub inner: BasicBlockBuilder<
290298
'a,
291299
OpBlockExecutorFactory<OpRethReceiptBuilder, OpChainSpec>,
@@ -297,15 +305,15 @@ pub struct BalBlockValidator<'a, DbRef: DatabaseRef + 'static, R: OpReceiptBuild
297305
pub access_list_sender: crossbeam_channel::Sender<FlashblockAccessList>,
298306
pub state_root_receiver:
299307
crossbeam_channel::Receiver<Result<StateRootResult, BlockExecutionError>>,
300-
pub temporal_db_factory: TemporalDbFactory<DbRef>,
308+
pub temporal_db_factory: &'a TemporalDbFactory<DbRef>,
301309
pub evm_env: EvmEnv<OpSpecId>,
302310
pub index_range: (u16, u16),
303311
}
304312

305313
impl<'a, DBRef, R, E> BalBlockValidator<'a, DBRef, R, E>
306314
where
307315
R: OpReceiptBuilder<Transaction = OpTransactionSigned, Receipt = OpReceipt>,
308-
DBRef: DatabaseRef + Clone + Send + Sync + std::fmt::Debug + 'static,
316+
DBRef: DatabaseRef + Clone + std::fmt::Debug + 'a,
309317
E: Evm<
310318
DB = ValidatorDb<'a, DBRef>,
311319
Tx = OpTransaction<TxEnv>,
@@ -322,7 +330,7 @@ where
322330
bundle_state: Arc<BundleState>,
323331
transactions: Vec<Recovered<OpTransactionSigned>>,
324332
chain_spec: Arc<OpChainSpec>,
325-
temporal_db_factory: TemporalDbFactory<DBRef>,
333+
temporal_db_factory: &'a TemporalDbFactory<DBRef>,
326334
state_root_receiver: crossbeam_channel::Receiver<
327335
Result<StateRootResult, BlockExecutionError>,
328336
>,
@@ -364,7 +372,7 @@ where
364372

365373
impl<'a, DB, R, E> BlockBuilder for BalBlockValidator<'a, DB, R, E>
366374
where
367-
DB: DatabaseRef + Clone + Send + Sync + std::fmt::Debug + 'static,
375+
DB: DatabaseRef + Clone + std::fmt::Debug + 'a,
368376
E: Evm<
369377
DB = ValidatorDb<'a, DB>,
370378
Tx = OpTransaction<TxEnv>,
@@ -466,7 +474,7 @@ where
466474

467475
impl<'a, DbRef, R, E> BalBlockValidator<'a, DbRef, R, E>
468476
where
469-
DbRef: DatabaseRef + Clone + Send + Sync + std::fmt::Debug + 'static,
477+
DbRef: DatabaseRef + Clone + std::fmt::Debug + 'a,
470478
E: Evm<
471479
DB = ValidatorDb<'a, DbRef>,
472480
Tx = OpTransaction<TxEnv>,
@@ -514,7 +522,9 @@ where
514522
// executor to finalize the block.
515523
let mut results = transactions
516524
.clone()
517-
.into_par_iter()
525+
// .into_par_iter()
526+
// TODO: get rayon to work
527+
.into_iter()
518528
.map(|(index, tx)| {
519529
let tx = tx.clone();
520530
info!(
@@ -604,7 +614,7 @@ pub fn execute_transaction<R, DBRef>(
604614
db_factory: &TemporalDbFactory<DBRef>,
605615
) -> Result<ParalleExecutionResult, BalExecutorError>
606616
where
607-
DBRef: DatabaseRef + Clone + Send + Sync + std::fmt::Debug + 'static,
617+
DBRef: DatabaseRef + Clone + std::fmt::Debug,
608618
R: OpReceiptBuilder<Receipt = OpReceipt, Transaction = OpTransactionSigned>
609619
+ Send
610620
+ Sync
@@ -628,7 +638,7 @@ where
628638
);
629639

630640
let res = executor
631-
.execute_transaction_with_commit_condition(tx.as_executable(), |_| CommitChanges::Yes)
641+
.execute_transaction_with_commit_condition(&tx, |_| CommitChanges::Yes)
632642
.map_err(BalExecutorError::BlockExecutionError);
633643

634644
trace!(
@@ -671,7 +681,7 @@ pub struct StateRootResult {
671681
}
672682

673683
pub fn compute_state_root(
674-
state_provider: Arc<dyn StateProvider>,
684+
state_provider: Arc<dyn StateProvider + Send>,
675685
bundle_state: &alloy_primitives::map::HashMap<Address, BundleAccount>,
676686
) -> Result<StateRootResult, BlockExecutionError> {
677687
// compute hashed post state

crates/flashblocks/builder/src/coordinator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ where
254254
})
255255
.call()?;
256256

257-
let state_provider = Arc::new(provider.state_by_block_hash(sealed_header.hash())?);
258257
let execution_context = OpBlockExecutionCtx {
259258
parent_hash: base.parent_hash,
260259
parent_beacon_block_root: Some(base.parent_beacon_block_root),
@@ -308,7 +307,7 @@ where
308307
};
309308

310309
block_validator.validate(
311-
state_provider.clone(),
310+
provider,
312311
diff.clone(),
313312
&sealed_header,
314313
*flashblock.payload_id(),
@@ -348,6 +347,7 @@ where
348347
min_base_fee: None,
349348
};
350349

350+
let state_provider = provider.state_by_block_hash(sealed_header.hash())?;
351351
let config = PayloadConfig::new(Arc::new(sealed_header), attributes);
352352
let cancel = CancelOnDrop::default();
353353

@@ -361,13 +361,13 @@ where
361361
);
362362

363363
let best = |_| BestPayloadTransactions::new(vec![].into_iter());
364-
let db = StateProviderDatabase::new(&state_provider);
364+
let db = StateProviderDatabase::new(state_provider);
365365

366366
let outcome = build(
367+
provider,
367368
best,
368369
Option::<NoopTransactionPool<EthPooledTransaction>>::None,
369370
db,
370-
state_provider.clone(),
371371
&builder_ctx,
372372
latest_payload.as_ref().map(|p| &p.0),
373373
false,

crates/flashblocks/builder/src/database/bal_builder_db.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ mod tests {
463463
// Helper function to create a simple account
464464
fn create_account(balance: U256, nonce: u64, code: Option<Bytecode>) -> AccountInfo {
465465
AccountInfo {
466+
account_id: None,
466467
balance,
467468
nonce,
468469
code_hash: code.as_ref().map(|c| c.hash_slow()).unwrap_or(KECCAK_EMPTY),
@@ -498,6 +499,7 @@ mod tests {
498499
addr,
499500
Account {
500501
info: create_account(U256::from(1), 0, None),
502+
original_info: Default::default(),
501503
status: AccountStatus::Touched,
502504
storage: Default::default(),
503505
transaction_id: 0,
@@ -511,6 +513,7 @@ mod tests {
511513
addr,
512514
Account {
513515
info: create_account(uint!(2_U256), 0, None),
516+
original_info: Default::default(),
514517
status: AccountStatus::Touched,
515518
storage: Default::default(),
516519
transaction_id: 1,
@@ -606,6 +609,7 @@ mod tests {
606609
let mut changes = HashMap::default();
607610
let new_account = Account {
608611
info: create_account(uint!(2000_U256), 5, None),
612+
original_info: Default::default(),
609613
status: AccountStatus::Touched,
610614
storage: Default::default(),
611615
transaction_id: 0,
@@ -636,6 +640,7 @@ mod tests {
636640
let mut changes = HashMap::default();
637641
let new_account = Account {
638642
info: create_account(uint!(1000_U256), 6, None),
643+
original_info: Default::default(),
639644
status: AccountStatus::Touched,
640645
storage: Default::default(),
641646
transaction_id: 0,
@@ -666,6 +671,7 @@ mod tests {
666671
let mut changes = HashMap::default();
667672
let new_account = Account {
668673
info: create_account(uint!(1000_U256), 5, Some(new_bytecode.clone())),
674+
original_info: Default::default(),
669675
status: AccountStatus::Touched,
670676
storage: Default::default(),
671677
transaction_id: 0,
@@ -709,6 +715,7 @@ mod tests {
709715

710716
let new_account = Account {
711717
info: create_account(uint!(1000_U256), 5, None),
718+
original_info: Default::default(),
712719
status: AccountStatus::Touched,
713720
storage,
714721
transaction_id: 0,
@@ -740,6 +747,7 @@ mod tests {
740747
let mut changes = HashMap::default();
741748
let new_account = Account {
742749
info: initial_account.clone(),
750+
original_info: Default::default(),
743751
status: AccountStatus::Touched,
744752
storage: Default::default(),
745753
transaction_id: 0,
@@ -770,6 +778,7 @@ mod tests {
770778
addr,
771779
Account {
772780
info: create_account(uint!(1500_U256), 0, None),
781+
original_info: Default::default(),
773782
status: AccountStatus::Touched,
774783
storage: Default::default(),
775784
transaction_id: 0,
@@ -784,6 +793,7 @@ mod tests {
784793
addr,
785794
Account {
786795
info: create_account(uint!(1500_U256), 0, None),
796+
original_info: Default::default(),
787797
status: AccountStatus::Touched,
788798
storage: Default::default(),
789799
transaction_id: 1,
@@ -812,6 +822,7 @@ mod tests {
812822
let mut changes = HashMap::default();
813823
let new_account = Account {
814824
info: create_account(uint!(1000_U256), 1, Some(bytecode.clone())),
825+
original_info: Default::default(),
815826
status: AccountStatus::Touched,
816827
storage: Default::default(),
817828
transaction_id: 0,
@@ -848,6 +859,7 @@ mod tests {
848859
addr,
849860
Account {
850861
info: create_account(uint!(900_U256), 6, None),
862+
original_info: Default::default(),
851863
status: AccountStatus::Touched,
852864
storage: Default::default(),
853865
transaction_id: 0,
@@ -862,6 +874,7 @@ mod tests {
862874
addr,
863875
Account {
864876
info: create_account(uint!(800_U256), 7, None),
877+
original_info: Default::default(),
865878
status: AccountStatus::Touched,
866879
storage: Default::default(),
867880
transaction_id: 0,
@@ -889,6 +902,7 @@ mod tests {
889902
db.insert_account_info(
890903
addr,
891904
AccountInfo {
905+
account_id: None,
892906
balance: U256::ZERO,
893907
nonce: 0,
894908
code_hash,

0 commit comments

Comments
 (0)