Skip to content

Commit

Permalink
automatically trigger upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Nov 8, 2024
1 parent 02fbf21 commit 97bfaff
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ async fn test_get_upgrade_journal() {
expected_upgrade_journal_entries.push(sns_pb::upgrade_journal_entry::Event::TargetVersionSet(
sns_pb::upgrade_journal_entry::TargetVersionSet {
old_target_version: None,
new_target_version: Some(new_sns_version_2),
new_target_version: Some(new_sns_version_2.clone()),
},
));

Expand All @@ -263,4 +263,98 @@ async fn test_get_upgrade_journal() {
&expected_upgrade_journal_entries,
)
.await;

// Check that the target version is set to the new version.
{
let sns_pb::GetUpgradeJournalResponse { target_version, .. } =
sns::governance::get_upgrade_journal(&pocket_ic, sns.governance.canister_id).await;

assert_eq!(target_version, Some(new_sns_version_2.clone()));
}

await_with_timeout(
&pocket_ic,
UPGRADE_STEPS_INTERVAL_REFRESH_BACKOFF_SECONDS,
|pocket_ic| async {
sns::governance::get_upgrade_journal(pocket_ic, sns.governance.canister_id)
.await
.deployed_version
},
&Some(new_sns_version_2.clone()),
)
.await
.unwrap();

// Check that the deployed version is now set to the new version.
{
let sns_pb::GetUpgradeJournalResponse {
deployed_version, ..
} = sns::governance::get_upgrade_journal(&pocket_ic, sns.governance.canister_id).await;

assert_eq!(deployed_version, Some(new_sns_version_2.clone()));
}

// Check that the upgrade journal contains the correct entries.
{
expected_upgrade_journal_entries.push(
sns_pb::upgrade_journal_entry::Event::UpgradeStarted(
sns_pb::upgrade_journal_entry::UpgradeStarted {
current_version: Some(initial_sns_version.clone()),
expected_version: Some(new_sns_version_1.clone()),
reason: Some(
sns_pb::upgrade_journal_entry::upgrade_started::Reason::BehindTargetVersion(
sns_pb::Empty {},
),
),
},
),
);

expected_upgrade_journal_entries.push(
sns_pb::upgrade_journal_entry::Event::UpgradeOutcome(
sns_pb::upgrade_journal_entry::UpgradeOutcome {
status: Some(
sns_pb::upgrade_journal_entry::upgrade_outcome::Status::Success(
sns_pb::Empty {},
),
),
human_readable: None,
},
),
);

expected_upgrade_journal_entries.push(
sns_pb::upgrade_journal_entry::Event::UpgradeStarted(
sns_pb::upgrade_journal_entry::UpgradeStarted {
current_version: Some(new_sns_version_1.clone()),
expected_version: Some(new_sns_version_2.clone()),
reason: Some(
sns_pb::upgrade_journal_entry::upgrade_started::Reason::BehindTargetVersion(
sns_pb::Empty {},
),
),
},
),
);

expected_upgrade_journal_entries.push(
sns_pb::upgrade_journal_entry::Event::UpgradeOutcome(
sns_pb::upgrade_journal_entry::UpgradeOutcome {
status: Some(
sns_pb::upgrade_journal_entry::upgrade_outcome::Status::Success(
sns_pb::Empty {},
),
),
human_readable: None,
},
),
);

assert_upgrade_journal(
&pocket_ic,
sns.governance,
&expected_upgrade_journal_entries,
)
.await;
}
}
2 changes: 1 addition & 1 deletion rs/sns/governance/canister/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ fn get_running_sns_version(_: GetRunningSnsVersionRequest) -> GetRunningSnsVersi
target_version: upgrade_in_progress.target_version.clone(),
mark_failed_at_seconds: upgrade_in_progress.mark_failed_at_seconds,
checking_upgrade_lock: upgrade_in_progress.checking_upgrade_lock,
proposal_id: upgrade_in_progress.proposal_id,
proposal_id: upgrade_in_progress.proposal_id.unwrap_or(0),
});
GetRunningSnsVersionResponse {
deployed_version: governance().proto.deployed_version.clone(),
Expand Down
12 changes: 9 additions & 3 deletions rs/sns/governance/canister/governance.did
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ type GetProposalResponse = record {

type GetRunningSnsVersionResponse = record {
deployed_version : opt Version;
pending_version : opt UpgradeInProgress;
pending_version : opt record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
target_version : opt Version;
};
};

type GetSnsInitializationParametersResponse = record {
Expand Down Expand Up @@ -674,14 +679,14 @@ type TransferSnsTreasuryFunds = record {
type UpgradeInProgress = record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
proposal_id : opt nat64;
target_version : opt Version;
};

type PendingVersion = record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
proposal_id : opt nat64;
target_version : opt Version;
};

Expand Down Expand Up @@ -781,6 +786,7 @@ type GetUpgradeJournalResponse = record {
upgrade_steps : opt Versions;
response_timestamp_seconds : opt nat64;
target_version : opt Version;
deployed_version : opt Version;
upgrade_journal : opt UpgradeJournal;
};

Expand Down
12 changes: 9 additions & 3 deletions rs/sns/governance/canister/governance_test.did
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ type GetProposalResponse = record {

type GetRunningSnsVersionResponse = record {
deployed_version : opt Version;
pending_version : opt UpgradeInProgress;
pending_version : opt record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
target_version : opt Version;
};
};

type GetSnsInitializationParametersResponse = record {
Expand Down Expand Up @@ -688,14 +693,14 @@ type TransferSnsTreasuryFunds = record {
type UpgradeInProgress = record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
proposal_id : opt nat64;
target_version : opt Version;
};

type PendingVersion = record {
mark_failed_at_seconds : nat64;
checking_upgrade_lock : nat64;
proposal_id : nat64;
proposal_id : opt nat64;
target_version : opt Version;
};

Expand Down Expand Up @@ -795,6 +800,7 @@ type GetUpgradeJournalResponse = record {
upgrade_steps : opt Versions;
response_timestamp_seconds : opt nat64;
target_version : opt Version;
deployed_version : opt Version;
upgrade_journal : opt UpgradeJournal;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ message Governance {
// allowing us to fail in case we otherwise have gotten stuck.
uint64 checking_upgrade_lock = 3;
// The proposal that initiated this upgrade
uint64 proposal_id = 4;
optional uint64 proposal_id = 4;
}

// Version SNS is in process of upgrading to.
Expand Down Expand Up @@ -2224,6 +2224,7 @@ message GetUpgradeJournalResponse {
// Currently, this field is always None, but in the "effortless SNS upgrade"
// feature, it reflect the version of the SNS that the community has decided to upgrade to.
Governance.Version target_version = 3;
Governance.Version deployed_version = 5;

UpgradeJournal upgrade_journal = 4;
}
Expand Down
6 changes: 4 additions & 2 deletions rs/sns/governance/src/gen/ic_sns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,8 @@ pub mod governance {
#[prost(uint64, tag = "3")]
pub checking_upgrade_lock: u64,
/// The proposal that initiated this upgrade
#[prost(uint64, tag = "4")]
pub proposal_id: u64,
#[prost(uint64, optional, tag = "4")]
pub proposal_id: ::core::option::Option<u64>,
}
#[derive(
candid::CandidType,
Expand Down Expand Up @@ -3569,6 +3569,8 @@ pub struct GetUpgradeJournalResponse {
/// feature, it reflect the version of the SNS that the community has decided to upgrade to.
#[prost(message, optional, tag = "3")]
pub target_version: ::core::option::Option<governance::Version>,
#[prost(message, optional, tag = "5")]
pub deployed_version: ::core::option::Option<governance::Version>,
#[prost(message, optional, tag = "4")]
pub upgrade_journal: ::core::option::Option<UpgradeJournal>,
}
Expand Down
Loading

0 comments on commit 97bfaff

Please sign in to comment.