Skip to content

Commit

Permalink
Merge branch 'NNS1-2296-p3' into 'master'
Browse files Browse the repository at this point in the history
[NNS1-2296] Add new Swap canister parameters to the SnsInitPayload

In this MR I've added new parameters to SnsInitPayload needed to populate the Swap Canister's new install payload defined in this MR [!13198](https://gitlab.com/dfinity-lab/public/ic/-/merge_requests/13198). 

The biggest change is introducing a new type in  NNS Governance called `ExecutedCreateServiceNervousSystemProposal` and used that to package proposal data like `executed_timestamp` and `proposal_id`, and adapted the `try_from` pattern to support creating the new SnsInitPayload. 

This is a backwards compatible change as the SNS-W is not making any use of the new fields in its request object, so they will default to None. The remaining TODOs that will be covered in the next MR is to add validation in the sns/init crate for the new unused fields. I'll also need to update the `execute_create_service_nervous_system` to draw maturity from the neurons' fund. 

See merge request dfinity-lab/public/ic!13258
  • Loading branch information
Daniel Thurau committed Jul 5, 2023
2 parents b3db266 + 2379fb9 commit 2a268fd
Show file tree
Hide file tree
Showing 24 changed files with 872 additions and 72 deletions.
2 changes: 1 addition & 1 deletion rs/nns/governance/protobuf_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ProtoPaths<'a> {
pub ledger: &'a Path,
pub sns_swap: &'a Path,

// Indirectly requiredby sns_swap
// Indirectly required by sns_swap
pub sns_root: &'a Path,
}

Expand Down
45 changes: 32 additions & 13 deletions rs/nns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use crate::{
RewardNodeProviders, SetSnsTokenSwapOpenTimeWindow, SettleCommunityFundParticipation,
SwapBackgroundInformation, Tally, Topic, UpdateNodeProvider, Vote, WaitForQuietState,
},
proposals::create_service_nervous_system::create_service_nervous_system_proposals_is_enabled,
proposals::create_service_nervous_system::{
create_service_nervous_system_proposals_is_enabled,
ExecutedCreateServiceNervousSystemProposal,
},
};
use async_trait::async_trait;
use candid::{Decode, Encode};
Expand Down Expand Up @@ -4399,8 +4402,24 @@ impl Governance {
proposal_id: u64,
create_service_nervous_system: &CreateServiceNervousSystem,
) {
// Get the current time of proposal execution.
let current_timestamp_seconds = self.env.now();

// TODO NNS1-2296: Draw from the Neurons' Fund
let neurons_fund_participants = vec![];

let executed_create_service_nervous_system_proposal =
ExecutedCreateServiceNervousSystemProposal {
current_timestamp_seconds,
create_service_nervous_system: create_service_nervous_system.clone(),
proposal_id,
neurons_fund_participants,
};

let execute_create_service_nervous_system_result = self
.execute_create_service_nervous_system_proposal(create_service_nervous_system)
.execute_create_service_nervous_system_proposal(
executed_create_service_nervous_system_proposal,
)
.await;
self.set_proposal_execution_status(
proposal_id,
Expand All @@ -4410,19 +4429,19 @@ impl Governance {

async fn execute_create_service_nervous_system_proposal(
&mut self,
create_service_nervous_system: &CreateServiceNervousSystem,
executed_create_service_nervous_system_proposal: ExecutedCreateServiceNervousSystemProposal,
) -> Result<(), GovernanceError> {
// Step 1: Convert proposal into main request object.
let sns_init_payload = match SnsInitPayload::try_from(create_service_nervous_system.clone())
{
Ok(ok) => ok,
Err(err) => {
return Err(GovernanceError::new_with_message(
ErrorType::InvalidProposal,
format!("Failed to convert proposal to SnsInitPayload: {}", err,),
))
}
};
let sns_init_payload =
match SnsInitPayload::try_from(executed_create_service_nervous_system_proposal) {
Ok(ok) => ok,
Err(err) => {
return Err(GovernanceError::new_with_message(
ErrorType::InvalidProposal,
format!("Failed to convert proposal to SnsInitPayload: {}", err,),
))
}
};

// Step 2 (main): Call deploy_new_sns method on the SNS_WASM canister.
let request = DeployNewSnsRequest {
Expand Down
35 changes: 26 additions & 9 deletions rs/nns/governance/src/governance/test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod src {
developer_distribution::NeuronDistribution, DeveloperDistribution, SwapDistribution,
TreasuryDistribution,
},
swap_parameters::NeuronBasketConstructionParameters,
GovernanceParameters, InitialTokenDistribution, LedgerParameters, SwapParameters,
};
} // end mod src
Expand Down Expand Up @@ -120,15 +121,31 @@ lazy_static! {
iso_codes: vec!["CH".to_string()]
}),

// Not used.
minimum_participants: None,
minimum_icp: None,
maximum_icp: None,
minimum_participant_icp: None,
maximum_participant_icp: None,
neuron_basket_construction_parameters: None,
start_time: None,
duration: None,
minimum_participants: Some(500),
minimum_icp: Some(pb::Tokens {
e8s: Some(12_300_000_000),
}),
maximum_icp: Some(pb::Tokens {
e8s: Some(321_000_000_000),
}),
minimum_participant_icp: Some(pb::Tokens {
e8s: Some(150_000_000)
}),
maximum_participant_icp: Some(pb::Tokens {
e8s: Some(500_000_000)
}),
neuron_basket_construction_parameters: Some(src::NeuronBasketConstructionParameters {
count: Some(5),
dissolve_delay_interval: Some(pb::Duration {
seconds: Some(10_001),
})
}),
start_time: Some(pb::GlobalTimeOfDay {
seconds_after_utc_midnight: Some(0),
}),
duration: Some(pb::Duration {
seconds: Some(604_800),
}),
})
};
}
Loading

0 comments on commit 2a268fd

Please sign in to comment.