Skip to content

Commit

Permalink
Fix SlabIterator to include nested storage ID
Browse files Browse the repository at this point in the history
SlabIterator is used by storage health check, which is used
for tests and for new migration features like filtering out
old unreferenced slabs, etc.

Currently, SlabIterator doesn't traverse deep enough to handle
nested storage ID inside another storable such as Cadence SomeValue.

This commit fixes this by handling nested storage ID in element
such as Cadence SomeValue.
  • Loading branch information
fxamacker committed Apr 26, 2024
1 parent f4568c0 commit ef6dd7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ func (s *PersistentSlabStorage) SlabIterator() (SlabIterator, error) {

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

Expand Down
25 changes: 24 additions & 1 deletion storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ func TestPersistentStorageSlabIterator(t *testing.T) {
id2 := StorageID{Address: address, Index: StorageIndex{0, 0, 0, 0, 0, 0, 0, 2}}
id3 := StorageID{Address: address, Index: StorageIndex{0, 0, 0, 0, 0, 0, 0, 3}}
id4 := StorageID{Address: address, Index: StorageIndex{0, 0, 0, 0, 0, 0, 0, 4}}
id5 := StorageID{Address: address, Index: StorageIndex{0, 0, 0, 0, 0, 0, 0, 5}}

data := map[StorageID][]byte{
// (metadata slab) headers: [{id:2 size:228 count:9} {id:3 size:270 count:11} ]
Expand Down Expand Up @@ -969,7 +970,7 @@ func TestPersistentStorageSlabIterator(t *testing.T) {
0xd8, 0xff, 0x50, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
},

// (data slab) next: 0, data: [0]
// (data slab) next: 0, data: [SomeValue(StorageID(...))]
id4: {
// extra data
// version
Expand All @@ -981,6 +982,28 @@ func TestPersistentStorageSlabIterator(t *testing.T) {
// type info
0x18, 0x2b,

// version
0x00,
// array data slab flag
0x80,
// CBOR encoded array head (fixed size 3 byte)
0x99, 0x00, 0x01,
// CBOR encoded array elements
0xd8, cborTagSomeValue, 0xd8, 0xff, 0x50, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
},

// (data slab) next: 0, data: [0]
id5: {
// extra data
// version
0x00,
// extra data flag
0x80,
// array of extra data
0x81,
// type info
0x18, 0x2b,

// version
0x00,
// array data slab flag
Expand Down

0 comments on commit ef6dd7e

Please sign in to comment.