Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove account storage format V1 #3814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 17 additions & 51 deletions interpreter/account_storagemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ func TestAccountStorageMapDomainExists(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

accountStorageMap := interpreter.NewAccountStorageMap(nil, storage, atree.Address(address))
Expand All @@ -75,9 +73,7 @@ func TestAccountStorageMapDomainExists(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -119,9 +115,7 @@ func TestAccountStorageMapGetDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -158,9 +152,7 @@ func TestAccountStorageMapGetDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -206,9 +198,7 @@ func TestAccountStorageMapCreateDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -259,9 +249,7 @@ func TestAccountStorageMapCreateDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -319,9 +307,7 @@ func TestAccountStorageMapSetAndUpdateDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -375,9 +361,7 @@ func TestAccountStorageMapSetAndUpdateDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -433,9 +417,7 @@ func TestAccountStorageMapRemoveDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -482,9 +464,7 @@ func TestAccountStorageMapRemoveDomain(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -537,9 +517,7 @@ func TestAccountStorageMapIterator(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -583,9 +561,7 @@ func TestAccountStorageMapIterator(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off AtreeStorageValidationEnabled and explicitly check atree storage health at the end of test.
Expand Down Expand Up @@ -650,9 +626,7 @@ func TestAccountStorageMapDomains(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

accountStorageMap := interpreter.NewAccountStorageMap(nil, storage, atree.Address(address))
Expand All @@ -674,9 +648,7 @@ func TestAccountStorageMapDomains(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off automatic AtreeStorageValidationEnabled and explicitly check atree storage health directly.
Expand Down Expand Up @@ -719,9 +691,7 @@ func TestAccountStorageMapLoadFromRootSlabID(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

inter := NewTestInterpreterWithStorage(t, storage)
Expand Down Expand Up @@ -755,9 +725,7 @@ func TestAccountStorageMapLoadFromRootSlabID(t *testing.T) {
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

// Turn off automatic AtreeStorageValidationEnabled and explicitly check atree storage health directly.
Expand Down Expand Up @@ -857,9 +825,7 @@ func checkAccountStorageMapDataWithRawData(
storage := runtime.NewStorage(
ledger,
nil,
runtime.StorageConfig{
StorageFormatV2Enabled: true,
},
runtime.StorageConfig{},
)

inter := NewTestInterpreterWithStorage(tb, storage)
Expand Down
39 changes: 27 additions & 12 deletions runtime/account_storage_v2.go → runtime/account_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/onflow/cadence/interpreter"
)

type AccountStorageV2 struct {
type AccountStorage struct {
ledger atree.Ledger
slabStorage atree.SlabStorage
memoryGauge common.MemoryGauge
Expand All @@ -41,19 +41,19 @@ type AccountStorageV2 struct {
newAccountStorageMapSlabIndices map[common.Address]atree.SlabIndex
}

func NewAccountStorageV2(
func NewAccountStorage(
ledger atree.Ledger,
slabStorage atree.SlabStorage,
memoryGauge common.MemoryGauge,
) *AccountStorageV2 {
return &AccountStorageV2{
) *AccountStorage {
return &AccountStorage{
ledger: ledger,
slabStorage: slabStorage,
memoryGauge: memoryGauge,
}
}

func (s *AccountStorageV2) GetDomainStorageMap(
func (s *AccountStorage) GetDomainStorageMap(
inter *interpreter.Interpreter,
address common.Address,
domain common.StorageDomain,
Expand All @@ -80,7 +80,7 @@ func (s *AccountStorageV2) GetDomainStorageMap(
}

// getAccountStorageMap returns AccountStorageMap if exists, or nil otherwise.
func (s *AccountStorageV2) getAccountStorageMap(
func (s *AccountStorage) getAccountStorageMap(
address common.Address,
) (
accountStorageMap *interpreter.AccountStorageMap,
Expand Down Expand Up @@ -118,7 +118,7 @@ func (s *AccountStorageV2) getAccountStorageMap(
return
}

func (s *AccountStorageV2) cacheAccountStorageMap(
func (s *AccountStorage) cacheAccountStorageMap(
address common.Address,
accountStorageMap *interpreter.AccountStorageMap,
) {
Expand All @@ -128,7 +128,7 @@ func (s *AccountStorageV2) cacheAccountStorageMap(
s.cachedAccountStorageMaps[address] = accountStorageMap
}

func (s *AccountStorageV2) storeNewAccountStorageMap(
func (s *AccountStorage) storeNewAccountStorageMap(
address common.Address,
) *interpreter.AccountStorageMap {

Expand All @@ -153,7 +153,7 @@ func (s *AccountStorageV2) storeNewAccountStorageMap(
return accountStorageMap
}

func (s *AccountStorageV2) SetNewAccountStorageMapSlabIndex(
func (s *AccountStorage) SetNewAccountStorageMapSlabIndex(
address common.Address,
slabIndex atree.SlabIndex,
) {
Expand All @@ -163,7 +163,7 @@ func (s *AccountStorageV2) SetNewAccountStorageMapSlabIndex(
s.newAccountStorageMapSlabIndices[address] = slabIndex
}

func (s *AccountStorageV2) commit() error {
func (s *AccountStorage) commit() error {
switch len(s.newAccountStorageMapSlabIndices) {
case 0:
// Nothing to commit.
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *AccountStorageV2) commit() error {
return nil
}

func (s *AccountStorageV2) writeAccountStorageSlabIndex(
func (s *AccountStorage) writeAccountStorageSlabIndex(
address common.Address,
slabIndex atree.SlabIndex,
) error {
Expand Down Expand Up @@ -303,7 +303,22 @@ func hasAccountStorageMap(
return registerExists, nil
}

func (s *AccountStorageV2) cachedRootSlabIDs() []atree.SlabID {
// hasDomainRegister returns true if given account has given domain register.
// NOTE: account storage format v1 has domain registers.
func hasDomainRegister(ledger atree.Ledger, address common.Address, domain common.StorageDomain) (bool, error) {
_, domainExists, err := readSlabIndexFromRegister(
ledger,
address,
[]byte(domain.Identifier()),
)
if err != nil {
return false, err
}

return domainExists, nil
}

func (s *AccountStorage) cachedRootSlabIDs() []atree.SlabID {

var slabIDs []atree.SlabID

Expand Down
Loading
Loading