onflow / atree

Atree provides scalable arrays and scalable ordered maps.
https://onflow.org
Apache License 2.0
39 stars 13 forks source link

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

Closed fxamacker closed 2 months ago

fxamacker commented 2 months ago

Updates #292 https://github.com/onflow/atree/issues/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 https://github.com/onflow/cadence/pull/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:

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:

turbolent commented 2 months ago

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