Skip to content

Commit

Permalink
Merge pull request #399 from onflow/fxamacker/fix-get-child-reference…
Browse files Browse the repository at this point in the history
…s-to-handle-storage-id-in-element-in-stable-cadence

Fix migration filter for old unreferenced slabs (non-inlining feature branch)
  • Loading branch information
fxamacker authored Apr 29, 2024
2 parents a64bde8 + 27b51f7 commit cb486ce
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 cb486ce

Please sign in to comment.