Skip to content

Commit

Permalink
automatically trigger upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Oct 31, 2024
1 parent b46ebe7 commit 3c5f154
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 38 deletions.
109 changes: 106 additions & 3 deletions rs/nervous_system/integration_tests/tests/advance_target_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ async fn assert_upgrade_journal(
let upgrade_journal = upgrade_journal.unwrap().entries;
assert_eq!(upgrade_journal.len(), expected_entries.len());

for (actual, expected) in upgrade_journal.iter().zip(expected_entries.iter()) {
for (index, (actual, expected)) in upgrade_journal
.iter()
.zip(expected_entries.iter())
.enumerate()
{
assert!(actual.timestamp_seconds.is_some());
assert_eq!(&actual.event, &Some(expected.clone()));
assert_eq!(
&actual.event,
&Some(expected.clone()),
"Upgrade journal entry at index {} does not match",
index
);
}
}

Expand Down Expand Up @@ -241,7 +250,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 @@ -251,4 +260,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 @@ -2218,7 +2218,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 @@ -3584,6 +3584,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 3c5f154

Please sign in to comment.