diff --git a/src/instruction_handlers/far_call.rs b/src/instruction_handlers/far_call.rs index 99b5df4d..638f9a2e 100644 --- a/src/instruction_handlers/far_call.rs +++ b/src/instruction_handlers/far_call.rs @@ -69,7 +69,7 @@ fn far_call< Address::from_low_u64_be(DEPLOYER_SYSTEM_CONTRACT_ADDRESS_LOW as u64); if !vm .world_diff - .read_storage_slots_ct + .read_storage_slots .contains(&(deployer_system_contract_address, destination_address)) { vm.state.storage_application_cycles += diff --git a/src/instruction_handlers/storage.rs b/src/instruction_handlers/storage.rs index dad90668..23e4bb8a 100644 --- a/src/instruction_handlers/storage.rs +++ b/src/instruction_handlers/storage.rs @@ -19,7 +19,7 @@ fn sstore>( let value = Register2::get(args, &mut vm.state); if !vm .world_diff - .written_storage_slots_ct + .written_storage_slots .contains(&(vm.state.current_frame.address, key)) { vm.state.storage_application_cycles += @@ -64,11 +64,11 @@ fn sload>( if !vm .world_diff - .read_storage_slots_ct + .read_storage_slots .contains(&(vm.state.current_frame.address, key)) && !vm .world_diff - .written_storage_slots_ct + .written_storage_slots .contains(&(vm.state.current_frame.address, key)) { vm.state.storage_application_cycles += STORAGE_READ_STORAGE_APPLICATION_CYCLES as usize; diff --git a/src/world_diff.rs b/src/world_diff.rs index 057cdb84..9bea722a 100644 --- a/src/world_diff.rs +++ b/src/world_diff.rs @@ -26,14 +26,11 @@ pub struct WorldDiff { // The fields below are only rolled back when the whole VM is rolled back. pub(crate) decommitted_hashes: RollbackableSet, - read_storage_slots: RollbackableSet<(H160, U256)>, - written_storage_slots: RollbackableSet<(H160, U256)>, + pub read_storage_slots: RollbackableSet<(H160, U256)>, + pub written_storage_slots: RollbackableSet<(H160, U256)>, // This is never rolled back. It is just a cache to avoid asking these from DB every time. storage_initial_values: BTreeMap<(H160, U256), Option>, - - pub read_storage_slots_ct: RollbackableSet<(H160, U256)>, - pub written_storage_slots_ct: RollbackableSet<(H160, U256)>, } #[derive(Debug)] @@ -44,9 +41,6 @@ pub struct ExternalSnapshot { written_storage_slots: as Rollback>::Snapshot, storage_refunds: as Rollback>::Snapshot, pubdata_costs: as Rollback>::Snapshot, - - read_storage_slots_ct: as Rollback>::Snapshot, - written_storage_slots_ct: as Rollback>::Snapshot, } /// There is no address field because nobody is interested in events that don't come @@ -108,15 +102,14 @@ impl WorldDiff { .copied() .unwrap_or_else(|| world.read_storage(contract, key).unwrap_or_default()); - self.read_storage_slots_ct.add((contract, key)); let refund = if world.is_free_storage_slot(&contract, &key) || self.read_storage_slots.contains(&(contract, key)) { WARM_READ_REFUND } else { - self.read_storage_slots.add((contract, key)); 0 }; + self.read_storage_slots.add((contract, key)); self.pubdata_costs.push(0); (value, refund) } @@ -136,8 +129,8 @@ impl WorldDiff { .entry((contract, key)) .or_insert_with(|| world.read_storage(contract, key)); - self.written_storage_slots_ct.add((contract, key)); if world.is_free_storage_slot(&contract, &key) { + self.written_storage_slots.add((contract, key)); self.storage_refunds.push(WARM_WRITE_REFUND); self.pubdata_costs.push(0); return WARM_WRITE_REFUND; @@ -313,9 +306,6 @@ impl WorldDiff { written_storage_slots: self.written_storage_slots.snapshot(), storage_refunds: self.storage_refunds.snapshot(), pubdata_costs: self.pubdata_costs.snapshot(), - - read_storage_slots_ct: self.read_storage_slots_ct.snapshot(), - written_storage_slots_ct: self.written_storage_slots_ct.snapshot(), } } @@ -329,11 +319,6 @@ impl WorldDiff { .rollback(snapshot.read_storage_slots); self.written_storage_slots .rollback(snapshot.written_storage_slots); - - self.read_storage_slots_ct - .rollback(snapshot.read_storage_slots_ct); - self.written_storage_slots_ct - .rollback(snapshot.written_storage_slots_ct); } pub(crate) fn delete_history(&mut self) {