Skip to content

Commit

Permalink
Merge pull request #398 from onflow/fxamacker/traverse-deeper-in-slab…
Browse files Browse the repository at this point in the history
…-iterator

Fix SlabIterator to include nested storage ID (non-inlining feature branch)
  • Loading branch information
fxamacker authored Apr 29, 2024
2 parents f4568c0 + ef6dd7e commit a64bde8
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 a64bde8

Please sign in to comment.