@@ -350,15 +350,7 @@ impl<'a> VM<'a> {
350
350
}
351
351
352
352
pub fn restore_state ( & mut self , backup : StateBackup , call_frame : & mut CallFrame ) {
353
- // self.db.cache = backup.cache;
354
- for ( address, account_opt) in & call_frame. backup {
355
- if let Some ( account) = account_opt {
356
- cache:: insert_account ( & mut self . db . cache , * address, account. clone ( ) , & mut None ) ;
357
- } else {
358
- // remove from cache
359
- cache:: remove_account ( & mut self . db . cache , address, & mut None ) ;
360
- }
361
- }
353
+ self . restore_cache_state ( call_frame) ;
362
354
self . accrued_substate = backup. substate ;
363
355
self . env . refunded_gas = backup. refunded_gas ;
364
356
self . env . transient_storage = backup. transient_storage ;
@@ -415,14 +407,7 @@ impl<'a> VM<'a> {
415
407
416
408
if let Err ( e) = self . prepare_execution ( & mut initial_call_frame) {
417
409
// We need to do a cleanup of the cache so that it doesn't interfere with next transaction's execution
418
- for ( address, account_opt) in & initial_call_frame. backup {
419
- if let Some ( account) = account_opt {
420
- cache:: insert_account ( & mut self . db . cache , * address, account. clone ( ) , & mut None ) ;
421
- } else {
422
- // remove from cache
423
- cache:: remove_account ( & mut self . db . cache , address, & mut None ) ;
424
- }
425
- }
410
+ self . restore_cache_state ( & initial_call_frame) ;
426
411
return Err ( e) ;
427
412
}
428
413
@@ -580,4 +565,15 @@ impl<'a> VM<'a> {
580
565
581
566
Ok ( ( ) )
582
567
}
568
+
569
+ fn restore_cache_state ( & mut self , call_frame : & CallFrame ) {
570
+ for ( address, account_opt) in & call_frame. backup {
571
+ if let Some ( account) = account_opt {
572
+ cache:: insert_account ( & mut self . db . cache , * address, account. clone ( ) , & mut None ) ;
573
+ } else {
574
+ // remove from cache
575
+ cache:: remove_account ( & mut self . db . cache , address, & mut None ) ;
576
+ }
577
+ }
578
+ }
583
579
}
0 commit comments