Skip to content

Commit

Permalink
handle non-merklized values in State methods
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jan 18, 2024
1 parent 223e4a5 commit 058aba7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub type Result<T> = std::result::Result<T, Error>;
/// it has 2 blocks delay on validator set update.
pub const EPOCH_SWITCH_BLOCKS_DELAY: u32 = 2;

/// Returns true if the given key is one whose data is not merklized
pub fn is_key_not_merklized(_key: &Key) -> bool {
// dummy value for now
false
}

/// The ledger's state
#[derive(Debug)]
pub struct State<D, H>
Expand Down Expand Up @@ -338,17 +344,23 @@ where
/// gas cost.
pub fn has_key(&self, key: &Key) -> Result<(bool, u64)> {
Ok((
self.block.tree.has_key(key)?,
if is_key_not_merklized(key) {
self.db.read_subspace_val(key)?.is_some()
} else {
self.block.tree.has_key(key)?
},
key.len() as u64 * STORAGE_ACCESS_GAS_PER_BYTE,
))
}

/// Returns a value from the specified subspace and the gas cost
pub fn read(&self, key: &Key) -> Result<(Option<Vec<u8>>, u64)> {
tracing::debug!("storage read key {}", key);
let (present, gas) = self.has_key(key)?;
if !present {
return Ok((None, gas));
if !is_key_not_merklized(key) {
let (present, gas) = self.has_key(key)?;
if !present {
return Ok((None, gas));
}
}

match self.db.read_subspace_val(key)? {
Expand Down

0 comments on commit 058aba7

Please sign in to comment.