Skip to content

Commit d649fb5

Browse files
Support reinstalling canisters (SNS) (#228)
Co-authored-by: Adam Spofford <93943719+adamspofford-dfinity@users.noreply.github.com>
1 parent 4308890 commit d649fb5

File tree

9 files changed

+48
-16
lines changed

9 files changed

+48
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Overhauled PEM auth. PEM files are now password-protected by default, and must be used instead of seed files. Passwords can be provided interactively or with `--password-file`. Keys can be generated unencrypted with `quill generate --storage-mode plaintext`, and encrypted keys can be converted to plaintext with `quill decrypt-pem`.
1111
- Overhauled output format. All commands besides `quill sns` should have human-readable output instead of candid IDL. Candid IDL format can be forced with `--raw`.
1212

13+
- Added support for setting the install mode for UpgradeSnsControlledCanister proposals.
14+
1315
## [0.4.4] - 2024-03-21
1416

1517
- Fixed `quill sns make-proposal` setting some fields to null.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "Apache-2.0"
1111
[dependencies]
1212
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }
1313
ic-ckbtc-minter = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }
14+
ic-management-canister-types = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }
1415
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }
1516
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }
1617
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "479fc39a7ee082a62ec070efeed224784a83eb1b" }

docs/cli-reference/sns/quill-sns-make-upgrade-canister-proposal.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ quill sns make-upgrade-canister-proposal <PROPOSER_NEURON_ID> --target-canister-
3636
| `--title <TITLE>` | Title of the proposal. |
3737
| `--url <URL>` | URL of the proposal. |
3838
| `--wasm-path <WASM_PATH>` | Path to the WASM file to be installed into the target canister. |
39+
| `--mode <MODE>` | The install mode ("install", "reinstall", or "upgrade"). |
3940

4041
## Remarks
4142

src/commands/sns/make_upgrade_canister_proposal.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use candid::Principal;
1212
use candid::{Encode, IDLArgs};
1313
use candid_parser::parse_idl_args;
1414
use clap::Parser;
15+
use ic_management_canister_types::CanisterInstallMode;
1516
use ic_sns_governance::pb::v1::{
1617
manage_neuron, proposal, ManageNeuron, Proposal, UpgradeSnsControlledCanister,
1718
};
@@ -27,8 +28,8 @@ pub struct MakeUpgradeCanisterProposalOpts {
2728
proposer_neuron_id: ParsedSnsNeuron,
2829

2930
/// Title of the proposal.
30-
#[arg(long, default_value_t = String::from("Upgrade Canister"))]
31-
title: String,
31+
#[arg(long)]
32+
title: Option<String>,
3233

3334
/// URL of the proposal.
3435
#[arg(long, default_value_t = String::new())]
@@ -62,6 +63,10 @@ pub struct MakeUpgradeCanisterProposalOpts {
6263
/// Path to the binary file containing argument to post-upgrade method of the new canister WASM.
6364
#[arg(long, conflicts_with = "canister_upgrade_arg")]
6465
canister_upgrade_arg_path: Option<String>,
66+
67+
/// The install mode.
68+
#[arg(long, value_parser = ["install", "reinstall", "upgrade"])]
69+
mode: String,
6570
}
6671

6772
pub fn exec(
@@ -79,7 +84,23 @@ pub fn exec(
7984
wasm_path,
8085
canister_upgrade_arg,
8186
canister_upgrade_arg_path,
87+
mode,
8288
} = opts;
89+
let mode = match mode.as_str() {
90+
"install" => CanisterInstallMode::Install,
91+
"reinstall" => CanisterInstallMode::Reinstall,
92+
"upgrade" => CanisterInstallMode::Upgrade,
93+
_ => return Err(Error::msg("Invalid mode.")),
94+
};
95+
96+
let title = title.unwrap_or_else(|| {
97+
match mode {
98+
CanisterInstallMode::Install => "Install Canister",
99+
CanisterInstallMode::Reinstall => "Reinstall Canister",
100+
CanisterInstallMode::Upgrade => "Upgrade Canister",
101+
}
102+
.to_string()
103+
});
83104

84105
let wasm = std::fs::read(wasm_path).context("Unable to read --wasm-path.")?;
85106
let canister_upgrade_arg = match (canister_upgrade_arg, canister_upgrade_arg_path) {
@@ -100,7 +121,7 @@ pub fn exec(
100121
String::from_utf8(std::fs::read(path).context("Unable to read --summary-path.")?)
101122
.context("Summary must be valid UTF-8.")?
102123
}
103-
(None, None) => summarize(target_canister_id, &wasm),
124+
(None, None) => summarize(target_canister_id, &wasm, mode),
104125
};
105126

106127
let proposal = Proposal {
@@ -112,7 +133,7 @@ pub fn exec(
112133
canister_id: Some(target_canister_id.into()),
113134
new_canister_wasm: wasm,
114135
canister_upgrade_arg,
115-
mode: None,
136+
mode: Some(mode as i32),
116137
},
117138
)),
118139
};
@@ -137,14 +158,20 @@ pub fn exec(
137158
Ok(vec![msg])
138159
}
139160

