Skip to content

Commit b2e8302

Browse files
Added success_value to ProposalData and ProposalInfo.
1 parent 58adb1e commit b2e8302

File tree

23 files changed

+430
-134
lines changed

23 files changed

+430
-134
lines changed

Cargo.lock

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

rs/nervous_system/string/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt::Debug;
66
/// More precisely, middle characters are removed such that the return value has at most `max_len`
77
/// characters. Some examples:
88
/// ```
9+
/// use ic_nervous_system_string::clamp_string_len;
910
/// println!("{}", clamp_string_len("abcdef", 5)); // a...f
1011
/// println!("{}", clamp_string_len("abcde", 5)); // abcde
1112
/// println!("{}", clamp_string_len("abcd", 5)); // abcd
@@ -41,5 +42,15 @@ pub fn clamp_debug_len(object: &impl Debug, max_len: usize) -> String {
4142
clamp_string_len(&format!("{object:#?}"), max_len)
4243
}
4344

45+
/// Hex-encodes bytes, truncating with a summary if longer than `max_bytes`.
46+
pub fn humanize_blob(bytes: &[u8], max_bytes: usize) -> String {
47+
if bytes.len() <= max_bytes {
48+
bytes.iter().map(|b| format!("{b:02x}")).collect()
49+
} else {
50+
let hex: String = bytes[..max_bytes].iter().map(|b| format!("{b:02x}")).collect();
51+
format!("{hex}... ({} bytes total)", bytes.len())
52+
}
53+
}
54+
4455
#[cfg(test)]
4556
mod tests;

rs/nns/governance/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ DEPENDENCIES = [
7575
"//rs/nervous_system/rate_limits",
7676
"//rs/nervous_system/root",
7777
"//rs/nervous_system/runtime",
78+
"//rs/nervous_system/string",
7879
"//rs/nervous_system/temporary",
7980
"//rs/nervous_system/time_helpers",
8081
"//rs/nervous_system/timer_task",

rs/nns/governance/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ ic-metrics-encoder = "1"
4343
ic-nervous-system-canisters = { path = "../../nervous_system/canisters" }
4444
ic-nervous-system-clients = { path = "../../nervous_system/clients" }
4545
ic-nervous-system-common = { path = "../../nervous_system/common" }
46+
ic-nervous-system-string = { path = "../../nervous_system/string" }
4647
ic-nervous-system-common-build-metadata = { path = "../../nervous_system/common/build_metadata" }
4748
ic-nervous-system-common-validation = { path = "../../nervous_system/common/validation" }
4849
ic-nervous-system-governance = { path = "../../nervous_system/governance" }

rs/nns/governance/api/src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,21 @@ pub struct ProposalInfo {
20532053
pub deadline_timestamp_seconds: Option<u64>,
20542054
pub derived_proposal_information: Option<DerivedProposalInformation>,
20552055
pub total_potential_voting_power: ::core::option::Option<u64>,
2056+
/// When an adopted proposal has been executed successfully, this may contain
2057+
/// a value produced by the execution. This is the dual of failure_reason.
2058+
pub success_value: Option<SuccessfulProposalExecutionValue>,
2059+
}
2060+
2061+
/// A value produced by successfully executing a proposal.
2062+
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, Clone, PartialEq, Debug)]
2063+
pub enum SuccessfulProposalExecutionValue {
2064+
CreateCanisterAndInstallCode(CreateCanisterAndInstallCodeOk),
2065+
}
2066+
2067+
/// The result of a successful CreateCanisterAndInstallCode proposal execution.
2068+
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, Clone, PartialEq, Debug)]
2069+
pub struct CreateCanisterAndInstallCodeOk {
2070+
pub canister_id: Option<PrincipalId>,
20562071
}
20572072

20582073
/// Network economics contains the parameters for several operations related

rs/nns/governance/canister/governance.did

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ type CreateCanisterAndInstallCodeRequest = record {
247247
install_arg : opt blob;
248248
};
249249

250+
type CreateCanisterAndInstallCodeOk = record {
251+
canister_id : opt principal;
252+
};
253+
254+
type SuccessfulProposalExecutionValue = variant {
255+
CreateCanisterAndInstallCode : CreateCanisterAndInstallCodeOk;
256+
};
257+
250258
type CreateServiceNervousSystem = record {
251259
url : opt text;
252260
governance_parameters : opt GovernanceParameters;
@@ -1163,6 +1171,7 @@ type ProposalData = record {
11631171
original_total_community_fund_maturity_e8s_equivalent : opt nat64;
11641172
total_potential_voting_power : opt nat64;
11651173
topic: opt int32;
1174+
success_value : opt SuccessfulProposalExecutionValue;
11661175
};
11671176

11681177
type ProposalInfo = record {
@@ -1184,6 +1193,7 @@ type ProposalInfo = record {
11841193
proposer : opt NeuronId;
11851194
executed_timestamp_seconds : nat64;
11861195
total_potential_voting_power : opt nat64;
1196+
success_value : opt SuccessfulProposalExecutionValue;
11871197
};
11881198

11891199
type RegisterVote = record {

rs/nns/governance/proto/ic_nns_governance/pb/v1/governance.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,25 @@ message ProposalData {
12471247
// field should not be set in normal circumstances, and if it is set, it is an indicator that a
12481248
// bug might have caused the voting power spike.
12491249
optional uint64 previous_ballots_timestamp_seconds = 24;
1250+
1251+
// When an adopted proposal has been executed successfully, this may contain
1252+
// a value produced by the execution (e.g. the ID of a newly created canister).
1253+
// This is the dual of failure_reason: that field is populated on failure,
1254+
// this field is populated on success.
1255+
optional SuccessfulProposalExecutionValue success_value = 25;
1256+
}
1257+
1258+
// A value produced by successfully executing a proposal.
1259+
// Not all proposal types produce a value; for those that don't, this field
1260+
// is simply not set.
1261+
message SuccessfulProposalExecutionValue {
1262+
oneof proposal_type {
1263+
CreateCanisterAndInstallCodeOk create_canister_and_install_code = 1;
1264+
}
1265+
}
1266+
1267+
message CreateCanisterAndInstallCodeOk {
1268+
ic_base_types.pb.v1.PrincipalId canister_id = 1;
12501269
}
12511270

12521271
// This structure contains data for settling the Neurons' Fund participation in an SNS token swap.

rs/nns/governance/src/canister_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Environment for CanisterEnv {
189189
execute_nns_function: &ValidExecuteNnsFunction,
190190
) -> Result<(), crate::pb::v1::GovernanceError> {
191191
let reply = move || {
192-
governance_mut().set_proposal_execution_status(proposal_id, Ok(()));
192+
governance_mut().set_proposal_execution_status::<()>(proposal_id, Ok(vec![]));
193193
};
194194
let reject = move |(code, msg): (i32, String)| {
195195
let mut msg = msg;
@@ -209,7 +209,7 @@ impl Environment for CanisterEnv {
209209
.collect();
210210
}
211211

212-
governance_mut().set_proposal_execution_status(
212+
governance_mut().set_proposal_execution_status::<()>(
213213
proposal_id,
214214
Err(GovernanceError::new_with_message(
215215
ErrorType::External,

rs/nns/governance/src/gen/ic_nns_governance.pb.v1.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,60 @@ pub struct ProposalData {
15201520
/// bug might have caused the voting power spike.
15211521
#[prost(uint64, optional, tag = "24")]
15221522
pub previous_ballots_timestamp_seconds: ::core::option::Option<u64>,
1523+
/// When an adopted proposal has been executed successfully, this may contain
1524+
/// a value produced by the execution (e.g. the ID of a newly created canister).
1525+
/// This is the dual of failure_reason: that field is populated on failure,
1526+
/// this field is populated on success.
1527+
#[prost(message, optional, tag = "25")]
1528+
pub success_value: ::core::option::Option<SuccessfulProposalExecutionValue>,
1529+
}
1530+
/// A value produced by successfully executing a proposal.
1531+
/// Not all proposal types produce a value; for those that don't, this field
1532+
/// is simply not set.
1533+
#[derive(
1534+
candid::CandidType,
1535+
candid::Deserialize,
1536+
serde::Serialize,
1537+
comparable::Comparable,
1538+
Clone,
1539+
PartialEq,
1540+
::prost::Message,
1541+
)]
1542+
pub struct SuccessfulProposalExecutionValue {
1543+
#[prost(
1544+
oneof = "successful_proposal_execution_value::ProposalType",
1545+
tags = "1"
1546+
)]
1547+
pub proposal_type: ::core::option::Option<successful_proposal_execution_value::ProposalType>,
1548+
}
1549+
/// Nested message and enum types in `SuccessfulProposalExecutionValue`.
1550+
pub mod successful_proposal_execution_value {
1551+
#[derive(
1552+
candid::CandidType,
1553+
candid::Deserialize,
1554+
serde::Serialize,
1555+
comparable::Comparable,
1556+
Clone,
1557+
PartialEq,
1558+
::prost::Oneof,
1559+
)]
1560+
pub enum ProposalType {
1561+
#[prost(message, tag = "1")]
1562+
CreateCanisterAndInstallCode(super::CreateCanisterAndInstallCodeOk),
1563+
}
1564+
}
1565+
#[derive(
1566+
candid::CandidType,
1567+
candid::Deserialize,
1568+
serde::Serialize,
1569+
comparable::Comparable,
1570+
Clone,
1571+
PartialEq,
1572+
::prost::Message,
1573+
)]
1574+
pub struct CreateCanisterAndInstallCodeOk {
1575+
#[prost(message, optional, tag = "1")]
1576+
pub canister_id: ::core::option::Option<::ic_base_types::PrincipalId>,
15231577
}
15241578
/// This structure contains data for settling the Neurons' Fund participation in an SNS token swap.
15251579
#[derive(

0 commit comments

Comments
 (0)