Skip to content

Commit

Permalink
Merge branch '@anchpop/get-proposal-id' into 'master'
Browse files Browse the repository at this point in the history
NNS1-3061: Render the proposal ID in UpgradeSnsToNextVersion proposals

## Problem

When viewing an UpgradeSnsToNextVersion proposal, you might be interested to know what's new in the new version. This information is in the NNS proposal that blessed the version being upgraded to.

## Solution

As of a recent MR this information is stored in SNS-W (in `SnsWasm`). This MR puts the proposal ID into the payload text rendering of the proposal. If SnsWasm doesn't have the proposal ID for an SNS version (which should never happen in the context of this MR), nothing is added to the proposal text.

## Open questions

This MR just requests the whole SnsWasm in `validate_and_render_upgrade_sns_to_next_version`. This is somewhat wasteful since we only need the proposal Id, and SnsWasm contains the proposal ID along with the entire wasm. In the future we could add a new endpoint to SNS-W which only returns the proposal ID.

Closes NNS1-3061 

Closes NNS1-3061

See merge request dfinity-lab/public/ic!19301
  • Loading branch information
anchpop committed May 16, 2024
2 parents 5ba1412 + 32da77f commit c6d730c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rs/sns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7070,7 +7070,8 @@ mod tests {
Ok(Encode!(&GetWasmResponse {
wasm: Some(SnsWasm {
wasm: vec![9, 8, 7, 6, 5, 4, 3, 2],
canister_type: expected_canister_to_be_upgraded.into() // Governance
canister_type: expected_canister_to_be_upgraded.into(), // Governance
proposal_id: None,
})
})
.unwrap()),
Expand Down
20 changes: 18 additions & 2 deletions rs/sns/governance/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::sns_upgrade::{get_wasm, SnsWasm};
use crate::{
canister_control::perform_execute_generic_nervous_system_function_validate_and_render_call,
governance::{
Expand Down Expand Up @@ -1082,7 +1083,7 @@ async fn validate_and_render_upgrade_sns_to_next_version(
) -> Result<String, String> {
let UpgradeSnsParams {
next_version,
canister_type_to_upgrade: _,
canister_type_to_upgrade,
new_wasm_hash,
canister_ids_to_upgrade,
} = get_upgrade_params(env, root_canister_id, &current_version)
Expand All @@ -1094,6 +1095,18 @@ async fn validate_and_render_upgrade_sns_to_next_version(
)
})?;

let proposal_id_message = get_wasm(env, new_wasm_hash.to_vec(), canister_type_to_upgrade)
.await
.ok()
.and_then(|SnsWasm { proposal_id, .. }| proposal_id)
.map(|id| {
format!(
"## Proposal ID of the NNS proposal that blessed this WASM version: NNS Proposal {}",
id
)
})
.unwrap_or_default();

// TODO display the hashes for current version and new version
Ok(format!(
r"# Proposal to upgrade SNS to next version:
Expand All @@ -1106,6 +1119,7 @@ async fn validate_and_render_upgrade_sns_to_next_version(
## Canisters to be upgraded: {}
## Upgrade Version: {}
{proposal_id_message}
",
render_version(&current_version),
render_version(&next_version),
Expand Down Expand Up @@ -3118,7 +3132,8 @@ mod tests {
Ok(Encode!(&GetWasmResponse {
wasm: Some(SnsWasm {
wasm: vec![9, 8, 7, 6, 5, 4, 3, 2],
canister_type: expected_canister_to_be_upgraded.into() // Governance
canister_type: expected_canister_to_be_upgraded.into(), // Governance
proposal_id: Some(2),
})
})
.unwrap()),
Expand Down Expand Up @@ -3170,6 +3185,7 @@ Version {
## Canisters to be upgraded: q7t5l-saaaa-aaaaa-aah2a-cai
## Upgrade Version: 67586e98fad27da0b9968bc039a1ef34c939b9b8e523a8bef89d478608c5ecf6
## Proposal ID of the NNS proposal that blessed this WASM version: NNS Proposal 2
";
assert_eq!(actual_text, expected_text);
}
Expand Down
3 changes: 3 additions & 0 deletions rs/sns/governance/src/sns_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,12 @@ pub(crate) struct GetWasmResponse {
#[derive(candid::CandidType, candid::Deserialize, Clone, PartialEq, ::prost::Message)]
pub(crate) struct SnsWasm {
#[prost(bytes = "vec", tag = "1")]
#[serde(with = "serde_bytes")]
pub wasm: ::prost::alloc::vec::Vec<u8>,
#[prost(enumeration = "SnsCanisterType", tag = "2")]
pub canister_type: i32,
#[prost(uint64, optional, tag = "3")]
pub proposal_id: ::core::option::Option<u64>,
}
/// Copied from ic-sns-wasm
/// The type of canister a particular WASM is intended to be installed on.
Expand Down

0 comments on commit c6d730c

Please sign in to comment.