@@ -5,6 +5,7 @@ mod receipt_builder;
55
66use crate :: {
77 block:: curie:: { apply_curie_hard_fork, L1_GAS_PRICE_ORACLE_ADDRESS } ,
8+ system_caller:: ScrollSystemCaller ,
89 IntoCompressed , ScrollEvm , ScrollEvmFactory , ScrollTransactionIntoTxEnv ,
910 ScrollTxCompressionFactorCache , WithCompression ,
1011} ;
@@ -35,7 +36,7 @@ use scroll_alloy_consensus::L1_MESSAGE_TRANSACTION_TYPE;
3536use scroll_alloy_hardforks:: { ScrollHardfork , ScrollHardforks } ;
3637
3738/// Context for Scroll Block Execution.
38- #[ derive( Debug , Clone ) ]
39+ #[ derive( Debug , Default , Clone ) ]
3940pub struct ScrollBlockExecutionCtx {
4041 /// Parent block hash.
4142 pub parent_hash : B256 ,
@@ -48,13 +49,16 @@ pub struct ScrollBlockExecutor<Evm, R: ScrollReceiptBuilder, Spec> {
4849 spec : Spec ,
4950 /// Receipt builder.
5051 receipt_builder : R ,
51-
5252 /// The EVM used by executor.
5353 evm : Evm ,
54+ /// Context for block execution.
55+ ctx : ScrollBlockExecutionCtx ,
5456 /// Receipts of executed transactions.
5557 receipts : Vec < R :: Receipt > ,
5658 /// Total gas used by executed transactions.
5759 gas_used : u64 ,
60+ /// Utility to call system smart contracts.
61+ system_caller : ScrollSystemCaller < Spec > ,
5862}
5963
6064impl < E , R : ScrollReceiptBuilder , Spec > ScrollBlockExecutor < E , R , Spec > {
7175 Spec : ScrollHardforks + Clone ,
7276{
7377 /// Creates a new [`ScrollBlockExecutor`].
74- pub const fn new ( evm : E , spec : Spec , receipt_builder : R ) -> Self {
75- Self { evm, spec, receipt_builder, receipts : Vec :: new ( ) , gas_used : 0 }
78+ pub fn new ( evm : E , ctx : ScrollBlockExecutionCtx , spec : Spec , receipt_builder : R ) -> Self {
79+ Self {
80+ evm,
81+ ctx,
82+ system_caller : ScrollSystemCaller :: new ( spec. clone ( ) ) ,
83+ spec,
84+ receipt_builder,
85+ receipts : Vec :: new ( ) ,
86+ gas_used : 0 ,
87+ }
88+ }
89+ }
90+
91+ impl < ' db , DB , E , R , Spec > ScrollBlockExecutor < E , R , Spec >
92+ where
93+ DB : Database + ' db ,
94+ E : EvmExt <
95+ DB = & ' db mut State < DB > ,
96+ Tx : FromRecoveredTx < R :: Transaction > + FromTxWithEncoded < R :: Transaction > ,
97+ > ,
98+ R : ScrollReceiptBuilder <
99+ Transaction : Transaction + Encodable2718 + RecoveredTx < R :: Transaction > ,
100+ Receipt : TxReceipt ,
101+ > ,
102+ Spec : ScrollHardforks ,
103+ for < ' a > & ' a WithCompression < <R as ScrollReceiptBuilder >:: Transaction > :
104+ IntoTxEnv < <E as alloy_evm:: Evm >:: Tx > ,
105+ {
106+ /// Executes all transactions in a block, applying pre and post execution changes.
107+ pub fn execute_block_with_compression_cache (
108+ mut self ,
109+ transactions : impl IntoIterator <
110+ Item = impl ExecutableTx < Self > + IntoCompressed < <Self as BlockExecutor >:: Transaction > ,
111+ > ,
112+ mut compression_cache : ScrollTxCompressionFactorCache ,
113+ ) -> Result < BlockExecutionResult < R :: Receipt > , BlockExecutionError >
114+ where
115+ Self : Sized ,
116+ {
117+ self . apply_pre_execution_changes ( ) ?;
118+
119+ for tx in transactions {
120+ let tx = tx. into_compressed ( Some ( & mut compression_cache) ) ;
121+ self . execute_transaction ( & tx) ?;
122+ }
123+
124+ self . apply_post_execution_changes ( )
76125 }
77126}
78127
@@ -133,13 +182,16 @@ where
133182 self . spec . is_spurious_dragon_active_at_block ( self . evm . block ( ) . number ) ;
134183 self . evm . db_mut ( ) . set_state_clear_flag ( state_clear_flag) ;
135184
136- // load the l1 gas oracle contract in cache
185+ // load the l1 gas oracle contract in cache.
137186 let _ = self
138187 . evm
139188 . db_mut ( )
140189 . load_cache_account ( L1_GAS_PRICE_ORACLE_ADDRESS )
141190 . map_err ( BlockExecutionError :: other) ?;
142191
192+ // apply eip-2935.
193+ self . system_caller . apply_blockhashes_contract_call ( self . ctx . parent_hash , & mut self . evm ) ?;
194+
143195 if self
144196 . spec
145197 . scroll_fork_activation ( ScrollHardfork :: Curie )
@@ -353,12 +405,12 @@ where
353405 fn create_executor < ' a , DB , I > (
354406 & ' a self ,
355407 evm : <ScrollEvmFactory as EvmFactory >:: Evm < & ' a mut State < DB > , I > ,
356- _ctx : Self :: ExecutionCtx < ' a > ,
408+ ctx : Self :: ExecutionCtx < ' a > ,
357409 ) -> impl BlockExecutorFor < ' a , Self , DB , I >
358410 where
359411 DB : Database + ' a ,
360412 I : Inspector < ScrollContext < & ' a mut State < DB > > > + ' a ,
361413 {
362- ScrollBlockExecutor :: new ( evm, & self . spec , & self . receipt_builder )
414+ ScrollBlockExecutor :: new ( evm, ctx , & self . spec , & self . receipt_builder )
363415 }
364416}
0 commit comments