Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate stable memory back-ups to v9 #2368

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/internet_identity/stable_memory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ These tests serve two purposes:
## Stable Memory Backups

The following stable memory backups are currently used:
* `buffered_archive_entries_v8.bin.gz`: a backup with buffered archive entries.
* `buffered_archive_entries_v9.bin.gz`: a backup with buffered archive entries.
* `clean_init_v8.bin.gz`: a clean initial state with storage layout v8. Used to test that II can be upgraded from v8
storage layout.
* `genesis-layout-migrated-to-v8.bin.gz`: a backup initially created with the first version of the stable memory layout and then incrementally migrated to the v8 layout. It contains a few well-known identities / devices, see `known_devices` in `tests/integration/stable_memory.rs`.
* `genesis-layout-migrated-to-v9.bin.gz`: a backup initially created with the first version of the stable memory layout and then incrementally migrated to the v8 layout. It contains a few well-known identities / devices, see `known_devices` in `tests/integration/stable_memory.rs`.
* `genesis-memory-layout.bin`: a backup of the initial memory layout. Not migrated. Mainly used to test behavior with respect to outdated / unsupported memory layouts.
* `multiple-recovery-phrases-v8.bin.gz`: a backup with an identity that has multiple recovery phrases. The input validation does no longer allow to create such an identity (only one recovery phrase is allowed). However, legacy users that are in that state need a way to make their identity consistent again. This backup is used to test exactly that.
* `no-persistent-state-v8.bin.gz`: a backup without persistent state. Used to check that II indeed fails to upgrade from such a state.
* `persistent_state_archive_v8.bin.gz`: a backup to check that archive state and configuration are restored correctly.
* `persistent_state_no_archive_v8.bin.gz`: a backup to check that persistent state without an archive is restored correctly.
* `multiple-recovery-phrases-v9.bin.gz`: a backup with an identity that has multiple recovery phrases. The input validation does no longer allow to create such an identity (only one recovery phrase is allowed). However, legacy users that are in that state need a way to make their identity consistent again. This backup is used to test exactly that.
* `persistent_state_archive_v9.bin.gz`: a backup to check that archive state and configuration are restored correctly.
* `persistent_state_no_archive_v9.bin.gz`: a backup to check that persistent state without an archive is restored correctly.

## Creating New Test Memory Backups

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ mod pull_entries_tests {
restore_compressed_stable_memory(
&env,
ii_canister,
"stable_memory/buffered_archive_entries_v8.bin.gz",
"stable_memory/buffered_archive_entries_v9.bin.gz",
);
upgrade_ii_canister_with_arg(
&env,
Expand Down
41 changes: 7 additions & 34 deletions src/internet_identity/tests/integration/stable_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn should_issue_same_principal_after_restoring_backup() -> Result<(), CallError>
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/genesis-layout-migrated-to-v8.bin.gz",
"stable_memory/genesis-layout-migrated-to-v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand Down Expand Up @@ -110,7 +110,7 @@ fn should_modify_devices_after_restoring_backup() -> Result<(), CallError> {
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/genesis-layout-migrated-to-v8.bin.gz",
"stable_memory/genesis-layout-migrated-to-v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand Down Expand Up @@ -144,7 +144,7 @@ fn should_not_break_on_multiple_legacy_recovery_phrases() -> Result<(), CallErro
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/multiple-recovery-phrases-v8.bin.gz",
"stable_memory/multiple-recovery-phrases-v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand Down Expand Up @@ -179,7 +179,7 @@ fn should_allow_modification_after_deleting_second_recovery_phrase() -> Result<(
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/multiple-recovery-phrases-v8.bin.gz",
"stable_memory/multiple-recovery-phrases-v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand Down Expand Up @@ -220,14 +220,14 @@ fn should_allow_modification_after_deleting_second_recovery_phrase() -> Result<(
}

#[test]
fn should_read_persistent_state_v8() -> Result<(), CallError> {
fn should_read_persistent_state_without_archive() -> Result<(), CallError> {
let env = env();
let canister_id = install_ii_canister(&env, EMPTY_WASM.clone());

restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/persistent_state_no_archive_v8.bin.gz",
"stable_memory/persistent_state_no_archive_v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand All @@ -251,7 +251,7 @@ fn should_read_persistent_state_with_archive() -> Result<(), CallError> {
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/persistent_state_archive_v8.bin.gz",
"stable_memory/persistent_state_archive_v9.bin.gz",
);
upgrade_ii_canister(&env, canister_id, II_WASM.clone());

Expand Down Expand Up @@ -300,30 +300,3 @@ fn should_trap_on_old_stable_memory() -> Result<(), CallError> {
}
Ok(())
}

/// Tests that II will refuse to upgrade on stable memory without persistent state.
#[test]
fn should_trap_on_missing_persistent_state() -> Result<(), CallError> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v9 persistent state exists by definition. Hence a back-up without one can no longer be created.

let env = env();
let canister_id = install_ii_canister(&env, EMPTY_WASM.clone());
restore_compressed_stable_memory(
&env,
canister_id,
"stable_memory/no-persistent-state-v8.bin.gz",
);

let result = upgrade_ii_canister_with_arg(&env, canister_id, II_WASM.clone(), None);

assert!(result.is_err());
let err = result.err().unwrap();
match err {
CallError::Reject(err) => panic!("unexpected error {err}"),
CallError::UserError(err) => {
assert_eq!(err.code, CanisterCalledTrap);
assert!(err
.description
.contains("failed to recover persistent state!"));
}
}
Ok(())
}
Loading