diff --git a/storage/src/state/cache.rs b/storage/src/state/cache.rs index 411d15b..d653f15 100644 --- a/storage/src/state/cache.rs +++ b/storage/src/state/cache.rs @@ -129,6 +129,19 @@ impl SessionedCache { self.delta.insert(key.to_owned(), None); } + /// Remove key-pair (when NOT EXIST in db) from cache + /// + /// Deprecated and replaced by `delete` + pub fn remove(&mut self, key: &[u8]) { + // exist in delta + if let Some(Some(_)) = self.delta.get(key) { + self.delta.remove(key); + } else if let Some(Some(_)) = self.base.get(key) { + // exist only in base + self.delta.insert(key.to_owned(), None); + } + } + /// commits pending KVs in session pub fn commit(&mut self) -> KVBatch { // Merge delta into the base version diff --git a/storage/src/state/mod.rs b/storage/src/state/mod.rs index 37fb478..7c94c7b 100644 --- a/storage/src/state/mod.rs +++ b/storage/src/state/mod.rs @@ -119,6 +119,18 @@ impl State { Ok(()) } + // Deprecated and replaced by `delete` + pub fn delete_v0(&mut self, key: &[u8]) -> Result<()> { + let cs = self.chain_state.read(); + match cs.get(key).c(d!())? { + //Mark key as deleted + Some(_) => self.cache.delete(key), + //Remove key from cache + None => self.cache.remove(key), + } + Ok(()) + } + /// Iterates the ChainState for the given range of keys pub fn iterate( &self, diff --git a/storage/src/store/traits.rs b/storage/src/store/traits.rs index 644a51c..b7afff7 100644 --- a/storage/src/store/traits.rs +++ b/storage/src/store/traits.rs @@ -181,6 +181,11 @@ where fn delete(&mut self, key: &[u8]) -> Result<()> { self.state_mut().delete(key) } + + /// deprecated and replaced by `delete` + fn delete_v0(&mut self, key: &[u8]) -> Result<()> { + self.state_mut().delete_v0(key) + } } /// A trait that implements the same functionality above without the requirement of owning a state @@ -335,4 +340,9 @@ pub trait StatelessStore { fn delete(state: &mut State, key: &[u8]) -> Result<()> { state.delete(key) } + + /// deprecated and replaced by `delete` + fn delete_v0(state: &mut State, key: &[u8]) -> Result<()> { + state.delete_v0(key) + } }