Skip to content

Commit a03f9a8

Browse files
authored
chore: Small improvements for the recovery phrase data migration (#3496)
* first * second
1 parent b585fc2 commit a03f9a8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/internet_identity/src/migrations/sync_anchor_indices.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ impl<M: Memory + Clone> Storage<M> {
4545
id_range_lo, anchor_count
4646
);
4747
ic_cdk::println!("ERROR: {}", err);
48+
RECOVERY_PHRASE_MIGRATION_ERRORS.with_borrow_mut(|all_errors| {
49+
all_errors.push(err);
50+
});
51+
52+
// Ensure that migration is not retried endlessly.
53+
ic_cdk::println!("Recovery phrase migration CANCELED.");
54+
RECOVERY_PHRASE_MIGRATION_BATCH_ID.replace(u64::MAX);
4855
return;
4956
};
5057

@@ -69,6 +76,10 @@ impl<M: Memory + Clone> Storage<M> {
6976

7077
let mut errors = vec![];
7178

79+
// This condition is used to terminate the migration in the unlikely event that *all*
80+
// anchors within this entire batch failed to migrate.
81+
let mut batch_did_not_fail_completely = false;
82+
7283
// This is where the index migration happens. For each anchor in the batch, read it
7384
// from storage and write it back, which updates the indices.
7485
for anchor_number in begin..=end {
@@ -86,17 +97,16 @@ impl<M: Memory + Clone> Storage<M> {
8697
Err(err) => {
8798
let err = format!("w#{}:{:?}", anchor_number, err);
8899
errors.push(err);
100+
continue;
89101
}
90102
}
103+
104+
batch_did_not_fail_completely = true;
91105
}
92106

93107
// Whether more batches are to be migrated.
94108
let has_more_work = end < last_anchor_id;
95109

96-
// This condition is used to terminate the migration in the unlikely event that *all*
97-
// anchors within this entire batch failed to migrate.
98-
let batch_did_not_fail_completely = errors.len() < batch_size as usize;
99-
100110
if errors.is_empty() {
101111
ic_cdk::println!("Successfully migrated batch {}..{}", begin, end);
102112
} else {

0 commit comments

Comments
 (0)