@@ -213,36 +213,7 @@ where
213213 let metrics = self . metrics . clone ( ) ;
214214 let state = self . transact ( tx) ?;
215215
216- let mut targets = MultiProofTargets :: with_capacity ( state. len ( ) ) ;
217- let mut storage_targets = 0 ;
218-
219- for ( addr, account) in state {
220- // if the account was not touched, or if the account was selfdestructed, do not
221- // fetch proofs for it
222- //
223- // Since selfdestruct can only happen in the same transaction, we can skip
224- // prefetching proofs for selfdestructed accounts
225- //
226- // See: https://eips.ethereum.org/EIPS/eip-6780
227- if !account. is_touched ( ) || account. is_selfdestructed ( ) {
228- continue
229- }
230-
231- let mut storage_set =
232- B256Set :: with_capacity_and_hasher ( account. storage . len ( ) , Default :: default ( ) ) ;
233- for ( key, slot) in account. storage {
234- // do nothing if unchanged
235- if !slot. is_changed ( ) {
236- continue
237- }
238-
239- storage_set. insert ( keccak256 ( B256 :: new ( key. to_be_bytes ( ) ) ) ) ;
240- }
241-
242- storage_targets += storage_set. len ( ) ;
243- targets. insert ( keccak256 ( addr) , storage_set) ;
244- }
245-
216+ let ( targets, storage_targets) = multiproof_targets_from_state ( state) ;
246217 metrics. prefetch_storage_targets . record ( storage_targets as f64 ) ;
247218
248219 Some ( targets)
@@ -314,6 +285,41 @@ where
314285 }
315286}
316287
288+ /// Returns a set of [`MultiProofTargets`] and the total amount of storage targets, based on the
289+ /// given state.
290+ fn multiproof_targets_from_state ( state : EvmState ) -> ( MultiProofTargets , usize ) {
291+ let mut targets = MultiProofTargets :: with_capacity ( state. len ( ) ) ;
292+ let mut storage_targets = 0 ;
293+ for ( addr, account) in state {
294+ // if the account was not touched, or if the account was selfdestructed, do not
295+ // fetch proofs for it
296+ //
297+ // Since selfdestruct can only happen in the same transaction, we can skip
298+ // prefetching proofs for selfdestructed accounts
299+ //
300+ // See: https://eips.ethereum.org/EIPS/eip-6780
301+ if !account. is_touched ( ) || account. is_selfdestructed ( ) {
302+ continue
303+ }
304+
305+ let mut storage_set =
306+ B256Set :: with_capacity_and_hasher ( account. storage . len ( ) , Default :: default ( ) ) ;
307+ for ( key, slot) in account. storage {
308+ // do nothing if unchanged
309+ if !slot. is_changed ( ) {
310+ continue
311+ }
312+
313+ storage_set. insert ( keccak256 ( B256 :: new ( key. to_be_bytes ( ) ) ) ) ;
314+ }
315+
316+ storage_targets += storage_set. len ( ) ;
317+ targets. insert ( keccak256 ( addr) , storage_set) ;
318+ }
319+
320+ ( targets, storage_targets)
321+ }
322+
317323/// The events the pre-warm task can handle.
318324pub ( super ) enum PrewarmTaskEvent {
319325 /// Forcefully terminate all remaining transaction execution.
0 commit comments