Skip to content

Commit

Permalink
Merge branch 'fraccaman/governable-wasm-txs' (#3100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli authored and Gianmarco Fraccaroli committed Apr 30, 2024
2 parents d2f1e80 + 6f498b7 commit 5976319
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3100-governable-wasm-txs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Wasm transactions are now governable via proposals.
([\#3100](https://github.com/anoma/namada/pull/3100))
14 changes: 9 additions & 5 deletions crates/core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::key::common;
use crate::address::{self, Address};
use crate::address::{self, Address, PARAMETERS};
use crate::bytes::ByteBuf;
use crate::ethereum_events::{GetEventNonce, TransfersToNamada, Uint};
use crate::hash::Hash;
Expand Down Expand Up @@ -717,7 +717,8 @@ impl Key {
/// Returns a key of the wasm code of the given hash
pub fn wasm_code(code_hash: &Hash) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
Self::from(PARAMETERS.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_KEY_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(WASM_CODE_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_hash.to_string()));
Key { segments }
Expand All @@ -726,7 +727,8 @@ impl Key {
/// Returns a key of wasm code's hash of the given name
pub fn wasm_code_name(code_name: String) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
Self::from(PARAMETERS.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_KEY_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(WASM_CODE_NAME_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_name));
Key { segments }
Expand All @@ -735,7 +737,8 @@ impl Key {
/// Returns a key of the wasm code's length of the given hash
pub fn wasm_code_len(code_hash: &Hash) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
Self::from(PARAMETERS.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_KEY_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(WASM_CODE_LEN_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_hash.to_string()));
Key { segments }
Expand All @@ -744,7 +747,8 @@ impl Key {
/// Returns a key of the wasm code hash of the given code path
pub fn wasm_hash(code_path: impl AsRef<str>) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).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_path.as_ref().to_string()));
Key { segments }
Expand Down
9 changes: 1 addition & 8 deletions crates/namada/src/ledger/native_vp/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
.into());
};
match key_type {
KeyType::PARAMETER => {
KeyType::PARAMETER | KeyType::UNKNOWN_PARAMETER => {
namada_governance::storage::is_proposal_accepted(
&self.ctx.pre(),
&data,
Expand All @@ -71,13 +71,6 @@ where
.into()
})
}
KeyType::UNKNOWN_PARAMETER => {
Err(native_vp::Error::new_alloc(format!(
"Attempted to change an unknown protocol parameter: \
{key}",
))
.into())
}
KeyType::UNKNOWN => Ok(()),
}
})
Expand Down
49 changes: 25 additions & 24 deletions wasm/checksums.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"tx_become_validator.wasm": "tx_become_validator.8b3b7ce3e57b7398b8cc318236d780d40e143f8814305eef862e230d0f1b9a4e.wasm",
"tx_bond.wasm": "tx_bond.39e8e86b1edcbeb7ae09a30ee0dd36357578f8bbaf9b5f383b50acdf95866dc0.wasm",
"tx_bridge_pool.wasm": "tx_bridge_pool.2f68d5127be2598e2036ad0d0131036c9e0b3d685ba5159a52167c0e8caabf3e.wasm",
"tx_change_consensus_key.wasm": "tx_change_consensus_key.b62d37c726f8026bf0769f16b49033738deea00f4ccfa9bd272241766d0089fd.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.0c57ec96210c3a054cf75d3b71674e0546b661e14cfd3f4382c34249bdb220d7.wasm",
"tx_change_validator_metadata.wasm": "tx_change_validator_metadata.29382c3364a46db819b12b207215510929fbe9f9189c20d06fe42dbdcca60cb6.wasm",
"tx_claim_rewards.wasm": "tx_claim_rewards.d2aefcd2cb90e7b1afd2a4d4ca5fd78bcdc60da2aa316875152e5f5cf86a5149.wasm",
"tx_deactivate_validator.wasm": "tx_deactivate_validator.88314334af5fab6c99d79be08435c2ed109a882908e81a30874583caa206a2bf.wasm",
"tx_ibc.wasm": "tx_ibc.6dc490630fbf6def05ebcff62a545efe6f8db8d09cd9027ff921e7463f733947.wasm",
"tx_init_account.wasm": "tx_init_account.11ec6c8909fbef33d035402f0e7ea44b0de5d8183ae2d882125f8e175b6f0b00.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.fe613cfbd61f15c4245eefb40127e3a795d63c01a03bc7c025c3494f4a55003e.wasm",
"tx_reactivate_validator.wasm": "tx_reactivate_validator.5102b6bf4256f72f28b70defff75274be1332a3c337fc6773a8c59c4b0d3fa16.wasm",
"tx_redelegate.wasm": "tx_redelegate.6baebed6bdaf6d689b56ba1fc9311f7975133957444f0c26a43023d03799f5ea.wasm",
"tx_resign_steward.wasm": "tx_resign_steward.8e18697714036affe32b0c9346cd704d1a4c445aa6dbb4db9d1f6c910a7947d3.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.acdd919ff3264b5f5bcacb73e53aed6408a801f226eed76873768e4417d5a93f.wasm",
"tx_transfer.wasm": "tx_transfer.ea2a3538f37212e6615917a201905f1793cd447009ab426c2f7c098f7452e3f6.wasm",
"tx_unbond.wasm": "tx_unbond.2ea349adada7ff85ff8ef21de0e94cf2218413c024b93e9d9154e3414987b4a0.wasm",
"tx_unjail_validator.wasm": "tx_unjail_validator.0629966b6389315d1ecd4660bf31925756195960e6bfce8a411e9949e97b5dc2.wasm",
"tx_update_account.wasm": "tx_update_account.67aee40a6e93a552f08ec36b763785673599fe2c413625ff3ce8d52df53fe6fe.wasm",
"tx_update_steward_commission.wasm": "tx_update_steward_commission.3f52cd04e3d5f16d1291926dc59d2fafb16d00909169a3da08fed5fe467cd34b.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.9f525fa2392854fc79483b777e3d9321041b3d2aa8c1434ed70290338928627f.wasm",
"tx_withdraw.wasm": "tx_withdraw.aeed96456f312edecc93a548fab90e5d550a3f1b0795333e3b426b5ec917b48c.wasm",
"vp_implicit.wasm": "vp_implicit.4b455e539f4b37f5a8d670971f695ec2412305a67d551a173164480531f27f51.wasm",
"vp_user.wasm": "vp_user.8b89d0aef02df5033cf895ffccd9d20b9a78383dccf446c88a307e55c2dce313.wasm"
"tx_become_validator.wasm": "tx_become_validator.83000b9fdb37249bd2d2f6a5cb430dd7cf8aaa4e40501116246a21d38fdaae58.wasm",
"tx_bond.wasm": "tx_bond.e970e7ddd7d17739492026cff437b5b973de299d5b66cba01d2965d1ada85f34.wasm",
"tx_bridge_pool.wasm": "tx_bridge_pool.2a5ff71c7e14a9be35451c57da7975c5ad23b032eafac731c96daf70f878234f.wasm",
"tx_change_consensus_key.wasm": "tx_change_consensus_key.c3f2b531bfbbd830c878d0cecf1fd1199c3bfc9cbc915242de56f40e04bc996a.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.0350f485b2701f7a0ee089995afba773835279c6f1999fa1c4b9f69361a8460c.wasm",
"tx_change_validator_metadata.wasm": "tx_change_validator_metadata.874777409cc7ac733a17643eb224b00bc34d84ae2f4360b4bb7ceb755f6f9c05.wasm",
"tx_claim_rewards.wasm": "tx_claim_rewards.1f9f1c92e0708be258d48bbb6be4d588d70177d58fa5720bcb6a09cd30d6034e.wasm",
"tx_deactivate_validator.wasm": "tx_deactivate_validator.11e913ebb3ffd70d3aa825c4ff09922340a660045a29c486fbeab703c28a72ac.wasm",
"tx_ibc.wasm": "tx_ibc.611951c2deef40faf46c7417b7f9c7d56f278d8c50e13e03c2d67092bcc8d9c1.wasm",
"tx_init_account.wasm": "tx_init_account.2aa2317dceba7bb7c9e53eb7f94e4d85a20951ea2ac09c438a12ffbb00baac31.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.26cad3393d2169cdfb610249da5c62f8a3f101becd3643c852e0ac548c81f4b6.wasm",
"tx_reactivate_validator.wasm": "tx_reactivate_validator.7671300f0e547dbd50f119689c66eb9ccd4af210407177efa68634f4d21f4d01.wasm",
"tx_redelegate.wasm": "tx_redelegate.190fb4e09176c8da5dabba61c98b585277c604aa6ddd02ac5cc2af3ce4efe9c9.wasm",
"tx_resign_steward.wasm": "tx_resign_steward.97ce6a528cda06e6ebc1a48bb5f9c59e386db5f9687d186b72144a679562fcc7.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.8eb69a287a4ab7c8a81932e0896f143cd2765f9d4006608a1e0430a79c12b987.wasm",
"tx_transfer.wasm": "tx_transfer.4108bd851ac717103de0f75e958e0b6a326d2f606d8624727e2680334f4d6c01.wasm",
"tx_unbond.wasm": "tx_unbond.fe033d58e07b52fc2597e9175d3d37d3df7f150ee6875d7ceb3a6b656a97eca0.wasm",
"tx_unjail_validator.wasm": "tx_unjail_validator.7ffd2ae443de5141a350e3b28d9bc495c8e0e1351a057647e78566086e9f8f36.wasm",
"tx_update_account.wasm": "tx_update_account.143c536b383cbeb4b6f8b546955d07bb7b3d68f680edacf3377cc55882b0f6a1.wasm",
"tx_update_reveal_pk.wasm": "tx_update_reveal_pk.98e4038b51f77545d550658890f115542b0c46bafe94ac6c9eaeb59f24d76969.wasm",
"tx_update_steward_commission.wasm": "tx_update_steward_commission.27948131eb82bb8d134d6ddb2d80b0dcc32439afa852c66691c72c81eb66a3c0.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.83488a945ecf5e1cfcee8a1d0e8b61ed9890fdf2f9e1dc564e4ace31f795b30f.wasm",
"tx_withdraw.wasm": "tx_withdraw.001a64055fca28649108094825a4e2f7bf9a4825b39f080abbb75c355b4be95b.wasm",
"vp_implicit.wasm": "vp_implicit.b5b570df3b4883cc5449ebd5646c3d3c23e085874de33fe8dce9d6b43483dc9e.wasm",
"vp_user.wasm": "vp_user.542148b1be526e4c9c21477d6d887d8cee5c88353d83139d613e9a4a4b61b221.wasm"
}
18 changes: 17 additions & 1 deletion wasm_for_tests/tx_proposal_code/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use namada_tx_prelude::*;
use namada_tx_prelude::{hash::Hash, storage::Key, *};

#[transaction]
fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult {
Expand All @@ -9,5 +9,21 @@ fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult {
// parameters
let target_key = parameters_storage::get_vp_allowlist_storage_key();
ctx.write(&target_key, vec!["hash"])?;

let wasm_code_hash = Hash::sha256("test");
let wasm_code_name = "test".to_string();

let wasm_code_key = Key::wasm_code(&wasm_code_hash);
ctx.write_bytes(&wasm_code_key, [])?;

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_hash_key = Key::wasm_hash("test");
ctx.write_bytes(&wasm_hash_key, wasm_code_name)?;

Ok(())
}

0 comments on commit 5976319

Please sign in to comment.