Skip to content

Commit 3c136f1

Browse files
committed
create cache restore method
1 parent 13dc11b commit 3c136f1

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

crates/vm/levm/bench/revm_comparison/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ pub fn run_with_levm(program: &str, runs: u64, calldata: &str) {
9191
vm.call_frames.last_mut().unwrap().calldata = calldata.clone();
9292
vm.env.gas_limit = u64::MAX - 1;
9393
vm.env.block_gas_limit = u64::MAX;
94-
let tx_report = black_box(vm.execute().unwrap());
94+
let tx_report = black_box(vm.stateless_execute().unwrap());
9595
assert!(tx_report.result == TxResult::Success);
9696
}
9797
let mut vm = new_vm_with_bytecode(&mut db, runs - 1).unwrap();
9898
vm.call_frames.last_mut().unwrap().calldata = calldata.clone();
9999
vm.env.gas_limit = u64::MAX - 1;
100100
vm.env.block_gas_limit = u64::MAX;
101-
let tx_report = black_box(vm.execute().unwrap());
101+
let tx_report = black_box(vm.stateless_execute().unwrap());
102102
assert!(tx_report.result == TxResult::Success);
103103

104104
match tx_report.result {

crates/vm/levm/src/vm.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,7 @@ impl<'a> VM<'a> {
350350
}
351351

352352
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);
362354
self.accrued_substate = backup.substate;
363355
self.env.refunded_gas = backup.refunded_gas;
364356
self.env.transient_storage = backup.transient_storage;
@@ -415,14 +407,7 @@ impl<'a> VM<'a> {
415407

416408
if let Err(e) = self.prepare_execution(&mut initial_call_frame) {
417409
// 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);
426411
return Err(e);
427412
}
428413

@@ -580,4 +565,15 @@ impl<'a> VM<'a> {
580565

581566
Ok(())
582567
}
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+
}
583579
}

0 commit comments

Comments
 (0)