Skip to content

Commit

Permalink
Merge branch 'namada/tomas+brent/lazy-vec-and-map' (#503)
Browse files Browse the repository at this point in the history
* namada/tomas+brent/lazy-vec-and-map:
  changelog: #503
  [ci] wasm checksums update
  remove unfinished lazy_set, lazy_hashset and lazy_hashmap for now
  ledger/storage/lazy: update lazy_set for updated trait LazyCollection
  ledger/storage/lazy: remove unused error cases
  WIP: Nested LazyMap validation and testing
  WIP: validation for lazy_map
  WIP: StateMachine tests for lazy_vec validation
  post-conditions for Transition::Update + some comments
  quick bug and documentation fix
  update after rebase on #458, #465
  storage/lazy_vec: add state machine test for lazy vec API
  storage/lazy_vec/validation: disallow unrecognized keys matching prefix
  impl LazyCollection trait for all the collections + refactor
  storage_api/collections/lazy: allow nested lazy collections in LazyMap
  add lazy_vec validation
  fix clippy
  storage_api/collections/lazy: add basic tests and missing methods
  cargo test test_lazy_vec_basics
  update lazy for explicit lifetime in StorageRead trait
  storage: add `Key::last` method, impl KeySeg for all ints
  Switch to use storage::KeySeg and add LazySet
  add lazy map without hashing
  refactored lazy collections, replaced hasher, added iter
  fmt && clippy
  add fn get_elem_key_by_hash to LazyMap
  lazy hash map first commit
  add lazy set (WIP), make LazyVec.get public
  add lazy vector
  create lazy data structures for storage access
  rustdoc: resolve ambiguous link
  fixup! Merge branch 'namada/tomas/sorted-prefix-iter' (#458)
  • Loading branch information
tzemanovic committed Sep 23, 2022
2 parents b485527 + 707db38 commit b3a1921
Show file tree
Hide file tree
Showing 21 changed files with 3,449 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/503-lazy-vec-and-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added lazy vector and map data structures for ledger storage
([#503](https://github.com/anoma/namada/pull/503))
38 changes: 38 additions & 0 deletions shared/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,44 @@ where
}
}

impl<D, H> StorageWrite for &mut Storage<D, H>
where
D: DB + for<'iter> DBIter<'iter>,
H: StorageHasher,
{
fn write<T: borsh::BorshSerialize>(
&mut self,
key: &crate::types::storage::Key,
val: T,
) -> storage_api::Result<()> {
let val = val.try_to_vec().unwrap();
self.write_bytes(key, val)
}

fn write_bytes(
&mut self,
key: &crate::types::storage::Key,
val: impl AsRef<[u8]>,
) -> storage_api::Result<()> {
let _ = self
.db
.write_subspace_val(self.block.height, key, val)
.into_storage_result()?;
Ok(())
}

fn delete(
&mut self,
key: &crate::types::storage::Key,
) -> storage_api::Result<()> {
let _ = self
.db
.delete_subspace_val(self.block.height, key)
.into_storage_result()?;
Ok(())
}
}

impl From<MerkleTreeError> for Error {
fn from(error: MerkleTreeError) -> Self {
Self::MerkleTreeError(error)
Expand Down
Loading

0 comments on commit b3a1921

Please sign in to comment.