140-
fn summarize(target_canister_id: Principal, wasm: &Vec<u8>) -> String {
161+
fn summarize(target_canister_id: Principal, wasm: &Vec<u8>, mode: CanisterInstallMode) -> String {
141162
// Fingerprint wasm.
142163
let mut hasher = Sha256::new();
143164
hasher.update(wasm);
144165
let wasm_fingerprint = hex::encode(hasher.finalize());
145166

167+
let action = match mode {
168+
CanisterInstallMode::Install => "Install",
169+
CanisterInstallMode::Reinstall => "Reinstall",
170+
CanisterInstallMode::Upgrade => "Upgrade",
171+
};
172+
146173
format!(
147-
"Upgrade canister:
174+
"{action} canister:
148175
149176
ID: {}
150177

tests/output/default/sns/make_proposal/upgrade.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Sending message with
1010
command = opt variant {
1111
MakeProposal = record {
1212
url = "";
13-
title = "Upgrade Canister";
13+
title = "Install Canister";
1414
action = opt variant {
1515
UpgradeSnsControlledCanister = record {
1616
new_canister_wasm = blob "\00\61\73\6d\01\00\00\00";
17-
mode = null;
17+
mode = opt (1 : int32);
1818
canister_id = opt principal "pycv5-3jbbb-ccccc-ddddd-cai";
1919
canister_upgrade_arg = null;
2020
}
2121
};
22-
summary = "Upgrade canister:\n\n ID: pycv5-3jbbb-ccccc-ddddd-cai\n\n WASM:\n length: 8\n fingerprint: 93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476";
22+
summary = "Install canister:\n\n ID: pycv5-3jbbb-ccccc-ddddd-cai\n\n WASM:\n length: 8\n fingerprint: 93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476";
2323
}
2424
};
2525
},

tests/output/default/sns/make_proposal/upgrade_arg.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Sending message with
1010
command = opt variant {
1111
MakeProposal = record {
1212
url = "";
13-
title = "Upgrade Canister";
13+
title = "Reinstall Canister";
1414
action = opt variant {
1515
UpgradeSnsControlledCanister = record {
1616
new_canister_wasm = blob "\00\61\73\6d\01\00\00\00";
17-
mode = null;
17+
mode = opt (2 : int32);
1818
canister_id = opt principal "pycv5-3jbbb-ccccc-ddddd-cai";
1919
canister_upgrade_arg = opt blob "\44\49\44\4c\01\6c\02\b9\fa\ee\18\79\b5\f6\a1\43\79\01\00\02\00\00\00\03\00\00\00";
2020
}
2121
};
22-
summary = "Upgrade canister:\n\n ID: pycv5-3jbbb-ccccc-ddddd-cai\n\n WASM:\n length: 8\n fingerprint: 93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476";
22+
summary = "Reinstall canister:\n\n ID: pycv5-3jbbb-ccccc-ddddd-cai\n\n WASM:\n length: 8\n fingerprint: 93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476";
2323
}
2424
};
2525
},

tests/output/default/sns/make_proposal/upgrade_summary_path.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Sending message with
1414
action = opt variant {
1515
UpgradeSnsControlledCanister = record {
1616
new_canister_wasm = blob "\00\61\73\6d\01\00\00\00";
17-
mode = null;
17+
mode = opt (3 : int32);
1818
canister_id = opt principal "pycv5-3jbbb-ccccc-ddddd-cai";
1919
canister_upgrade_arg = null;
2020
}

tests/output/sns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ fn make_proposal() {
134134
.diff("sns/make_proposal/from_file.txt");
135135

136136
let canister_wasm = asset("sns_canister.wasm");
137-
quill_sns_send(&format!("sns make-upgrade-canister-proposal {NEURON_ID} --wasm-path '{canister_wasm}' --target-canister-id pycv5-3jbbb-ccccc-ddddd-cai"))
137+
quill_sns_send(&format!("sns make-upgrade-canister-proposal {NEURON_ID} --wasm-path '{canister_wasm}' --target-canister-id pycv5-3jbbb-ccccc-ddddd-cai --mode install"))
138138
.diff("sns/make_proposal/upgrade.txt");
139139
quill_sns_send(&format!("sns make-upgrade-canister-proposal {NEURON_ID} --wasm-path '{canister_wasm}'
140-
--canister-upgrade-arg '(record {{major=2:nat32; minor=3:nat32;}})' --target-canister-id pycv5-3jbbb-ccccc-ddddd-cai"))
140+
--canister-upgrade-arg '(record {{major=2:nat32; minor=3:nat32;}})' --target-canister-id pycv5-3jbbb-ccccc-ddddd-cai --mode reinstall"))
141141
.diff("sns/make_proposal/upgrade_arg.txt");
142142

143143
let upgrade_summary = asset("upgrade_summary.txt");
144144
quill_sns_send(&format!(
145145
"sns make-upgrade-canister-proposal {NEURON_ID} --wasm-path '{canister_wasm}'
146-
--target-canister-id pycv5-3jbbb-ccccc-ddddd-cai --summary-path '{upgrade_summary}'"
146+
--target-canister-id pycv5-3jbbb-ccccc-ddddd-cai --summary-path '{upgrade_summary}' --mode upgrade"
147147
))
148148
.diff("sns/make_proposal/upgrade_summary_path.txt");
149149
}

0 commit comments

Comments
 (0)