@@ -6,8 +6,7 @@ mod receipt_builder;
66use crate :: {
77 block:: curie:: { apply_curie_hard_fork, L1_GAS_PRICE_ORACLE_ADDRESS } ,
88 system_caller:: ScrollSystemCaller ,
9- IntoCompressed , ScrollEvm , ScrollEvmFactory , ScrollTransactionIntoTxEnv ,
10- ScrollTxCompressionFactorCache , WithCompression ,
9+ FromTxWithCompression , IntoCompressed , ScrollEvm , ScrollEvmFactory , ScrollTransactionIntoTxEnv ,
1110} ;
1211use alloc:: { boxed:: Box , format, vec:: Vec } ;
1312
@@ -18,7 +17,7 @@ use alloy_evm::{
1817 BlockExecutionError , BlockExecutionResult , BlockExecutor , BlockExecutorFactory ,
1918 BlockExecutorFor , BlockValidationError , CommitChanges , ExecutableTx , OnStateHook ,
2019 } ,
21- Database , Evm , EvmFactory , FromRecoveredTx , FromTxWithEncoded , IntoTxEnv , RecoveredTx ,
20+ Database , Evm , EvmFactory , FromRecoveredTx , FromTxWithEncoded ,
2221} ;
2322use alloy_primitives:: { B256 , U256 } ;
2423use revm:: {
@@ -35,6 +34,10 @@ use revm_scroll::builder::ScrollContext;
3534use scroll_alloy_consensus:: L1_MESSAGE_TRANSACTION_TYPE ;
3635use scroll_alloy_hardforks:: { ScrollHardfork , ScrollHardforks } ;
3736
37+ /// A cache for transaction compression factors, mapping transaction hashes to their compression
38+ /// factors.
39+ pub type ScrollTxCompressionFactors = Vec < U256 > ;
40+
3841/// Context for Scroll Block Execution.
3942#[ derive( Debug , Default , Clone ) ]
4043pub struct ScrollBlockExecutionCtx {
@@ -93,68 +96,31 @@ where
9396 DB : Database + ' db ,
9497 E : EvmExt <
9598 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 ( )
125- }
126- }
127-
128- impl < ' db , DB , E , R , Spec > ScrollBlockExecutor < E , R , Spec >
129- where
130- DB : Database + ' db ,
131- E : EvmExt <
132- DB = & ' db mut State < DB > ,
133- Tx : FromRecoveredTx < R :: Transaction > + FromTxWithEncoded < R :: Transaction > ,
134- > ,
135- R : ScrollReceiptBuilder <
136- Transaction : Transaction + Encodable2718 + RecoveredTx < R :: Transaction > ,
137- Receipt : TxReceipt ,
99+ Tx : FromRecoveredTx < R :: Transaction >
100+ + FromTxWithEncoded < R :: Transaction >
101+ + FromTxWithCompression < R :: Transaction > ,
138102 > ,
103+ R : ScrollReceiptBuilder < Transaction : Transaction + Encodable2718 , Receipt : TxReceipt > ,
139104 Spec : ScrollHardforks ,
140- for < ' a > & ' a WithCompression < <R as ScrollReceiptBuilder >:: Transaction > :
141- IntoTxEnv < <E as alloy_evm:: Evm >:: Tx > ,
142105{
143- /// Executes all transactions in a block, applying pre and post execution changes.
106+ /// Executes all transactions in a block, applying pre and post execution changes. The provided
107+ /// transaction compression factors are expected to be in the same order as the
108+ /// transactions.
144109 pub fn execute_block_with_compression_cache (
145110 mut self ,
146111 transactions : impl IntoIterator <
147112 Item = impl ExecutableTx < Self > + IntoCompressed < <Self as BlockExecutor >:: Transaction > ,
148113 > ,
149- mut compression_cache : ScrollTxCompressionFactorCache ,
114+ compression_cache : ScrollTxCompressionFactors ,
150115 ) -> Result < BlockExecutionResult < R :: Receipt > , BlockExecutionError >
151116 where
152117 Self : Sized ,
153118 {
154119 self . apply_pre_execution_changes ( ) ?;
155120
156- for tx in transactions {
157- let tx = tx. into_compressed ( Some ( & mut compression_cache) ) ;
121+ for ( tx, compression_factor) in transactions. into_iter ( ) . zip ( compression_cache. into_iter ( ) )
122+ {
123+ let tx = tx. into_compressed ( compression_factor) ;
158124 self . execute_transaction ( & tx) ?;
159125 }
160126
0 commit comments