4040 pub bundle_orders : AggregateOrders ,
4141}
4242
43- impl < Db , Insp > From < signet_evm:: EvmNeedsTx < Db , Insp > > for DriverOutput < Db , Insp >
44- where
45- Db : Database ,
46- Insp : Inspector < Ctx < Db > > ,
47- {
48- fn from ( evm : signet_evm:: EvmNeedsTx < Db , Insp > ) -> Self {
49- Self {
50- host_evm : Some ( evm) ,
51- total_gas_used : 0 ,
52- beneficiary_balance_increase : U256 :: ZERO ,
53- bundle_fills : AggregateFills :: default ( ) ,
54- bundle_orders : AggregateOrders :: default ( ) ,
55- }
56- }
57- }
58-
5943impl < Db , Insp > DriverOutput < Db , Insp >
6044where
6145 Db : Database ,
@@ -141,9 +125,8 @@ where
141125 /// The bundle to apply.
142126 bundle : & ' a SignetEthBundle ,
143127
144- /// Reference to the fill state to check against. When we modify it, we'll
145- /// clone and take a running total.
146- fill_state : Cow < ' b , AggregateFills > ,
128+ /// Reference to the fill state to check against.
129+ pub fill_state : Cow < ' b , AggregateFills > ,
147130
148131 /// Execution deadline for this bundle. This limits the total WALLCLOCK
149132 /// time spent simulating the bundle.
@@ -178,7 +161,18 @@ where
178161 deadline : std:: time:: Instant ,
179162 fill_state : Cow < ' b , AggregateFills > ,
180163 ) -> Self {
181- Self { bundle, fill_state, deadline, output : host_evm. into ( ) }
164+ Self {
165+ bundle,
166+ fill_state,
167+ deadline,
168+ output : DriverOutput {
169+ host_evm : Some ( host_evm) ,
170+ total_gas_used : 0 ,
171+ beneficiary_balance_increase : U256 :: ZERO ,
172+ bundle_fills : AggregateFills :: default ( ) ,
173+ bundle_orders : AggregateOrders :: default ( ) ,
174+ } ,
175+ }
182176 }
183177
184178 /// Get a reference to the bundle.
@@ -258,7 +252,6 @@ where
258252 // We simply run all host transactions first, accumulating their state
259253 // changes into the host_evm's state. If any reverts, we error out the
260254 // simulation.
261- let mut host_bundle_fills = AggregateFills :: default ( ) ;
262255 for tx in host_txs. into_iter ( ) {
263256 self . output . host_evm = Some ( trevm_try ! (
264257 self . output
@@ -275,13 +268,14 @@ where
275268 EVMError :: Custom ( "host transaction reverted" . to_string( ) )
276269 ) ;
277270
271+ // The host fills go in the bundle fills.
278272 let host_fills = htrevm
279273 . inner_mut_unchecked( )
280274 . inspector
281275 . as_mut_detector( )
282276 . take_aggregates( )
283277 . 0 ;
284- host_bundle_fills . absorb( & host_fills) ;
278+ self . output . bundle_fills . absorb( & host_fills) ;
285279
286280 Ok ( htrevm. accept_state( ) )
287281 } )
@@ -292,8 +286,6 @@ where
292286 trevm
293287 ) ) ;
294288 }
295- // Absorb the host fills into our running total.
296- self . fill_state . to_mut ( ) . absorb ( & host_bundle_fills) ;
297289
298290 // -- ROLLUP PORTION --
299291 for tx in txs. into_iter ( ) {
@@ -324,13 +316,18 @@ where
324316 let ( tx_fills, tx_orders) =
325317 t. inner_mut_unchecked ( ) . inspector . as_mut_detector ( ) . take_aggregates ( ) ;
326318
319+ // These clones are inefficient. We can optimize later if
320+ // needed.
321+ let mut candidate_fills = self . output . bundle_fills . clone ( ) ;
322+ let mut candidate_orders = self . output . bundle_orders . clone ( ) ;
323+
324+ // The candidate is the updated
325+ candidate_fills. absorb ( & tx_fills) ;
326+ candidate_orders. absorb ( & tx_orders) ;
327+
327328 // Then we check that the fills are sufficient against the
328329 // provided fill state. This does nothing on error.
329- if self
330- . fill_state
331- . to_mut ( )
332- . checked_remove_ru_tx_events ( & tx_fills, & tx_orders)
333- . is_err ( )
330+ if self . fill_state . check_ru_tx_events ( & candidate_fills, & candidate_orders) . is_err ( )
334331 {
335332 if self . bundle . reverting_tx_hashes ( ) . contains ( tx_hash) {
336333 debug ! ( "transaction marked as revertible, reverting" ) ;
@@ -342,9 +339,9 @@ where
342339 }
343340 }
344341
345- // now we absorb the fills and orders into our running totals.
346- self . output . absorb ( & tx_fills , & tx_orders ) ;
347- self . output . use_gas ( gas_used ) ;
342+ // Now we accept the fills and order candidates
343+ self . output . bundle_fills = candidate_fills ;
344+ self . output . bundle_orders = candidate_orders ;
348345 } else {
349346 // EVM Execution did not succeed.
350347 // If not success, we are in a revert or halt. If the tx is
@@ -354,11 +351,11 @@ where
354351 debug ! ( "transaction reverted, not marked as revertible" ) ;
355352 return Err ( t. errored ( BundleError :: BundleReverted . into ( ) ) ) ;
356353 }
357- self . output . use_gas ( gas_used) ;
358354 }
359355
360356 // If we did not shortcut return/continue, we accept the state
361357 // changes from this transaction.
358+ self . output . use_gas ( gas_used) ;
362359 trevm = t. accept_state ( )
363360 }
364361
0 commit comments