Skip to content

Commit

Permalink
refactor(sns): Move get_upgrade_journal to upgrade_journal.rs (#2872)
Browse files Browse the repository at this point in the history
This improves organization because now all the upgrade_journal logic is
collected in the same file. This is just a move, no behavior was
changed.
  • Loading branch information
anchpop authored Nov 27, 2024
1 parent 23dfb95 commit f89ff3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
41 changes: 9 additions & 32 deletions rs/sns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ use crate::{
GetMaturityModulationRequest, GetMaturityModulationResponse, GetMetadataRequest,
GetMetadataResponse, GetMode, GetModeResponse, GetNeuron, GetNeuronResponse,
GetProposal, GetProposalResponse, GetSnsInitializationParametersRequest,
GetSnsInitializationParametersResponse, GetUpgradeJournalResponse,
Governance as GovernanceProto, GovernanceError, ListNervousSystemFunctionsResponse,
ListNeurons, ListNeuronsResponse, ListProposals, ListProposalsResponse,
ManageDappCanisterSettings, ManageLedgerParameters, ManageNeuron, ManageNeuronResponse,
ManageSnsMetadata, MintSnsTokens, MintTokensRequest, MintTokensResponse,
NervousSystemFunction, NervousSystemParameters, Neuron, NeuronId, NeuronPermission,
NeuronPermissionList, NeuronPermissionType, Proposal, ProposalData,
ProposalDecisionStatus, ProposalId, ProposalRewardStatus, RegisterDappCanisters,
RewardEvent, Tally, TransferSnsTreasuryFunds, UpgradeSnsControlledCanister, Vote,
WaitForQuietState,
GetSnsInitializationParametersResponse, Governance as GovernanceProto, GovernanceError,
ListNervousSystemFunctionsResponse, ListNeurons, ListNeuronsResponse, ListProposals,
ListProposalsResponse, ManageDappCanisterSettings, ManageLedgerParameters,
ManageNeuron, ManageNeuronResponse, ManageSnsMetadata, MintSnsTokens,
MintTokensRequest, MintTokensResponse, NervousSystemFunction, NervousSystemParameters,
Neuron, NeuronId, NeuronPermission, NeuronPermissionList, NeuronPermissionType,
Proposal, ProposalData, ProposalDecisionStatus, ProposalId, ProposalRewardStatus,
RegisterDappCanisters, RewardEvent, Tally, TransferSnsTreasuryFunds,
UpgradeSnsControlledCanister, Vote, WaitForQuietState,
},
},
proposal::{
Expand Down Expand Up @@ -5056,28 +5055,6 @@ impl Governance {
self.upgrade_periodic_task_lock = None;
}

pub fn get_upgrade_journal(&self) -> GetUpgradeJournalResponse {
let cached_upgrade_steps = self.proto.cached_upgrade_steps.clone();
match cached_upgrade_steps {
Some(cached_upgrade_steps) => GetUpgradeJournalResponse {
upgrade_steps: cached_upgrade_steps.upgrade_steps,
response_timestamp_seconds: cached_upgrade_steps.response_timestamp_seconds,
target_version: self.proto.target_version.clone(),
deployed_version: self.proto.deployed_version.clone(),
// TODO(NNS1-3416): Bound the size of the response.
upgrade_journal: self.proto.upgrade_journal.clone(),
},
None => GetUpgradeJournalResponse {
upgrade_steps: None,
response_timestamp_seconds: None,
target_version: None,
deployed_version: self.proto.deployed_version.clone(),
// TODO(NNS1-3416): Bound the size of the response.
upgrade_journal: self.proto.upgrade_journal.clone(),
},
}
}

// This is a test-only function, so panicking should be okay.
pub fn advance_target_version(
&mut self,
Expand Down
24 changes: 23 additions & 1 deletion rs/sns/governance/src/upgrade_journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::governance::Governance;
use crate::pb::v1::{
governance::{Version, Versions},
upgrade_journal_entry::{self, upgrade_outcome, upgrade_started},
Empty, ProposalId, UpgradeJournal, UpgradeJournalEntry,
Empty, GetUpgradeJournalResponse, ProposalId, UpgradeJournal, UpgradeJournalEntry,
};

impl upgrade_journal_entry::UpgradeStepsRefreshed {
Expand Down Expand Up @@ -128,6 +128,28 @@ impl Governance {
}
}
}

pub fn get_upgrade_journal(&self) -> GetUpgradeJournalResponse {
let cached_upgrade_steps = self.proto.cached_upgrade_steps.clone();
match cached_upgrade_steps {
Some(cached_upgrade_steps) => GetUpgradeJournalResponse {
upgrade_steps: cached_upgrade_steps.upgrade_steps,
response_timestamp_seconds: cached_upgrade_steps.response_timestamp_seconds,
target_version: self.proto.target_version.clone(),
deployed_version: self.proto.deployed_version.clone(),
// TODO(NNS1-3416): Bound the size of the response.
upgrade_journal: self.proto.upgrade_journal.clone(),
},
None => GetUpgradeJournalResponse {
upgrade_steps: None,
response_timestamp_seconds: None,
target_version: None,
deployed_version: self.proto.deployed_version.clone(),
// TODO(NNS1-3416): Bound the size of the response.
upgrade_journal: self.proto.upgrade_journal.clone(),
},
}
}
}

impl From<upgrade_journal_entry::UpgradeStepsRefreshed> for upgrade_journal_entry::Event {
Expand Down

0 comments on commit f89ff3b

Please sign in to comment.