diff --git a/src/db/extend.rs b/src/db/extend.rs index 1906675..96c1244 100644 --- a/src/db/extend.rs +++ b/src/db/extend.rs @@ -12,6 +12,164 @@ impl KVDatabase for RwLock { self.read().unwrap().contains_key(k) } + #[inline(always)] + fn put(&mut self, k: &[u8], v: &[u8]) -> Result, Self::Error> { + self.get_mut().unwrap().put(k, v) + } + + #[inline(always)] + fn or_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), Self::Error> { + self.get_mut().unwrap().or_put(k, v) + } + + #[inline(always)] + fn or_put_with, F: FnOnce() -> O>( + &mut self, + k: &[u8], + default: F, + ) -> Result<(), Self::Error> { + self.get_mut().unwrap().or_put_with(k, default) + } + + #[inline(always)] + fn put_owned + Into>>( + &mut self, + k: K, + v: impl Into, + ) -> Result, Self::Error> { + self.get_mut().unwrap().put_owned(k, v) + } + + #[inline(always)] + fn get + Clone>(&self, k: K) -> Result, Self::Error> { + self.read().unwrap().get(k) + } + + #[inline(always)] + fn is_gc_supported(&self) -> bool { + self.read().unwrap().is_gc_supported() + } + + #[inline(always)] + fn set_gc_enabled(&mut self, _gc_enabled: bool) { + self.get_mut().unwrap().set_gc_enabled(_gc_enabled) + } + + #[inline(always)] + fn gc_enabled(&self) -> bool { + self.read().unwrap().gc_enabled() + } + + #[inline(always)] + fn remove(&mut self, k: &[u8]) -> Result<(), Self::Error> { + self.get_mut().unwrap().remove(k) + } + + #[inline(always)] + fn retain(&mut self, f: F) -> Result<(), Self::Error> + where + F: FnMut(&[u8], &[u8]) -> bool, + { + self.get_mut().unwrap().retain(f) + } + + #[inline(always)] + fn extend, Self::Item)>>( + &mut self, + other: T, + ) -> Result<(), Self::Error> { + self.get_mut().unwrap().extend(other) + } +} + +impl KVDatabase for Mutex { + type Item = Db::Item; + type Error = Db::Error; + + #[inline(always)] + fn contains_key(&self, k: &[u8]) -> Result { + self.lock().unwrap().contains_key(k) + } + + #[inline(always)] + fn put(&mut self, k: &[u8], v: &[u8]) -> Result, Self::Error> { + self.get_mut().unwrap().put(k, v) + } + + #[inline(always)] + fn or_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), Self::Error> { + self.get_mut().unwrap().or_put(k, v) + } + + #[inline(always)] + fn or_put_with, F: FnOnce() -> O>( + &mut self, + k: &[u8], + default: F, + ) -> Result<(), Self::Error> { + self.get_mut().unwrap().or_put_with(k, default) + } + + #[inline(always)] + fn put_owned + Into>>( + &mut self, + k: K, + v: impl Into, + ) -> Result, Self::Error> { + self.get_mut().unwrap().put_owned(k, v) + } + + #[inline(always)] + fn get + Clone>(&self, k: K) -> Result, Self::Error> { + self.lock().unwrap().get(k) + } + + #[inline(always)] + fn is_gc_supported(&self) -> bool { + self.lock().unwrap().is_gc_supported() + } + + #[inline(always)] + fn set_gc_enabled(&mut self, gc_enabled: bool) { + self.get_mut().unwrap().set_gc_enabled(gc_enabled) + } + + #[inline(always)] + fn gc_enabled(&self) -> bool { + self.lock().unwrap().gc_enabled() + } + + #[inline(always)] + fn remove(&mut self, k: &[u8]) -> Result<(), Self::Error> { + self.get_mut().unwrap().remove(k) + } + + #[inline(always)] + fn retain(&mut self, f: F) -> Result<(), Self::Error> + where + F: FnMut(&[u8], &[u8]) -> bool, + { + self.get_mut().unwrap().retain(f) + } + + #[inline(always)] + fn extend, Self::Item)>>( + &mut self, + other: T, + ) -> Result<(), Self::Error> { + self.get_mut().unwrap().extend(other) + } +} + +impl KVDatabase for Arc> { + type Item = Db::Item; + type Error = Db::Error; + + #[inline(always)] + fn contains_key(&self, k: &[u8]) -> Result { + self.read().unwrap().contains_key(k) + } + #[inline(always)] fn put(&mut self, k: &[u8], v: &[u8]) -> Result, Self::Error> { self.write().unwrap().put(k, v) @@ -82,7 +240,7 @@ impl KVDatabase for RwLock { } } -impl KVDatabase for Mutex { +impl KVDatabase for Arc> { type Item = Db::Item; type Error = Db::Error; @@ -498,12 +656,12 @@ impl KVDatabase for &mut Db { #[inline(always)] fn get + Clone>(&self, k: K) -> Result, Self::Error> { - (&**self).get(k) + (**self).get(k) } #[inline(always)] fn is_gc_supported(&self) -> bool { - (&**self).is_gc_supported() + (**self).is_gc_supported() } #[inline(always)] @@ -513,7 +671,7 @@ impl KVDatabase for &mut Db { #[inline(always)] fn gc_enabled(&self) -> bool { - (&**self).gc_enabled() + (**self).gc_enabled() } #[inline(always)] diff --git a/src/db/sled.rs b/src/db/sled.rs index e13ed72..eb3a4a5 100644 --- a/src/db/sled.rs +++ b/src/db/sled.rs @@ -72,7 +72,7 @@ impl KVDatabase for SledDb { #[inline] fn contains_key(&self, k: &[u8]) -> Result { - Ok(self.db.contains_key(k)?) + self.db.contains_key(k) } #[inline] diff --git a/src/scroll_types.rs b/src/scroll_types.rs index 96b26ae..38c0649 100644 --- a/src/scroll_types.rs +++ b/src/scroll_types.rs @@ -121,7 +121,7 @@ impl EncodeValueBytes for U256 { impl DecodeValueBytes for U256 { fn decode_values_bytes(values: &[[u8; 32]]) -> Option { - values.get(0).map(|v| U256::from_be_bytes(*v)) + values.first().map(|v| U256::from_be_bytes(*v)) } } @@ -145,9 +145,9 @@ mod tests { let trie_account = Account::from_revm_account_with_storage_root(account, storage_root); - trie.update(address.as_ref(), trie_account).unwrap(); + trie.update(address, trie_account).unwrap(); - let account: Account = trie.get(address.as_ref()).unwrap(); + let account = trie.get::(address).unwrap().unwrap(); assert_eq!(trie_account, account); } diff --git a/src/trie/zktrie/tests.rs b/src/trie/zktrie/tests.rs index b6c2694..28ed0cb 100644 --- a/src/trie/zktrie/tests.rs +++ b/src/trie/zktrie/tests.rs @@ -26,7 +26,7 @@ fn test_simple() { old_trie.try_update(&old_key, 1, v.clone()).unwrap(); old_trie.prepare_root().unwrap(); - trie.raw_update(&k, v.clone(), 1).unwrap(); + trie.raw_update(k, v.clone(), 1).unwrap(); trie.commit().unwrap(); assert_eq!(old_trie.root().as_ref(), trie.root.unwrap_ref().as_slice()); @@ -56,7 +56,7 @@ fn test_random() { .try_update(&old_key, compression_flag, values.clone()) .unwrap(); - trie.raw_update(&k, values, compression_flag).unwrap(); + trie.raw_update(k, values, compression_flag).unwrap(); keys.push((k, old_key)); } @@ -95,7 +95,7 @@ fn test_random() { .iter() .map(|n| n.value()) .collect::>>(); - let mut new_proof = trie.prove(&k).unwrap(); + let mut new_proof = trie.prove(k).unwrap(); new_proof.pop(); // pop the magic bytes assert_eq!(old_proof, new_proof);