chore: Force-sync all indices in sync_anchor_indices#3659
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the anchor index migration logic so that indices can be (re)built for already-existing anchors by treating the “previous index state” as empty rather than relying on a read→write roundtrip.
Changes:
- Add
Storage::force_sync_all_indices()to rebuild all anchor-derived indices from the storedStorableAnchorusing empty “previous” data. - Update
sync_anchor_indicesmigration to callforce_sync_all_indicesinstead of read+write. - Extend migration tests to simulate empty indices and verify passkey pubkey-hash indexing across single- and multi-batch runs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/internet_identity/src/storage.rs |
Introduces force_sync_all_indices() to rebuild indices for an existing StorableAnchor without rewriting the anchor. |
src/internet_identity/src/migrations/sync_anchor_indices.rs |
Switches the migration to force-sync indices and adds assertions for the new passkey pubkey-hash index behavior in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e841c2b to
54e294d
Compare
…internet-identity into arshavir/force-sync-all-indices
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+712
to
+716
| /// Force-sync the passkey pubkey index for an anchor by reading its current `StorableAnchor` | ||
| /// and syncing indices with empty previous data. This is intended for data migrations | ||
| /// where the `StorableAnchor` already exists in `stable_anchor_memory` but the index | ||
| /// was not yet populated. | ||
| pub(crate) fn force_sync_all_indices( |
Comment on lines
+87
to
+88
| // force-sync its indices with empty previous data so that all current entries | ||
| // get added to the indices (even if the StorableAnchor already existed). |
| /// * version 1-8: no longer supported | ||
| /// * version 9: 4KB anchors, candid anchor record layout, persistent state in virtual memory, | ||
| /// with memory manager (from 2nd page on), archive entries buffer in stable memory | ||
| /// * version 10: passkey pubkey hash index key type changed from [u8; 32] to Principal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Indices computed based on pre-existing data cannot be synched for existing anchors simply by reading and then writing the anchor memory. Instead, the previous state of each index to be force-updated should be empty. In particular, this enables correctly populating the new
lookup_anchor_with_passkey_pubkey_hash_memoryindex.