From 0783575020bb06968912c9f427d343cf79ef7d6b Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli Date: Mon, 12 Aug 2024 17:37:54 +0200 Subject: [PATCH 1/2] client: print sha256 of proposal wasm --- crates/governance/src/storage/mod.rs | 21 +++++++++++++++++---- crates/node/src/shell/governance.rs | 10 +--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/governance/src/storage/mod.rs b/crates/governance/src/storage/mod.rs index 50ac876dc8..fea46850ec 100644 --- a/crates/governance/src/storage/mod.rs +++ b/crates/governance/src/storage/mod.rs @@ -12,6 +12,7 @@ use std::collections::{BTreeMap, BTreeSet}; use namada_core::address::Address; use namada_core::borsh::BorshDeserialize; use namada_core::collections::HashSet; +use namada_core::hash::Hash; use namada_core::storage::Epoch; use namada_core::token; use namada_state::{ @@ -169,7 +170,21 @@ where let proposal_type: Option = storage.read(&proposal_type_key)?; - let proposal = proposal_type.map(|proposal_type| StorageProposal { + let proposal_type = if let Some(proposal_type) = proposal_type { + if let ProposalType::DefaultWithWasm(_) = proposal_type { + let proposal_code_key = governance_keys::get_proposal_code_key(id); + let proposal_code: Vec = + storage.read(&proposal_code_key)?.unwrap_or_default(); + let proposal_code_hash = Hash::sha256(proposal_code); + ProposalType::DefaultWithWasm(proposal_code_hash) + } else { + proposal_type + } + } else { + return Ok(None); + }; + + Ok(Some(StorageProposal { id, content: content.unwrap(), author: author.unwrap(), @@ -177,9 +192,7 @@ where voting_start_epoch: voting_start_epoch.unwrap(), voting_end_epoch: voting_end_epoch.unwrap(), activation_epoch: activation_epoch.unwrap(), - }); - - Ok(proposal) + })) } /// Query all the votes for a proposal_id diff --git a/crates/node/src/shell/governance.rs b/crates/node/src/shell/governance.rs index 7329b9bc36..cc4a3a3412 100644 --- a/crates/node/src/shell/governance.rs +++ b/crates/node/src/shell/governance.rs @@ -122,14 +122,6 @@ where TallyResult::Passed => { let proposal_event = match proposal_type { ProposalType::Default => { - let proposal_code = - gov_api::get_proposal_code(&shell.state, id)? - .unwrap_or_default(); - let _result = execute_default_proposal( - shell, - id, - proposal_code.clone(), - )?; tracing::info!( "Governance proposal #{} (default) has passed.", id, @@ -176,7 +168,7 @@ where } ProposalType::PGFPayment(payments) => { let native_token = &shell.state.get_native_token()?; - let _result = execute_pgf_funding_proposal( + execute_pgf_funding_proposal( &mut shell.state, events, native_token, From 8cb793cdebecbeddd51c745daada1641e9692714 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli Date: Tue, 13 Aug 2024 13:13:16 +0200 Subject: [PATCH 2/2] added changelog --- .../improvements/3617-governance-proposal-client-better-hash.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/3617-governance-proposal-client-better-hash.md diff --git a/.changelog/unreleased/improvements/3617-governance-proposal-client-better-hash.md b/.changelog/unreleased/improvements/3617-governance-proposal-client-better-hash.md new file mode 100644 index 0000000000..1f9ced280e --- /dev/null +++ b/.changelog/unreleased/improvements/3617-governance-proposal-client-better-hash.md @@ -0,0 +1,2 @@ +- Display the hash of the proposal wasm code when querying proposals with + associated wasm payload. ([\#3617](https://github.com/anoma/namada/pull/3617)) \ No newline at end of file