Skip to content

Commit

Permalink
Use BtreeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadkaouk committed Sep 15, 2023
1 parent f14d3e2 commit ca9e4d3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frame/evm/src/runner/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use evm::{
};
use fp_evm::ACCOUNT_STORAGE_PROOF_SIZE;
use sp_core::{H160, H256};
use sp_std::collections::btree_map::BTreeMap;
use sp_std::collections::btree_set::BTreeSet;

/// An error that is returned when the storage limit has been exceeded.
#[derive(Debug, PartialEq)]
Expand All @@ -35,7 +35,7 @@ pub enum MeterError {
pub struct StorageMeter {
usage: u64,
limit: u64,
recorded_new_entries: BTreeMap<(H160, H256), ()>,
recorded_new_entries: BTreeSet<(H160, H256)>,
}

impl StorageMeter {
Expand All @@ -44,7 +44,7 @@ impl StorageMeter {
Self {
usage: 0,
limit,
recorded_new_entries: BTreeMap::new(),
recorded_new_entries: BTreeSet::new(),
}
}

Expand All @@ -54,7 +54,7 @@ impl StorageMeter {
let usage = self
.usage
.checked_add(amount)
.ok_or_else(|| MeterError::LimitExceeded)?;
.ok_or(MeterError::LimitExceeded)?;

if usage > self.limit {
return Err(MeterError::LimitExceeded);
Expand All @@ -81,10 +81,10 @@ impl StorageMeter {
StorageTarget::Slot(address, index) => (address, index),
_ => return Ok(()),
};
let recorded = self.recorded_new_entries.contains_key(&(address, index));
let recorded = self.recorded_new_entries.contains(&(address, index));
if !recorded && original == H256::default() && !new.is_zero() {
self.record(ACCOUNT_STORAGE_PROOF_SIZE)?;
self.recorded_new_entries.insert((address, index), ());
self.recorded_new_entries.insert((address, index));
}
}
Ok(())
Expand Down

0 comments on commit ca9e4d3

Please sign in to comment.