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

Add feature to enable atree inlining migration to fix references to non-existent registers #388

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Apr 11, 2024

Updates #292 #386

Problem

Broken references were found in testnet data and they seem to have resulted from a bug that was fixed 2 years ago by onflow/cadence#1565.

A broken reference is a StorageID referencing a non-existent register. So far, only 10 registers in testnet (none on mainnet) were found to contain broken references.

Solution

Port from non-inlining version of the solution:

This PR adds a feature to enable migration programs in onflow/flow-go to fix broken references in maps.

FixLoadedBrokenReferences() traverses loaded slabs and replaces broken map (if any) with empty map having the same StorageID and also removes all slabs in the old map.

Limitations:

  • only fix broken references in map (this is intentional)
  • only traverse loaded slabs in deltas and cache

IMPORTANT: This should not be used to silently fix unknown problems. It should only be used by migration programs to fix known problems which were determined to be appropriate to fix in this manner.

TODO:

  • Add more tests and increase code coverage

  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

In testnet, broken references seem to have resulted from a bug that was
fixed 2 years ago by onflow/cadence#1565.

A broken reference is a `StorageID` referencing a non-existent register.
So far, only 10 registers in testnet (none on mainnet) were found to
contain broken references.

This commit adds a feature to enable migration programs in onflow/flow-go
to fix broken references in maps.

`FixLoadedBrokenReferences()` traverses loaded slabs and replaces
broken map (if any) with empty map having the same StorageID and
also removes all slabs in the old map.

Limitations:
- only fix broken references in map (this is intentional)
- only traverse loaded slabs in deltas and cache

IMPORTANT: This should not be used to silently fix unknown problems.
It should only be used by migration programs to fix known problems
which were determined to be appropriate to fix in this manner.
@fxamacker fxamacker added the enhancement New feature or request label Apr 11, 2024
@fxamacker fxamacker self-assigned this Apr 11, 2024
@turbolent
Copy link
Member

LGTM! As this is basically the same as #387, I have the same feedback. Once that other PR is in, it would be good to update this PR in a similar way

fxamacker and others added 4 commits April 17, 2024 08:41
Co-authored-by: Bastian Müller <[email protected]>
Currently, calls to this function can be limited by migration
programs by specifying the 9 testnet accounts affected by 10
registers with broken references on testnet.

This commit allows callers to implement additional restrictions,
so calling FixLoadedBrokenReferences for the affected 9 testnet
accounts can be even more limited at the callers discretion.

In practice, this change is not expected to produce different
migration results because full migration tests before this change
correctly fixed the 10 known registers in the 9 testnet accounts.

This commit added predicate func(old Value) bool to
PersistentSlabStorage.FixLoadedBrokenReferences() to control
whether to fix a atree.Value containing broken references.

Also modified PersistentSlabStorage.FixLoadedBrokenReferences()
to return fixed storage IDs and skipped storage IDs.  Both returned
values are of type map[StorageID][]StorageID, with key as
root slab ID and value as all slab IDs containing broken references
connected to the root.

Also added more tests and improved existing tests.
This commit adds GetAllChildReferences() which essentially wraps
an existing internal function.
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice work!

…ences-for-atree-inlining

Add PersistentSlabStorage.GetAllChildReferences() for atree inlining
@turbolent turbolent requested a review from a team April 17, 2024 17:40
@fxamacker fxamacker merged commit e11f55f into feature/array-map-inlining Apr 17, 2024
7 checks passed
fxamacker added a commit to onflow/flow-go that referenced this pull request Apr 22, 2024
This commit adds --fix-testnet-slabs-with-broken-references flag
to the migration program.

It uses a feature from onflow/atree#388 to fix 10 testnet registers
affecting 9 testnet accounts.

The 9 testnet accounts are hardcoded in this commit to prevent
accidentally applying this fix to any other accounts.

In testnet, broken references seem to have resulted from a bug
that was fixed 2 years ago by onflow/cadence#1565.

A broken reference is a `StorageID` referencing a non-existent register.
So far, only 10 registers in testnet (none on mainnet) were found to
contain broken references.
turbolent pushed a commit to onflow/flow-go that referenced this pull request Apr 23, 2024
This commit adds --fix-testnet-slabs-with-broken-references flag
to the migration program.

It uses a feature from onflow/atree#388 to fix 10 testnet registers
affecting 9 testnet accounts.

The 9 testnet accounts are hardcoded in this commit to prevent
accidentally applying this fix to any other accounts.

In testnet, broken references seem to have resulted from a bug
that was fixed 2 years ago by onflow/cadence#1565.

A broken reference is a `StorageID` referencing a non-existent register.
So far, only 10 registers in testnet (none on mainnet) were found to
contain broken references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants