Skip to content

Commit

Permalink
Merge branch 'bat/multistore-refactor' (#547)
Browse files Browse the repository at this point in the history
* bat/multistore-refactor:
  changelog: add #547
  wasm: update checksums
  [chore]: Lints and formatting
  [fix]: Fixed proof specs for non-existence proofs
  [fix]: Update the main tree when deleting a key
  [fix]: Fixed last ibc unit test
  [fix]: Fixed some tests.
  [feat]: Refactored the merkle tree into a more maintainable multi-store
  • Loading branch information
juped committed Oct 17, 2022
2 parents 81f57b9 + a9c5f7b commit 5f6e323
Show file tree
Hide file tree
Showing 14 changed files with 628 additions and 452 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/547-multistore-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Extend Merkle tree storage to support multiple Merkle trees with a uniform
interface. ([#547](https://github.com/anoma/namada/pull/547))
23 changes: 5 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ark-serialize = "0.3.0"
ark-std = "0.3.0"
# branch = "bat/arse-merkle-tree"
arse-merkle-tree = {package = "sparse-merkle-tree", git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "04ad1eeb28901b57a7599bbe433b3822965dabe8", features = ["std", "borsh"]}
async-std = {version = "1.9.0", features = ["unstable"]}
async-std = {version = "=1.9.0", features = ["unstable"]}
async-trait = "0.1.51"
base64 = "0.13.0"
bech32 = "0.8.0"
Expand Down Expand Up @@ -97,7 +97,6 @@ serde_bytes = "0.11.5"
serde_json = {version = "1.0.62", features = ["raw_value"]}
sha2 = "0.9.3"
signal-hook = "0.3.9"
sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "121c79424646cc3e917f8616e549fbddee775a0a", features = ["borsh"]}
# sysinfo with disabled multithread feature
sysinfo = {version = "=0.21.1", default-features = false}
tar = "0.4.37"
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
let proof_ops = if is_proven {
match self.storage.get_existence_proof(
key,
value.clone(),
value.clone().into(),
height,
) {
Ok(proof) => Some(proof.into()),
Expand Down Expand Up @@ -199,7 +199,7 @@ where
for PrefixValue { key, value } in &values {
match self.storage.get_existence_proof(
key,
value.clone(),
value.clone().into(),
height,
) {
Ok(p) => {
Expand Down
1 change: 0 additions & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ serde = {version = "1.0.125", features = ["derive"]}
serde_json = "1.0.62"
sha2 = "0.9.3"
# We switch off "blake2b" because it cannot be compiled to wasm
sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "121c79424646cc3e917f8616e549fbddee775a0a", default-features = false, features = ["std", "borsh"]}
tempfile = {version = "3.2.0", optional = true}
# temporarily using fork work-around for https://github.com/informalsystems/tendermint-rs/issues/971
tendermint = {git = "https://github.com/heliaxdev/tendermint-rs", rev = "95c52476bc37927218374f94ac8e2a19bd35bec9", features = ["secp256k1"]}
Expand Down
75 changes: 75 additions & 0 deletions shared/src/ledger/storage/ics23_specs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! A module that contains

use arse_merkle_tree::H256;
use ics23::{HashOp, LeafOp, LengthOp, ProofSpec};

use super::traits::StorageHasher;

/// Get the leaf spec for the base tree. The key is stored after hashing,
/// but the stored value is the subtree's root without hashing.
pub fn base_leaf_spec<H: StorageHasher>() -> LeafOp {
LeafOp {
hash: H::hash_op().into(),
prehash_key: H::hash_op().into(),
prehash_value: HashOp::NoHash.into(),
length: LengthOp::NoPrefix.into(),
prefix: H256::zero().as_slice().to_vec(),
}
}

/// Get the leaf spec for the subtree. Non-hashed values are used for the
/// verification with this spec because a subtree stores the key-value pairs
/// after hashing.
pub fn leaf_spec<H: StorageHasher>() -> LeafOp {
LeafOp {
hash: H::hash_op().into(),
prehash_key: H::hash_op().into(),
prehash_value: H::hash_op().into(),
length: LengthOp::NoPrefix.into(),
prefix: H256::zero().as_slice().to_vec(),
}
}

/// Get the leaf spec for the ibc subtree. Non-hashed values are used for
/// the verification with this spec because a subtree stores the
/// key-value pairs after hashing. However, keys are also not hashed in
/// the backing store.
pub fn ibc_leaf_spec<H: StorageHasher>() -> LeafOp {
LeafOp {
hash: H::hash_op().into(),
prehash_key: HashOp::NoHash.into(),
prehash_value: HashOp::NoHash.into(),
length: LengthOp::NoPrefix.into(),
prefix: H256::zero().as_slice().to_vec(),
}
}

/// Get the proof specs for ibc
#[allow(dead_code)]
pub fn ibc_proof_specs<H: StorageHasher>() -> Vec<ProofSpec> {
let spec = arse_merkle_tree::proof_ics23::get_spec(H::hash_op());
let sub_tree_spec = ProofSpec {
leaf_spec: Some(ibc_leaf_spec::<H>()),
..spec.clone()
};
let base_tree_spec = ProofSpec {
leaf_spec: Some(base_leaf_spec::<H>()),
..spec
};
vec![sub_tree_spec, base_tree_spec]
}

/// Get the proof specs
#[allow(dead_code)]
pub fn proof_specs<H: StorageHasher>() -> Vec<ProofSpec> {
let spec = arse_merkle_tree::proof_ics23::get_spec(H::hash_op());
let sub_tree_spec = ProofSpec {
leaf_spec: Some(leaf_spec::<H>()),
..spec.clone()
};
let base_tree_spec = ProofSpec {
leaf_spec: Some(base_leaf_spec::<H>()),
..spec
};
vec![sub_tree_spec, base_tree_spec]
}
Loading

0 comments on commit 5f6e323

Please sign in to comment.