Skip to content

Commit

Permalink
chore(sns): Rename SetCustomProposalTopics into `SetTopicsForCustom…
Browse files Browse the repository at this point in the history
…Proposals` (#4185)

This PR renames the (not yet released) proposal type
`SetCustomProposalTopics` into `SetTopicsForCustomProposals`.
  • Loading branch information
aterga authored Mar 1, 2025
1 parent ddcdb2e commit ebb190b
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 64 deletions.
8 changes: 4 additions & 4 deletions rs/sns/governance/api/src/ic_sns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub struct AdvanceSnsTargetVersion {
#[derive(
candid::CandidType, candid::Deserialize, comparable::Comparable, Clone, Debug, PartialEq,
)]
pub struct SetCustomProposalTopics {
pub struct SetTopicsForCustomProposals {
pub custom_function_id_to_topic: BTreeMap<u64, topics::Topic>,
}
/// A proposal is the immutable input of a proposal submission.
Expand Down Expand Up @@ -590,10 +590,10 @@ pub mod proposal {
///
/// Id = 15.
AdvanceSnsTargetVersion(super::AdvanceSnsTargetVersion),
/// SetCustomProposalTopics
/// Set mapping from custom proposal types to topics.
///
/// Id = 16;
SetCustomProposalTopics(super::SetCustomProposalTopics),
SetTopicsForCustomProposals(super::SetTopicsForCustomProposals),
}
}
#[derive(Default, candid::CandidType, candid::Deserialize, Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -795,7 +795,7 @@ pub struct ProposalData {
/// Id 13 - ManageLedgerParameters proposals.
/// Id 14 - ManageDappCanisterSettings proposals.
/// Id 15 - AdvanceSnsTargetVersion proposals.
/// Id 16 - SetCustomProposalTopics proposals.
/// Id 16 - SetTopicsForCustomProposals proposals.
pub action: u64,
/// This is stored here temporarily. It is also stored on the map
/// that contains proposals.
Expand Down
4 changes: 2 additions & 2 deletions rs/sns/governance/canister/governance.did
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Account = record {
type Action = variant {
ManageNervousSystemParameters : NervousSystemParameters;
AddGenericNervousSystemFunction : NervousSystemFunction;
SetCustomProposalTopics : SetCustomProposalTopics;
SetTopicsForCustomProposals : SetTopicsForCustomProposals;
ManageDappCanisterSettings : ManageDappCanisterSettings;
RemoveGenericNervousSystemFunction : nat64;
UpgradeSnsToNextVersion : record {};
Expand Down Expand Up @@ -395,7 +395,7 @@ type AdvanceSnsTargetVersion = record {
new_target : opt SnsVersion;
};

type SetCustomProposalTopics = record {
type SetTopicsForCustomProposals = record {
custom_function_id_to_topic : vec record { nat64; Topic };
};

Expand Down
4 changes: 2 additions & 2 deletions rs/sns/governance/canister/governance_test.did
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Account = record {
type Action = variant {
ManageNervousSystemParameters : NervousSystemParameters;
AddGenericNervousSystemFunction : NervousSystemFunction;
SetCustomProposalTopics : SetCustomProposalTopics;
SetTopicsForCustomProposals : SetTopicsForCustomProposals;
ManageDappCanisterSettings : ManageDappCanisterSettings;
RemoveGenericNervousSystemFunction : nat64;
UpgradeSnsToNextVersion : record {};
Expand Down Expand Up @@ -404,7 +404,7 @@ type AdvanceSnsTargetVersion = record {
new_target : opt SnsVersion;
};

type SetCustomProposalTopics = record {
type SetTopicsForCustomProposals = record {
custom_function_id_to_topic : vec record { nat64; Topic };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ message AdvanceSnsTargetVersion {
optional SnsVersion new_target = 1;
}

message SetCustomProposalTopics {
message SetTopicsForCustomProposals {
map<uint64, Topic> custom_function_id_to_topic = 1;
}

Expand Down Expand Up @@ -606,7 +606,7 @@ message Proposal {
// Change the mapping from custom proposal types to topics.
//
// Id = 16;
SetCustomProposalTopics set_custom_proposal_topics = 20;
SetTopicsForCustomProposals set_topics_for_custom_proposals = 20;
}
}

Expand Down Expand Up @@ -801,7 +801,7 @@ message ProposalData {
// Id 13 - ManageLedgerParameters proposals.
// Id 14 - ManageDappCanisterSettings proposals.
// Id 15 - AdvanceSnsTargetVersion proposals.
// Id 16 - SetCustomProposalTopics proposals.
// Id 16 - SetTopicsForCustomProposals proposals.
uint64 action = 1;

// This is stored here temporarily. It is also stored on the map
Expand Down
6 changes: 3 additions & 3 deletions rs/sns/governance/src/gen/ic_sns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ pub struct AdvanceSnsTargetVersion {
PartialEq,
::prost::Message,
)]
pub struct SetCustomProposalTopics {
pub struct SetTopicsForCustomProposals {
#[prost(btree_map = "uint64, enumeration(Topic)", tag = "1")]
pub custom_function_id_to_topic: ::prost::alloc::collections::BTreeMap<u64, i32>,
}
Expand Down Expand Up @@ -842,7 +842,7 @@ pub mod proposal {
///
/// Id = 16;
#[prost(message, tag = "20")]
SetCustomProposalTopics(super::SetCustomProposalTopics),
SetTopicsForCustomProposals(super::SetTopicsForCustomProposals),
}
}
#[derive(candid::CandidType, candid::Deserialize, comparable::Comparable)]
Expand Down Expand Up @@ -1076,7 +1076,7 @@ pub struct ProposalData {
/// Id 13 - ManageLedgerParameters proposals.
/// Id 14 - ManageDappCanisterSettings proposals.
/// Id 15 - AdvanceSnsTargetVersion proposals.
/// Id 16 - SetCustomProposalTopics proposals.
/// Id 16 - SetTopicsForCustomProposals proposals.
#[prost(uint64, tag = "1")]
pub action: u64,
/// This is stored here temporarily. It is also stored on the map
Expand Down
20 changes: 10 additions & 10 deletions rs/sns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ use crate::{
MintTokensRequest, MintTokensResponse, NervousSystemFunction, NervousSystemParameters,
Neuron, NeuronId, NeuronPermission, NeuronPermissionList, NeuronPermissionType,
Proposal, ProposalData, ProposalDecisionStatus, ProposalId, ProposalRewardStatus,
RegisterDappCanisters, RewardEvent, SetCustomProposalTopics, Tally,
RegisterDappCanisters, RewardEvent, SetTopicsForCustomProposals, Tally,
TransferSnsTreasuryFunds, UpgradeSnsControlledCanister, Vote, WaitForQuietState,
},
},
proposal::{
get_action_auxiliary,
transfer_sns_treasury_funds_amount_is_small_enough_at_execution_time_or_err,
validate_and_render_proposal, validate_and_render_set_custom_proposal_topics,
validate_and_render_proposal, validate_and_render_set_topics_for_custom_proposals,
ValidGenericNervousSystemFunction, MAX_LIST_PROPOSAL_RESULTS,
MAX_NUMBER_OF_PROPOSALS_WITH_BALLOTS,
},
Expand Down Expand Up @@ -2142,8 +2142,8 @@ impl Governance {
})
.and_then(|new_target| self.perform_advance_target_version(new_target))
}
Action::SetCustomProposalTopics(set_custom_proposal_topics) => {
self.perform_set_custom_proposal_topics(set_custom_proposal_topics)
Action::SetTopicsForCustomProposals(set_topics_for_custom_proposals) => {
self.perform_set_topics_for_custom_proposals(set_topics_for_custom_proposals)
}
// This should not be possible, because Proposal validation is performed when
// a proposal is first made.
Expand Down Expand Up @@ -3127,14 +3127,14 @@ impl Governance {
}

// Make a change to the mapping from custom proposal types to topics.
fn perform_set_custom_proposal_topics(
fn perform_set_topics_for_custom_proposals(
&mut self,
set_custom_proposal_topics: SetCustomProposalTopics,
set_topics_for_custom_proposals: SetTopicsForCustomProposals,
) -> Result<(), GovernanceError> {
// This proposal had already been validated at submission time, but the state may have
// change since then, which is why it is being validated again.
if let Err(message) = validate_and_render_set_custom_proposal_topics(
&set_custom_proposal_topics,
if let Err(message) = validate_and_render_set_topics_for_custom_proposals(
&set_topics_for_custom_proposals,
&self.proto.custom_functions_to_topics(),
) {
return Err(GovernanceError::new_with_message(
Expand All @@ -3143,9 +3143,9 @@ impl Governance {
));
}

let SetCustomProposalTopics {
let SetTopicsForCustomProposals {
custom_function_id_to_topic,
} = set_custom_proposal_topics;
} = set_topics_for_custom_proposals;

for (custom_function_id, new_topic) in custom_function_id_to_topic {
let nervous_system_function = self
Expand Down
16 changes: 8 additions & 8 deletions rs/sns/governance/src/pb/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ impl From<pb::AdvanceSnsTargetVersion> for pb_api::AdvanceSnsTargetVersion {
}
}

impl From<pb_api::SetCustomProposalTopics> for pb::SetCustomProposalTopics {
fn from(item: pb_api::SetCustomProposalTopics) -> Self {
impl From<pb_api::SetTopicsForCustomProposals> for pb::SetTopicsForCustomProposals {
fn from(item: pb_api::SetTopicsForCustomProposals) -> Self {
Self {
custom_function_id_to_topic: item
.custom_function_id_to_topic
Expand All @@ -588,8 +588,8 @@ impl From<pb_api::SetCustomProposalTopics> for pb::SetCustomProposalTopics {
}
}
}
impl From<pb::SetCustomProposalTopics> for pb_api::SetCustomProposalTopics {
fn from(item: pb::SetCustomProposalTopics) -> Self {
impl From<pb::SetTopicsForCustomProposals> for pb_api::SetTopicsForCustomProposals {
fn from(item: pb::SetTopicsForCustomProposals) -> Self {
let custom_function_id_to_topic = item
.custom_function_id_to_topic
.into_iter()
Expand Down Expand Up @@ -680,8 +680,8 @@ impl From<pb::proposal::Action> for pb_api::proposal::Action {
pb::proposal::Action::AdvanceSnsTargetVersion(v) => {
pb_api::proposal::Action::AdvanceSnsTargetVersion(v.into())
}
pb::proposal::Action::SetCustomProposalTopics(v) => {
pb_api::proposal::Action::SetCustomProposalTopics(v.into())
pb::proposal::Action::SetTopicsForCustomProposals(v) => {
pb_api::proposal::Action::SetTopicsForCustomProposals(v.into())
}
}
}
Expand Down Expand Up @@ -733,8 +733,8 @@ impl From<pb_api::proposal::Action> for pb::proposal::Action {
pb_api::proposal::Action::AdvanceSnsTargetVersion(v) => {
pb::proposal::Action::AdvanceSnsTargetVersion(v.into())
}
pb_api::proposal::Action::SetCustomProposalTopics(v) => {
pb::proposal::Action::SetCustomProposalTopics(v.into())
pb_api::proposal::Action::SetTopicsForCustomProposals(v) => {
pb::proposal::Action::SetTopicsForCustomProposals(v.into())
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions rs/sns/governance/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cached_upgrade_steps::render_two_versions_as_markdown_table;
use crate::pb::v1::{AdvanceSnsTargetVersion, SetCustomProposalTopics, Topic};
use crate::pb::v1::{AdvanceSnsTargetVersion, SetTopicsForCustomProposals, Topic};
use crate::types::Wasm;
use crate::{
canister_control::perform_execute_generic_nervous_system_function_validate_and_render_call,
Expand Down Expand Up @@ -492,9 +492,9 @@ pub(crate) async fn validate_and_render_action(
advance_sns_target_version,
);
}
proposal::Action::SetCustomProposalTopics(set_custom_proposal_topics) => {
validate_and_render_set_custom_proposal_topics(
set_custom_proposal_topics,
proposal::Action::SetTopicsForCustomProposals(set_topics_for_custom_proposals) => {
validate_and_render_set_topics_for_custom_proposals(
set_topics_for_custom_proposals,
&governance_proto.custom_functions_to_topics(),
)
}
Expand Down Expand Up @@ -1845,17 +1845,18 @@ fn topic_to_str(topic: &Topic) -> &'static str {
}
}

pub(crate) fn validate_and_render_set_custom_proposal_topics(
set_custom_proposal_topics: &SetCustomProposalTopics,
pub(crate) fn validate_and_render_set_topics_for_custom_proposals(
set_topics_for_custom_proposals: &SetTopicsForCustomProposals,
existing_custom_functions: &BTreeMap<u64, (String, Option<Topic>)>,
) -> Result<String, String> {
let SetCustomProposalTopics {
let SetTopicsForCustomProposals {
custom_function_id_to_topic,
} = set_custom_proposal_topics;
} = set_topics_for_custom_proposals;

if custom_function_id_to_topic.is_empty() {
return Err(
"SetCustomProposalTopics.custom_function_id_to_topic must not be empty.".to_string(),
"SetTopicsForCustomProposals.custom_function_id_to_topic must not be empty."
.to_string(),
);
}

Expand Down Expand Up @@ -2725,7 +2726,7 @@ mod minting_tests;
mod advance_sns_target_version;

#[cfg(test)]
mod set_custom_proposal_topics;
mod set_topics_for_custom_proposals;

#[cfg(test)]
mod tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use maplit::btreemap;
use pretty_assertions::assert_eq;

#[test]
fn test_validate_and_render_set_custom_proposal_topics() {
for (set_custom_proposal_topics, existing_custom_functions, expected) in [
fn test_validate_and_render_set_topics_for_custom_proposals() {
for (set_topics_for_custom_proposals, existing_custom_functions, expected) in [
(
SetCustomProposalTopics {
SetTopicsForCustomProposals {
custom_function_id_to_topic: btreemap! {
111_u64 => Topic::DaoCommunitySettings as i32,
},
Expand All @@ -24,7 +24,7 @@ fn test_validate_and_render_set_custom_proposal_topics() {
),
),
(
SetCustomProposalTopics {
SetTopicsForCustomProposals {
custom_function_id_to_topic: btreemap! {
222_u64 => Topic::DaoCommunitySettings as i32,
111_u64 => Topic::DaoCommunitySettings as i32,
Expand All @@ -49,19 +49,19 @@ fn test_validate_and_render_set_custom_proposal_topics() {
),
),
(
SetCustomProposalTopics {
SetTopicsForCustomProposals {
custom_function_id_to_topic: btreemap! {},
},
btreemap! {
111 => ("AAA".to_string(), Some(Topic::Governance)),
},
Err::<String, String>(
"SetCustomProposalTopics.custom_function_id_to_topic must not be empty."
"SetTopicsForCustomProposals.custom_function_id_to_topic must not be empty."
.to_string(),
),
),
(
SetCustomProposalTopics {
SetTopicsForCustomProposals {
custom_function_id_to_topic: btreemap! {
111_u64 => Topic::DaoCommunitySettings as i32,
},
Expand All @@ -77,8 +77,8 @@ fn test_validate_and_render_set_custom_proposal_topics() {
),
),
] {
let observed = validate_and_render_set_custom_proposal_topics(
&set_custom_proposal_topics,
let observed = validate_and_render_set_topics_for_custom_proposals(
&set_topics_for_custom_proposals,
&existing_custom_functions,
);
assert_eq!(observed, expected);
Expand Down
Loading

0 comments on commit ebb190b

Please sign in to comment.