@@ -13,7 +13,7 @@ use flashblocks_primitives::{
1313 primitives:: ExecutionPayloadFlashblockDeltaV1 ,
1414} ;
1515use op_alloy_consensus:: OpReceipt ;
16- use rayon:: iter:: { IntoParallelIterator , ParallelIterator } ;
16+ use rayon:: iter:: IntoParallelIterator ;
1717use reth:: revm:: database:: StateProviderDatabase ;
1818use reth_primitives:: transaction:: SignedTransaction ;
1919
@@ -31,7 +31,7 @@ use reth_optimism_evm::{OpBlockAssembler, OpEvmConfig, OpRethReceiptBuilder};
3131use reth_optimism_node:: OpBuiltPayload ;
3232use reth_optimism_primitives:: { OpPrimitives , OpTransactionSigned } ;
3333use reth_primitives:: { Recovered , RecoveredBlock , SealedHeader } ;
34- use reth_provider:: { ExecutionOutcome , StateProvider } ;
34+ use reth_provider:: { BlockExecutionOutput , StateProvider , StateProviderFactory } ;
3535use reth_trie_common:: { HashedPostState , KeccakKeyHasher , updates:: TrieUpdates } ;
3636use revm:: {
3737 DatabaseRef ,
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 ,
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
305313impl < ' a , DBRef , R , E > BalBlockValidator < ' a , DBRef , R , E >
306314where
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
365373impl < ' a , DB , R , E > BlockBuilder for BalBlockValidator < ' a , DB , R , E >
366374where
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
467475impl < ' a , DbRef , R , E > BalBlockValidator < ' a , DbRef , R , E >
468476where
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 >
606616where
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
673683pub 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
0 commit comments