Skip to content

Commit

Permalink
deprecated: pre-rebase method of checking if key is merklized
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jan 18, 2024
1 parent 058aba7 commit a668827
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
25 changes: 19 additions & 6 deletions crates/ibc/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use namada_core::types::storage::{DbKeySeg, Key, KeySeg};
use sha2::{Digest, Sha256};
use thiserror::Error;

const CLIENTS_COUNTER: &str = "clients/counter";
const CONNECTIONS_COUNTER: &str = "connections/counter";
const CHANNELS_COUNTER: &str = "channelEnds/counter";
const CLIENTS_COUNTER_PREFIX: &str = "clients";
const CONNECTIONS_COUNTER_PREFIX: &str = "connections";
const CHANNELS_COUNTER_PREFIX: &str = "channelEnds";
const COUNTER_SEG: &str = "counter";
const DENOM: &str = "ibc_denom";

#[allow(missing_docs)]
Expand Down Expand Up @@ -52,20 +53,20 @@ pub fn ibc_key(path: impl AsRef<str>) -> Result<Key> {

/// Returns a key of the IBC client counter
pub fn client_counter_key() -> Key {
let path = CLIENTS_COUNTER.to_owned();
let path = format!("{}/{}", CLIENTS_COUNTER_PREFIX, COUNTER_SEG);
ibc_key(path).expect("Creating a key for the client counter shouldn't fail")
}

/// Returns a key of the IBC connection counter
pub fn connection_counter_key() -> Key {
let path = CONNECTIONS_COUNTER.to_owned();
let path = format!("{}/{}", CONNECTIONS_COUNTER_PREFIX, COUNTER_SEG);
ibc_key(path)
.expect("Creating a key for the connection counter shouldn't fail")
}

/// Returns a key of the IBC channel counter
pub fn channel_counter_key() -> Key {
let path = CHANNELS_COUNTER.to_owned();
let path = format!("{}/{}", CHANNELS_COUNTER_PREFIX, COUNTER_SEG);
ibc_key(path)
.expect("Creating a key for the channel counter shouldn't fail")
}
Expand Down Expand Up @@ -449,3 +450,15 @@ pub fn is_ibc_denom_key(key: &Key) -> Option<(String, String)> {
_ => None,
}
}

/// Returns true if the given key is for an IBC counter for clients,
/// connections, or channelEnds
pub fn is_ibc_counter_key(key: &Key) -> bool {
matches!(&key.segments[..],
[DbKeySeg::AddressSeg(addr), DbKeySeg::StringSeg(prefix), DbKeySeg::StringSeg(counter)]
if addr == &Address::Internal(InternalAddress::Ibc)
&& (prefix == CLIENTS_COUNTER_PREFIX
|| prefix == CONNECTIONS_COUNTER_PREFIX
|| prefix == CHANNELS_COUNTER_PREFIX) && counter == COUNTER_SEG
)
}
16 changes: 13 additions & 3 deletions crates/state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ pub type Result<T> = std::result::Result<T, Error>;
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
pub fn is_key_not_merklized(key: &Key) -> bool {
is_masp_key(key) || is_ibc_counter_key(key)
}

/// The ledger's state
Expand Down Expand Up @@ -1586,4 +1585,15 @@ mod tests {
.unwrap();
assert!(res2.is_none());
}

#[test]
fn test_non_merklized_keys() {
let channel_counter_key = channel_counter_key();
let connections_counter_key = connection_counter_key();
let client_counter_key = client_counter_key();

assert!(is_key_not_merklized(&channel_counter_key));
assert!(is_key_not_merklized(&client_counter_key));
assert!(is_key_not_merklized(&connections_counter_key));
}
}

0 comments on commit a668827

Please sign in to comment.