Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Indexers fail to identify the types of older txs since these types use wasm hashes. If those hashes were overwritten by governance proposals, the indexer is unable to determine how to deserialize these txs. This PR adds a new key to storage which allows looking up a tx type from a wasm hash, even if that hash is of code no longer in use. ([\#4690](https://github.com/anoma/namada/pull/4690))
12 changes: 11 additions & 1 deletion crates/core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl Key {
}

/// Returns a key of wasm code's hash of the given name
pub fn wasm_code_name(code_name: String) -> Self {
pub fn wasm_code_hash(code_name: String) -> Self {
let mut segments =
Self::from(PARAMETERS.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_KEY_PREFIX.to_owned()));
Expand Down Expand Up @@ -580,6 +580,16 @@ impl Key {
Key { segments }
}

/// Returns a key of the wasm name of the given code hash
pub fn wasm_code_name(code_hash: &Hash) -> Self {
let mut segments =
Self::from(PARAMETERS.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_KEY_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(WASM_HASH_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_hash.to_string()));
Key { segments }
}

/// Returns a key of the validity predicate of the given address
/// Only this function can push "?" segment for validity predicate
pub fn validity_predicate(addr: &Address) -> Self {
Expand Down
1 change: 1 addition & 0 deletions crates/migrations/src/foreign_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use namada_macros::derive_typehash;

use crate::TypeHash;

derive_typehash!(String);
derive_typehash!(Vec::<u8>);
derive_typehash!(Vec::<String>);
derive_typehash!(u64);
Expand Down
6 changes: 4 additions & 2 deletions crates/node/src/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,17 @@ where
let code_key = Key::wasm_code(&code_hash);
let code_len_key = Key::wasm_code_len(&code_hash);
let hash_key = Key::wasm_hash(name);
let code_name_key = Key::wasm_code_name(name.to_owned());
let code_hash_key = Key::wasm_code_hash(name.to_owned());
let code_name_key = Key::wasm_code_name(&code_hash);

self.state.write(&code_key, code).unwrap();
self.state.write(&code_len_key, code_len).unwrap();
self.state.write(&hash_key, code_hash).unwrap();
if &Some(code_hash) == implicit_vp_code_hash {
is_implicit_vp_stored = true;
}
self.state.write(&code_name_key, code_hash).unwrap();
self.state.write(&code_hash_key, code_hash).unwrap();
self.state.write(&code_name_key, name).unwrap();
} else {
tracing::warn!("The wasm {name} isn't allowed.");
self.warn(Warning::DisallowedWasm(name.to_string()));
Expand Down
2 changes: 1 addition & 1 deletion crates/tx/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ mod test_process_tx {

let batched_result = BatchedTxResult {
changed_keys: [
namada_account::Key::wasm_code_name("test-name".to_string()),
namada_account::Key::wasm_code_hash("test-name".to_string()),
namada_account::Key::wasm_hash("test-name"),
]
.into(),
Expand Down
11 changes: 9 additions & 2 deletions examples/make-db-migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ pub fn wasm_migration(updates: &mut Vec<migrations::DbUpdateType>) {
let code_key = Key::wasm_code(&new_code_hash);
let code_len_key = Key::wasm_code_len(&new_code_hash);
let hash_key = Key::wasm_hash(name);
let code_name_key = Key::wasm_code_name(name.to_owned());
let code_hash_key = Key::wasm_code_hash(name.to_owned());
let code_name_key = Key::wasm_code_name(&new_code_hash);

updates.push(migrations::DbUpdateType::Add {
key: code_key,
Expand All @@ -613,11 +614,17 @@ pub fn wasm_migration(updates: &mut Vec<migrations::DbUpdateType>) {
force: false,
});
updates.push(migrations::DbUpdateType::Add {
key: code_name_key,
key: code_hash_key,
cf: DbColFam::SUBSPACE,
value: new_code_hash.into(),
force: false,
});
updates.push(migrations::DbUpdateType::Add {
key: code_name_key,
cf: DbColFam::SUBSPACE,
value: name.to_string().into(),
force: false,
});
}
// Put the allow list in storage
updates.push(migrations::DbUpdateType::Add {
Expand Down
7 changes: 5 additions & 2 deletions wasm_for_tests/tx_proposal_code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
let wasm_code_len_key = Key::wasm_code_len(&wasm_code_hash);
ctx.write(&wasm_code_len_key, 30.serialize_to_vec())?;

let wasm_code_name_key = Key::wasm_code_name("test".to_string());
ctx.write_bytes(&wasm_code_name_key, wasm_code_name.clone())?;
let wasm_code_hash_key = Key::wasm_code_hash("test".to_string());
ctx.write_bytes(&wasm_code_hash_key, wasm_code_hash)?;

let wasm_code_name_key = Key::wasm_code_name(&wasm_code_hash);
ctx.write_bytes(&wasm_code_name_key, &wasm_code_name)?;

let wasm_hash_key = Key::wasm_hash("test");
ctx.write_bytes(&wasm_hash_key, wasm_code_name)?;
Expand Down
Loading