Skip to content

Commit

Permalink
Merge branch 'auto-update-onflow-cadence-v1.3.0' into bastian/account…
Browse files Browse the repository at this point in the history
…-storage-map-migration
  • Loading branch information
turbolent committed Dec 4, 2024
2 parents 0a393ef + a037ca3 commit 2b1ecac
Show file tree
Hide file tree
Showing 83 changed files with 3,362 additions and 796 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ generate-mocks: install-mock-generators
mockery --name 'API' --dir="./engine/protocol" --case=underscore --output="./engine/protocol/mock" --outpkg="mock"
mockery --name '.*' --dir="./engine/access/state_stream" --case=underscore --output="./engine/access/state_stream/mock" --outpkg="mock"
mockery --name 'BlockTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'DataProvider' --dir="./engine/access/rest/websockets/data_provider" --case=underscore --output="./engine/access/rest/websockets/data_provider/mock" --outpkg="mock"
mockery --name 'DataProvider' --dir="./engine/access/rest/websockets/data_providers" --case=underscore --output="./engine/access/rest/websockets/data_providers/mock" --outpkg="mock"
mockery --name 'DataProviderFactory' --dir="./engine/access/rest/websockets/data_providers" --case=underscore --output="./engine/access/rest/websockets/data_providers/mock" --outpkg="mock"
mockery --name 'ExecutionDataTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'ConnectionFactory' --dir="./engine/access/rpc/connection" --case=underscore --output="./engine/access/rpc/connection/mock" --outpkg="mock"
mockery --name 'Communicator' --dir="./engine/access/rpc/backend" --case=underscore --output="./engine/access/rpc/backend/mock" --outpkg="mock"
Expand Down
20 changes: 10 additions & 10 deletions access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ func (h *Handler) SubscribeBlocksFromStartBlockID(request *access.SubscribeBlock
}

sub := h.api.SubscribeBlocksFromStartBlockID(stream.Context(), startBlockID, blockStatus)
return subscription.HandleSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
return subscription.HandleRPCSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
}

// SubscribeBlocksFromStartHeight handles subscription requests for blocks started from block height.
Expand All @@ -1093,7 +1093,7 @@ func (h *Handler) SubscribeBlocksFromStartHeight(request *access.SubscribeBlocks
}

