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

Update to Cadence v1.3.0 #6779

Merged
merged 7 commits into from
Jan 21, 2025
Merged
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
27 changes: 24 additions & 3 deletions cmd/util/cmd/check-storage/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package check_storage
import (
"context"

"github.com/onflow/cadence/interpreter"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -322,17 +323,37 @@ func checkAccountStorageHealth(accountRegisters *registers.AccountRegisters, nWo
// Check atree storage health

ledger := &registers.ReadOnlyLedger{Registers: accountRegisters}
storage := runtime.NewStorage(ledger, nil)
storage := runtime.NewStorage(ledger, nil, runtime.StorageConfig{})

inter, err := interpreter.NewInterpreter(
nil,
nil,
&interpreter.Config{
Storage: storage,
},
)
if err != nil {
issues = append(
issues,
accountStorageIssue{
Address: address.Hex(),
Kind: storageErrorKindString[otherErrorKind],
Msg: err.Error(),
},
)
return issues
}

err = util.CheckStorageHealth(address, storage, accountRegisters, util.StorageMapDomains, nWorkers)
err = util.CheckStorageHealth(inter, address, storage, accountRegisters, common.AllStorageDomains, nWorkers)
if err != nil {
issues = append(
issues,
accountStorageIssue{
Address: address.Hex(),
Kind: storageErrorKindString[cadenceAtreeStorageErrorKind],
Msg: err.Error(),
})
},
)
}

// TODO: check health of non-atree registers
Expand Down
29 changes: 24 additions & 5 deletions cmd/util/cmd/check-storage/evm_account_storage_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"slices"

"github.com/onflow/cadence/interpreter"
"golang.org/x/exp/maps"

"github.com/onflow/atree"

"github.com/onflow/cadence/common"
"github.com/onflow/cadence/runtime"

"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/registers"
"github.com/onflow/flow-go/fvm/evm/emulator/state"
"github.com/onflow/flow-go/model/flow"
Expand Down Expand Up @@ -70,16 +70,35 @@ func checkCadenceAtreeRegistersInEVMAccount(
) []accountStorageIssue {
var issues []accountStorageIssue

storage := runtime.NewStorage(ledger, nil)
storage := runtime.NewStorage(ledger, nil, runtime.StorageConfig{})

inter, err := interpreter.NewInterpreter(
nil,
nil,
&interpreter.Config{
Storage: storage,
},
)
if err != nil {
issues = append(
issues,
accountStorageIssue{
Address: address.Hex(),
Kind: storageErrorKindString[otherErrorKind],
Msg: fmt.Sprintf("failed to create interpreter for cadence registers: %s", err),
},
)
return issues
}

// Load Cadence domains storage map, so atree slab iterator can traverse connected slabs from loaded root slab.
// NOTE: don't preload all atree slabs in evm account because evm-atree registers require evm-atree decoder.

for _, domain := range util.StorageMapDomains {
_ = storage.GetStorageMap(address, domain, false)
for _, domain := range common.AllStorageDomains {
_ = storage.GetDomainStorageMap(inter, address, domain, false)
}

err := storage.CheckHealth()
err = storage.CheckHealth()
if err != nil {
issues = append(
issues,
Expand Down
15 changes: 10 additions & 5 deletions cmd/util/cmd/check-storage/evm_account_storage_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func createEVMStorage(t *testing.T, ledger atree.Ledger, address common.Address)
}

func createCadenceStorage(t *testing.T, ledger atree.Ledger, address common.Address) {
storage := runtime.NewStorage(ledger, nil)

storage := runtime.NewStorage(ledger, nil, runtime.StorageConfig{})

inter, err := interpreter.NewInterpreter(
nil,
Expand All @@ -123,13 +124,17 @@ func createCadenceStorage(t *testing.T, ledger atree.Ledger, address common.Addr
require.NoError(t, err)

// Create storage and public domains
for _, domain := range []string{"storage", "public"} {
storageDomain := storage.GetStorageMap(address, domain, true)
for _, domain := range []common.StorageDomain{
common.StorageDomainPathStorage,
common.StorageDomainPathPublic,
} {
storageDomain := storage.GetDomainStorageMap(inter, address, domain, true)

// Create large domain map so there are more than one atree registers under the hood.
for i := 0; i < 100; i++ {
key := interpreter.StringStorageMapKey(domain + "_key_" + strconv.Itoa(i))
value := interpreter.NewUnmeteredStringValue(domain + "_value_" + strconv.Itoa(i))
domainStr := domain.Identifier()
key := interpreter.StringStorageMapKey(domainStr + "_key_" + strconv.Itoa(i))
value := interpreter.NewUnmeteredStringValue(domainStr + "_value_" + strconv.Itoa(i))
storageDomain.SetValue(inter, key, value)
}
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/util/cmd/checkpoint-collect-stats/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"github.com/montanaflynn/stats"
"github.com/onflow/cadence/common"
"github.com/pkg/profile"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -460,7 +461,7 @@ func getTypeStats(t string, values []float64) RegisterStatsByTypes {
}

func getStats(valueSizesByType sizesByType) []RegisterStatsByTypes {
domainStats := make([]RegisterStatsByTypes, 0, len(util.StorageMapDomains))
domainStats := make([]RegisterStatsByTypes, 0, len(common.AllStorageDomains))
var allDomainSizes []float64

statsByTypes := make([]RegisterStatsByTypes, 0, len(valueSizesByType))
Expand Down Expand Up @@ -514,7 +515,7 @@ func getType(key ledger.Key) string {
return "atree slab"
}

isDomain := slices.Contains(util.StorageMapDomains, kstr)
_, isDomain := common.AllStorageDomainsByIdentifier[kstr]
if isDomain {
return domainTypePrefix + kstr
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/cmd/diff-states/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func diffAccount(
).DiffStates(
accountRegisters1,
accountRegisters2,
util.StorageMapDomains,
common.AllStorageDomains,
)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/util/cmd/generate-authorization-fixes/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
"github.com/rs/zerolog/log"
"github.com/schollz/progressbar/v3"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -334,9 +333,10 @@ func (g *AuthorizationFixGenerator) generateFixesForAccount(address common.Addre
log.Fatal().Err(err)
}

capabilityControllerStorage := mr.Storage.GetStorageMap(
capabilityControllerStorage := mr.Storage.GetDomainStorageMap(
mr.Interpreter,
address,
stdlib.CapabilityControllerStorageDomain,
common.StorageDomainCapabilityController,
false,
)
if capabilityControllerStorage == nil {
Expand Down
Loading
Loading