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 5, 2024
1 parent 366566c commit 237faf2
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 39 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;
}
}
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 @@ -2210,7 +2210,8 @@ 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 @@ -3540,6 +3540,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 237faf2

Please sign in to comment.