sub := h.api.SubscribeBlocksFromStartHeight(stream.Context(), request.GetStartBlockHeight(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
return subscription.HandleRPCSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
}

// SubscribeBlocksFromLatest handles subscription requests for blocks started from latest sealed block.
Expand All @@ -1120,7 +1120,7 @@ func (h *Handler) SubscribeBlocksFromLatest(request *access.SubscribeBlocksFromL
}

sub := h.api.SubscribeBlocksFromLatest(stream.Context(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
return subscription.HandleRPCSubscription(sub, h.handleBlocksResponse(stream.Send, request.GetFullBlockResponse(), blockStatus))
}

// handleBlocksResponse handles the subscription to block updates and sends
Expand Down Expand Up @@ -1179,7 +1179,7 @@ func (h *Handler) SubscribeBlockHeadersFromStartBlockID(request *access.Subscrib
}

sub := h.api.SubscribeBlockHeadersFromStartBlockID(stream.Context(), startBlockID, blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
}

// SubscribeBlockHeadersFromStartHeight handles subscription requests for block headers started from block height.
Expand All @@ -1206,7 +1206,7 @@ func (h *Handler) SubscribeBlockHeadersFromStartHeight(request *access.Subscribe
}

sub := h.api.SubscribeBlockHeadersFromStartHeight(stream.Context(), request.GetStartBlockHeight(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
}

// SubscribeBlockHeadersFromLatest handles subscription requests for block headers started from latest sealed block.
Expand All @@ -1233,7 +1233,7 @@ func (h *Handler) SubscribeBlockHeadersFromLatest(request *access.SubscribeBlock
}

sub := h.api.SubscribeBlockHeadersFromLatest(stream.Context(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockHeadersResponse(stream.Send))
}

// handleBlockHeadersResponse handles the subscription to block updates and sends
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func (h *Handler) SubscribeBlockDigestsFromStartBlockID(request *access.Subscrib
}

sub := h.api.SubscribeBlockDigestsFromStartBlockID(stream.Context(), startBlockID, blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
}

// SubscribeBlockDigestsFromStartHeight handles subscription requests for lightweight blocks started from block height.
Expand All @@ -1320,7 +1320,7 @@ func (h *Handler) SubscribeBlockDigestsFromStartHeight(request *access.Subscribe
}

sub := h.api.SubscribeBlockDigestsFromStartHeight(stream.Context(), request.GetStartBlockHeight(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
}

// SubscribeBlockDigestsFromLatest handles subscription requests for lightweight block started from latest sealed block.
Expand All @@ -1347,7 +1347,7 @@ func (h *Handler) SubscribeBlockDigestsFromLatest(request *access.SubscribeBlock
}

sub := h.api.SubscribeBlockDigestsFromLatest(stream.Context(), blockStatus)
return subscription.HandleSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
return subscription.HandleRPCSubscription(sub, h.handleBlockDigestsResponse(stream.Send))
}

// handleBlockDigestsResponse handles the subscription to block updates and sends
Expand Down Expand Up @@ -1433,7 +1433,7 @@ func (h *Handler) SendAndSubscribeTransactionStatuses(
sub := h.api.SubscribeTransactionStatuses(ctx, &tx, request.GetEventEncodingVersion())

messageIndex := counters.NewMonotonousCounter(0)
return subscription.HandleSubscription(sub, func(txResults []*TransactionResult) error {
return subscription.HandleRPCSubscription(sub, func(txResults []*TransactionResult) error {
for i := range txResults {
index := messageIndex.Value()
if ok := messageIndex.Set(index + 1); !ok {
Expand Down
32 changes: 4 additions & 28 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import (
"github.com/onflow/flow-go/cmd/build"
"github.com/onflow/flow-go/config"
"github.com/onflow/flow-go/consensus/hotstuff/persister"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/initialize"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/filter"
"github.com/onflow/flow-go/module"
Expand Down Expand Up @@ -1522,32 +1521,9 @@ func (fnb *FlowNodeBuilder) initLocal() error {
}

func (fnb *FlowNodeBuilder) initFvmOptions() {
blockFinder := environment.NewBlockFinder(fnb.Storage.Headers)
vmOpts := []fvm.Option{
fvm.WithChain(fnb.RootChainID.Chain()),
fvm.WithBlocks(blockFinder),
fvm.WithAccountStorageLimit(true),
}
switch fnb.RootChainID {
case flow.Testnet,
flow.Sandboxnet,
flow.Previewnet,
flow.Mainnet:
vmOpts = append(vmOpts,
fvm.WithTransactionFeesEnabled(true),
)
}
switch fnb.RootChainID {
case flow.Testnet,
flow.Sandboxnet,
flow.Previewnet,
flow.Localnet,
flow.Benchnet:
vmOpts = append(vmOpts,
fvm.WithContractDeploymentRestricted(false),
)
}
fnb.FvmOptions = vmOpts
fnb.FvmOptions = initialize.InitFvmOptions(
fnb.RootChainID, fnb.Storage.Headers,
)
}

// handleModules initializes the given module.
Expand Down
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
4 changes: 4 additions & 0 deletions cmd/util/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
"github.com/onflow/flow-go/cmd/util/cmd/snapshot"
system_addresses "github.com/onflow/flow-go/cmd/util/cmd/system-addresses"
truncate_database "github.com/onflow/flow-go/cmd/util/cmd/truncate-database"
verify_evm_offchain_replay "github.com/onflow/flow-go/cmd/util/cmd/verify-evm-offchain-replay"
verify_execution_result "github.com/onflow/flow-go/cmd/util/cmd/verify_execution_result"
"github.com/onflow/flow-go/cmd/util/cmd/version"
"github.com/onflow/flow-go/module/profiler"
)
Expand Down Expand Up @@ -126,6 +128,8 @@ func addCommands() {
rootCmd.AddCommand(debug_script.Cmd)
rootCmd.AddCommand(generate_authorization_fixes.Cmd)
rootCmd.AddCommand(evm_state_exporter.Cmd)
rootCmd.AddCommand(verify_execution_result.Cmd)
rootCmd.AddCommand(verify_evm_offchain_replay.Cmd)
}

func initConfig() {
Expand Down
Loading

0 comments on commit 2b1ecac

Please sign in to comment.