Skip to content

Commit

Permalink
Fix GetAllChildReferences used by migration filter
Browse files Browse the repository at this point in the history
Migration programs in onflow/flow-go added a flag to filter
old unreferenced slabs and onflow/atree added some functions
to support that. However, some of the old unreferenced slabs
are not filtered during migration.

This commit fixes the migration filter by handling nested
storage ID inside element such as Cadence SomeValue.
  • Loading branch information
fxamacker committed Apr 26, 2024
1 parent ef6dd7e commit 27b51f7
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 23 deletions.
71 changes: 48 additions & 23 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,40 +1071,60 @@ func (s *PersistentSlabStorage) FixLoadedBrokenReferences(needToFix func(old Val
return false
}

var isMetaDataSlab bool

switch slab.(type) {
case *ArrayMetaDataSlab, *MapMetaDataSlab:
isMetaDataSlab = true
}
case *ArrayMetaDataSlab, *MapMetaDataSlab: // metadata slabs
var foundBrokenRef bool

var foundBrokenRef bool
for _, childStorable := range slab.ChildStorables() {
for _, childStorable := range slab.ChildStorables() {

storageIDStorable, ok := childStorable.(StorageIDStorable)
if !ok {
continue
}
if slabIDStorable, ok := childStorable.(StorageIDStorable); ok {

childID := StorageID(storageIDStorable)
childID := StorageID(slabIDStorable)

// Track parent-child relationship of root slabs and non-root slabs.
if isMetaDataSlab {
parentOf[childID] = id
}
// Track parent-child relationship of root slabs and non-root slabs.
parentOf[childID] = id

if s.existIfLoaded(childID) {
continue
if !s.existIfLoaded(childID) {
foundBrokenRef = true
}

// Continue with remaining child storables to track parent-child relationship.
}
}

foundBrokenRef = true
return foundBrokenRef

default: // data slabs
childStorables := slab.ChildStorables()

for len(childStorables) > 0 {

var nextChildStorables []Storable

for _, childStorable := range childStorables {

if slabIDStorable, ok := childStorable.(StorageIDStorable); ok {

if !isMetaDataSlab {
return true
if !s.existIfLoaded(StorageID(slabIDStorable)) {
return true
}

continue
}

// Append child storables of this childStorable to
// handle nested StorageIDStorable, such as Cadence SomeValue.
nextChildStorables = append(
nextChildStorables,
childStorable.ChildStorables()...,
)
}

childStorables = nextChildStorables
}
}

return foundBrokenRef
return false
}
}

var brokenStorageIDs []StorageID
Expand Down Expand Up @@ -1273,6 +1293,11 @@ func (s *PersistentSlabStorage) getAllChildReferences(slab Slab) (

storageIDStorable, ok := childStorable.(StorageIDStorable)
if !ok {
nextChildStorables = append(
nextChildStorables,
childStorable.ChildStorables()...,
)

continue
}

Expand Down
Loading

0 comments on commit 27b51f7

Please sign in to comment.