Skip to content

Commit

Permalink
Extract new function NewPersistentSlabStorage()
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Nov 25, 2024
1 parent 7772eb0 commit ba76c11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
16 changes: 12 additions & 4 deletions runtime/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ type Storage struct {
var _ atree.SlabStorage = &Storage{}
var _ interpreter.Storage = &Storage{}

func NewStorage(
func NewPersistentSlabStorage(
ledger atree.Ledger,
memoryGauge common.MemoryGauge,
config StorageConfig,
) *Storage {
) *atree.PersistentSlabStorage {
decodeStorable := func(
decoder *cbor.StreamDecoder,
slabID atree.SlabID,
Expand All @@ -95,13 +94,22 @@ func NewStorage(
}

ledgerStorage := atree.NewLedgerBaseStorage(ledger)
persistentSlabStorage := atree.NewPersistentSlabStorage(

return atree.NewPersistentSlabStorage(
ledgerStorage,
interpreter.CBOREncMode,
interpreter.CBORDecMode,
decodeStorable,
decodeTypeInfo,
)
}

func NewStorage(
ledger atree.Ledger,
memoryGauge common.MemoryGauge,
config StorageConfig,
) *Storage {
persistentSlabStorage := NewPersistentSlabStorage(ledger, memoryGauge)

accountStorageV1 := NewAccountStorageV1(
ledger,
Expand Down
37 changes: 2 additions & 35 deletions runtime/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"strings"
"testing"

"github.com/fxamacker/cbor/v2"
"github.com/onflow/atree"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -8363,7 +8362,7 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
return func() (storedValues map[string][]byte, StorageIndices map[string]uint64) {
ledger := NewTestLedger(nil, nil)

persistentSlabStorage := newSlabStorage(ledger)
persistentSlabStorage := NewPersistentSlabStorage(ledger, nil)

orderedMap, err := atree.NewMap(
persistentSlabStorage,
Expand Down Expand Up @@ -8761,7 +8760,7 @@ func TestGetDomainStorageMapRegisterReadsForV2Account(t *testing.T) {
return func() (storedValues map[string][]byte, StorageIndices map[string]uint64) {
ledger := NewTestLedger(nil, nil)

persistentSlabStorage := newSlabStorage(ledger)
persistentSlabStorage := NewPersistentSlabStorage(ledger, nil)

accountOrderedMap, err := atree.NewMap(
persistentSlabStorage,
Expand Down Expand Up @@ -9144,38 +9143,6 @@ func checkAccountStorageMapData(
require.Contains(tb, rootSlabIDs, accountSlabID)
}

func newSlabStorage(ledger atree.Ledger) *atree.PersistentSlabStorage {
decodeStorable := func(
decoder *cbor.StreamDecoder,
slabID atree.SlabID,
inlinedExtraData []atree.ExtraData,
) (
atree.Storable,
error,
) {
return interpreter.DecodeStorable(
decoder,
slabID,
inlinedExtraData,
nil,
)
}

decodeTypeInfo := func(decoder *cbor.StreamDecoder) (atree.TypeInfo, error) {
return interpreter.DecodeTypeInfo(decoder, nil)
}

ledgerStorage := atree.NewLedgerBaseStorage(ledger)

return atree.NewPersistentSlabStorage(
ledgerStorage,
interpreter.CBOREncMode,
interpreter.CBORDecMode,
decodeStorable,
decodeTypeInfo,
)
}

func concatRegisterAddressAndKey(
address common.Address,
key []byte,
Expand Down

0 comments on commit ba76c11

Please sign in to comment.