diff --git a/cmd/bootstrap/utils/key_generation.go b/cmd/bootstrap/utils/key_generation.go index fd4c8c53444..6cb662be21c 100644 --- a/cmd/bootstrap/utils/key_generation.go +++ b/cmd/bootstrap/utils/key_generation.go @@ -13,6 +13,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/model/bootstrap" model "github.com/onflow/flow-go/model/bootstrap" diff --git a/cmd/collection/main.go b/cmd/collection/main.go index c3d1496918a..1a241ba703b 100644 --- a/cmd/collection/main.go +++ b/cmd/collection/main.go @@ -9,6 +9,7 @@ import ( client "github.com/onflow/flow-go-sdk/access/grpc" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/admin/commands" collectionCommands "github.com/onflow/flow-go/admin/commands/collection" storageCommands "github.com/onflow/flow-go/admin/commands/storage" diff --git a/cmd/consensus/main.go b/cmd/consensus/main.go index 874385b2b3f..616e7657d10 100644 --- a/cmd/consensus/main.go +++ b/cmd/consensus/main.go @@ -12,6 +12,7 @@ import ( client "github.com/onflow/flow-go-sdk/access/grpc" "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/cmd" "github.com/onflow/flow-go/cmd/util/cmd/common" "github.com/onflow/flow-go/consensus" diff --git a/cmd/observer/node_builder/observer_builder.go b/cmd/observer/node_builder/observer_builder.go index f35da6858f1..d04d5b5ad20 100644 --- a/cmd/observer/node_builder/observer_builder.go +++ b/cmd/observer/node_builder/observer_builder.go @@ -19,10 +19,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" badgerds "github.com/ipfs/go-ds-badger2" - dht "github.com/libp2p/go-libp2p-kad-dht" - "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/routing" "github.com/onflow/crypto" "github.com/rs/zerolog" "github.com/spf13/pflag" @@ -93,17 +90,12 @@ import ( "github.com/onflow/flow-go/network/converter" "github.com/onflow/flow-go/network/p2p" "github.com/onflow/flow-go/network/p2p/blob" - p2pbuilder "github.com/onflow/flow-go/network/p2p/builder" - p2pbuilderconfig "github.com/onflow/flow-go/network/p2p/builder/config" "github.com/onflow/flow-go/network/p2p/cache" "github.com/onflow/flow-go/network/p2p/conduit" - p2pdht "github.com/onflow/flow-go/network/p2p/dht" "github.com/onflow/flow-go/network/p2p/keyutils" p2plogging "github.com/onflow/flow-go/network/p2p/logging" - networkingsubscription "github.com/onflow/flow-go/network/p2p/subscription" "github.com/onflow/flow-go/network/p2p/translator" "github.com/onflow/flow-go/network/p2p/unicast/protocols" - "github.com/onflow/flow-go/network/p2p/utils" "github.com/onflow/flow-go/network/slashing" "github.com/onflow/flow-go/network/underlay" "github.com/onflow/flow-go/network/validator" @@ -138,8 +130,6 @@ import ( // For a node running as a standalone process, the config fields will be populated from the command line params, // while for a node running as a library, the config fields are expected to be initialized by the caller. type ObserverServiceConfig struct { - bootstrapNodeAddresses []string - bootstrapNodePublicKeys []string observerNetworkingKeyPath string bootstrapIdentities flow.IdentitySkeletonList // the identity list of bootstrap peers the node uses to discover other nodes apiRatelimits map[string]int @@ -223,8 +213,6 @@ func DefaultObserverServiceConfig() *ObserverServiceConfig { rpcMetricsEnabled: false, apiRatelimits: nil, apiBurstlimits: nil, - bootstrapNodeAddresses: []string{}, - bootstrapNodePublicKeys: []string{}, observerNetworkingKeyPath: cmd.NotSet, apiTimeout: 3 * time.Second, upstreamNodeAddresses: []string{}, @@ -334,7 +322,7 @@ func (builder *ObserverServiceBuilder) deriveBootstrapPeerIdentities() error { return nil } - ids, err := cmd.BootstrapIdentities(builder.bootstrapNodeAddresses, builder.bootstrapNodePublicKeys) + ids, err := builder.DeriveBootstrapPeerIdentities() if err != nil { return fmt.Errorf("failed to derive bootstrap peer identities: %w", err) } @@ -655,14 +643,6 @@ func (builder *ObserverServiceBuilder) extraFlags() { "observer-networking-key-path", defaultConfig.observerNetworkingKeyPath, "path to the networking key for observer") - flags.StringSliceVar(&builder.bootstrapNodeAddresses, - "bootstrap-node-addresses", - defaultConfig.bootstrapNodeAddresses, - "the network addresses of the bootstrap access node if this is an observer e.g. access-001.mainnet.flow.org:9653,access-002.mainnet.flow.org:9653") - flags.StringSliceVar(&builder.bootstrapNodePublicKeys, - "bootstrap-node-public-keys", - defaultConfig.bootstrapNodePublicKeys, - "the networking public key of the bootstrap access node if this is an observer (in the same order as the bootstrap node addresses) e.g. \"d57a5e9c5.....\",\"44ded42d....\"") flags.DurationVar(&builder.apiTimeout, "upstream-api-timeout", defaultConfig.apiTimeout, "tcp timeout for Flow API gRPC sockets to upstrem nodes") flags.StringSliceVar(&builder.upstreamNodeAddresses, "upstream-node-addresses", @@ -1002,10 +982,10 @@ func (builder *ObserverServiceBuilder) validateParams() error { if len(builder.bootstrapIdentities) > 0 { return nil } - if len(builder.bootstrapNodeAddresses) == 0 { + if len(builder.BootstrapNodeAddresses) == 0 { return errors.New("no bootstrap node address provided") } - if len(builder.bootstrapNodeAddresses) != len(builder.bootstrapNodePublicKeys) { + if len(builder.BootstrapNodeAddresses) != len(builder.BootstrapNodePublicKeys) { return errors.New("number of bootstrap node addresses and public keys should match") } if len(builder.upstreamNodePublicKeys) > 0 && len(builder.upstreamNodeAddresses) != len(builder.upstreamNodePublicKeys) { @@ -1014,77 +994,6 @@ func (builder *ObserverServiceBuilder) validateParams() error { return nil } -// initPublicLibp2pNode creates a libp2p node for the observer service in the public (unstaked) network. -// The factory function is later passed into the initMiddleware function to eventually instantiate the p2p.LibP2PNode instance -// The LibP2P host is created with the following options: -// * DHT as client and seeded with the given bootstrap peers -// * The specified bind address as the listen address -// * The passed in private key as the libp2p key -// * No connection gater -// * No connection manager -// * No peer manager -// * Default libp2p pubsub options. -// Args: -// - networkKey: the private key to use for the libp2p node -// Returns: -// - p2p.LibP2PNode: the libp2p node -// - error: if any error occurs. Any error returned is considered irrecoverable. -func (builder *ObserverServiceBuilder) initPublicLibp2pNode(networkKey crypto.PrivateKey) (p2p.LibP2PNode, error) { - var pis []peer.AddrInfo - - for _, b := range builder.bootstrapIdentities { - pi, err := utils.PeerAddressInfo(*b) - if err != nil { - return nil, fmt.Errorf("could not extract peer address info from bootstrap identity %v: %w", b, err) - } - - pis = append(pis, pi) - } - - node, err := p2pbuilder.NewNodeBuilder( - builder.Logger, - &builder.FlowConfig.NetworkConfig.GossipSub, - &p2pbuilderconfig.MetricsConfig{ - HeroCacheFactory: builder.HeroCacheMetricsFactory(), - Metrics: builder.Metrics.Network, - }, - network.PublicNetwork, - builder.BaseConfig.BindAddr, - networkKey, - builder.SporkID, - builder.IdentityProvider, - &builder.FlowConfig.NetworkConfig.ResourceManager, - p2pbuilderconfig.PeerManagerDisableConfig(), // disable peer manager for observer node. - &p2p.DisallowListCacheConfig{ - MaxSize: builder.FlowConfig.NetworkConfig.DisallowListNotificationCacheSize, - Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork), - }, - &p2pbuilderconfig.UnicastConfig{ - Unicast: builder.FlowConfig.NetworkConfig.Unicast, - }). - SetSubscriptionFilter( - networkingsubscription.NewRoleBasedFilter( - networkingsubscription.UnstakedRole, builder.IdentityProvider, - ), - ). - SetRoutingSystem(func(ctx context.Context, h host.Host) (routing.Routing, error) { - return p2pdht.NewDHT(ctx, h, protocols.FlowPublicDHTProtocolID(builder.SporkID), - builder.Logger, - builder.Metrics.Network, - p2pdht.AsClient(), - dht.BootstrapPeers(pis...), - ) - }). - Build() - if err != nil { - return nil, fmt.Errorf("could not initialize libp2p node for observer: %w", err) - } - - builder.LibP2PNode = node - - return builder.LibP2PNode, nil -} - // initObserverLocal initializes the observer's ID, network key and network address // Currently, it reads a node-info.priv.json like any other node. // TODO: read the node ID from the special bootstrap files @@ -1673,11 +1582,13 @@ func (builder *ObserverServiceBuilder) enqueuePublicNetworkInit() { builder. Component("public libp2p node", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) { var err error - publicLibp2pNode, err = builder.initPublicLibp2pNode(node.NetworkKey) + publicLibp2pNode, err = builder.BuildPublicLibp2pNode(builder.BaseConfig.BindAddr, builder.bootstrapIdentities) if err != nil { - return nil, fmt.Errorf("could not create public libp2p node: %w", err) + return nil, fmt.Errorf("could not build public libp2p node: %w", err) } + builder.LibP2PNode = publicLibp2pNode + return publicLibp2pNode, nil }). Component("public network", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) { diff --git a/cmd/scaffold.go b/cmd/scaffold.go index 5db4e75c395..a3a95cfff15 100644 --- a/cmd/scaffold.go +++ b/cmd/scaffold.go @@ -138,8 +138,8 @@ type FlowNodeBuilder struct { adminCommandBootstrapper *admin.CommandRunnerBootstrapper adminCommands map[string]func(config *NodeConfig) commands.AdminCommand componentBuilder component.ComponentManagerBuilder - bootstrapNodeAddresses []string - bootstrapNodePublicKeys []string + BootstrapNodeAddresses []string + BootstrapNodePublicKeys []string } var _ NodeBuilder = (*FlowNodeBuilder)(nil) @@ -254,13 +254,13 @@ func (fnb *FlowNodeBuilder) BaseFlags() { // observer mode allows a unstaked execution node to fetch blocks from a public staked access node, and being able to execute blocks fnb.flags.BoolVar(&fnb.BaseConfig.ObserverMode, "observer-mode", defaultConfig.ObserverMode, "whether the node is running in observer mode") - fnb.flags.StringSliceVar(&fnb.bootstrapNodePublicKeys, + fnb.flags.StringSliceVar(&fnb.BootstrapNodePublicKeys, "observer-mode-bootstrap-node-public-keys", - nil, + []string{}, "the networking public key of the bootstrap access node if this is an observer (in the same order as the bootstrap node addresses) e.g. \"d57a5e9c5.....\",\"44ded42d....\"") - fnb.flags.StringSliceVar(&fnb.bootstrapNodeAddresses, + fnb.flags.StringSliceVar(&fnb.BootstrapNodeAddresses, "observer-mode-bootstrap-node-addresses", - nil, + []string{}, "the network addresses of the bootstrap access node if this is an observer e.g. access-001.mainnet.flow.org:9653,access-002.mainnet.flow.org:9653") } @@ -413,8 +413,13 @@ func (fnb *FlowNodeBuilder) EnqueueNetworkInit() { } if fnb.ObserverMode { - // observer mode only init pulbic libp2p node - publicLibp2pNode, err := fnb.BuildPublicLibp2pNode(myAddr) + // observer mode only init public libp2p node + ids, err := fnb.DeriveBootstrapPeerIdentities() + if err != nil { + return nil, fmt.Errorf("failed to derive bootstrap peer identities: %w", err) + } + + publicLibp2pNode, err := fnb.BuildPublicLibp2pNode(myAddr, ids) if err != nil { return nil, fmt.Errorf("could not build public libp2p node: %w", err) } @@ -500,7 +505,18 @@ func (fnb *FlowNodeBuilder) HeroCacheMetricsFactory() metrics.HeroCacheMetricsFa return metrics.NewNoopHeroCacheMetricsFactory() } -// initPublicLibp2pNode creates a libp2p node for the observer service in the public (unstaked) network. +// DeriveBootstrapPeerIdentities derives the Flow Identity of the bootstrap peers from the parameters. +// These are the identities of the observers also acting as the DHT bootstrap server +func (fnb *FlowNodeBuilder) DeriveBootstrapPeerIdentities() (flow.IdentitySkeletonList, error) { + ids, err := BootstrapIdentities(fnb.BootstrapNodeAddresses, fnb.BootstrapNodePublicKeys) + if err != nil { + return nil, fmt.Errorf("failed to derive bootstrap peer identities: %w", err) + } + + return ids, nil +} + +// BuildPublicLibp2pNode creates a libp2p node for the observer service in the public (unstaked) network. // The factory function is later passed into the initMiddleware function to eventually instantiate the p2p.LibP2PNode instance // The LibP2P host is created with the following options: // * DHT as client and seeded with the given bootstrap peers @@ -515,24 +531,10 @@ func (fnb *FlowNodeBuilder) HeroCacheMetricsFactory() metrics.HeroCacheMetricsFa // Returns: // - p2p.LibP2PNode: the libp2p node // - error: if any error occurs. Any error returned is considered irrecoverable. -func (fnb *FlowNodeBuilder) BuildPublicLibp2pNode(address string) (p2p.LibP2PNode, error) { +func (fnb *FlowNodeBuilder) BuildPublicLibp2pNode(address string, bootstrapIdentities flow.IdentitySkeletonList) (p2p.LibP2PNode, error) { var pis []peer.AddrInfo - ids, err := BootstrapIdentities(fnb.bootstrapNodeAddresses, fnb.bootstrapNodePublicKeys) - if err != nil { - return nil, fmt.Errorf("could not create bootstrap identities: %w", err) - } - - for _, b := range ids { - pi, err := utils.PeerAddressInfo(*b) - if err != nil { - return nil, fmt.Errorf("could not extract peer address info from bootstrap identity %v: %w", b, err) - } - - pis = append(pis, pi) - } - - for _, b := range ids { + for _, b := range bootstrapIdentities { pi, err := utils.PeerAddressInfo(*b) if err != nil { return nil, fmt.Errorf("could not extract peer address info from bootstrap identity %v: %w", b, err) diff --git a/cmd/util/cmd/common/snapshot.go b/cmd/util/cmd/common/snapshot.go index 6e940237ea1..83b568b71b8 100644 --- a/cmd/util/cmd/common/snapshot.go +++ b/cmd/util/cmd/common/snapshot.go @@ -9,9 +9,10 @@ import ( "github.com/rs/zerolog" "github.com/sethvargo/go-retry" + "github.com/onflow/flow-go-sdk/access/grpc" + "github.com/onflow/flow-go/utils/logging" - "github.com/onflow/flow-go-sdk/access/grpc" "github.com/onflow/flow-go/model/flow" "github.com/onflow/flow-go/state/protocol" "github.com/onflow/flow-go/state/protocol/inmem" diff --git a/cmd/util/cmd/read-badger/cmd/find-block-by-commits/main.go b/cmd/util/cmd/read-badger/cmd/find-block-by-commits/main.go index 8eec5ddee0b..b1fb1cf3106 100644 --- a/cmd/util/cmd/read-badger/cmd/find-block-by-commits/main.go +++ b/cmd/util/cmd/read-badger/cmd/find-block-by-commits/main.go @@ -80,7 +80,7 @@ func FindBlockIDByCommits( func toStateCommitments(commitsStr string) ([]flow.StateCommitment, error) { commitSlice := strings.Split(commitsStr, ",") - commits := make([]flow.StateCommitment, len(commitSlice)) + commits := make([]flow.StateCommitment, 0, len(commitSlice)) for _, c := range commitSlice { commit, err := toStateCommitment(c) if err != nil { diff --git a/cmd/util/ledger/migrations/account_based_migration_test.go b/cmd/util/ledger/migrations/account_based_migration_test.go index bd2b59b6ee6..c06a6a7f090 100644 --- a/cmd/util/ledger/migrations/account_based_migration_test.go +++ b/cmd/util/ledger/migrations/account_based_migration_test.go @@ -3,7 +3,6 @@ package migrations import ( "context" "fmt" - "testing" "github.com/onflow/cadence/common" diff --git a/cmd/util/ledger/migrations/migrator_runtime.go b/cmd/util/ledger/migrations/migrator_runtime.go index ab051393bed..35e35b065d3 100644 --- a/cmd/util/ledger/migrations/migrator_runtime.go +++ b/cmd/util/ledger/migrations/migrator_runtime.go @@ -16,6 +16,7 @@ import ( "github.com/onflow/flow-go/fvm/evm" evmStdlib "github.com/onflow/flow-go/fvm/evm/stdlib" "github.com/onflow/flow-go/fvm/storage/state" + "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/model/flow" ) @@ -111,8 +112,11 @@ func (c InterpreterMigrationRuntimeConfig) NewRuntimeInterface( } } + sc := systemcontracts.SystemContractsForChain(chainID) + return util.NewMigrationRuntimeInterface( chainID, + common.Address(sc.Crypto.Address), getCodeFunc, getContractNames, getOrLoadProgram, diff --git a/cmd/util/ledger/util/migration_runtime_interface.go b/cmd/util/ledger/util/migration_runtime_interface.go index 1043fd03ce5..12142eb15b4 100644 --- a/cmd/util/ledger/util/migration_runtime_interface.go +++ b/cmd/util/ledger/util/migration_runtime_interface.go @@ -38,6 +38,7 @@ type GerOrLoadProgramListenerFunc func( type MigrationRuntimeInterface struct { runtime.EmptyRuntimeInterface chainID flow.ChainID + CryptoContractAddress common.Address GetContractCodeFunc GetContractCodeFunc GetContractNamesFunc GetContractNamesFunc GetOrLoadProgramFunc GetOrLoadProgramFunc @@ -48,6 +49,7 @@ var _ runtime.Interface = &MigrationRuntimeInterface{} func NewMigrationRuntimeInterface( chainID flow.ChainID, + cryptoContractAddress common.Address, getCodeFunc GetContractCodeFunc, getContractNamesFunc GetContractNamesFunc, getOrLoadProgramFunc GetOrLoadProgramFunc, @@ -55,6 +57,7 @@ func NewMigrationRuntimeInterface( ) *MigrationRuntimeInterface { return &MigrationRuntimeInterface{ chainID: chainID, + CryptoContractAddress: cryptoContractAddress, GetContractCodeFunc: getCodeFunc, GetContractNamesFunc: getContractNamesFunc, GetOrLoadProgramFunc: getOrLoadProgramFunc, @@ -67,65 +70,12 @@ func (m *MigrationRuntimeInterface) ResolveLocation( location runtime.Location, ) ([]runtime.ResolvedLocation, error) { - addressLocation, isAddress := location.(common.AddressLocation) - - // if the location is not an address location, e.g. an identifier location (`import Crypto`), - // then return a single resolved location which declares all identifiers. - if !isAddress { - return []runtime.ResolvedLocation{ - { - Location: location, - Identifiers: identifiers, - }, - }, nil - } - - // if the location is an address, - // and no specific identifiers where requested in the import statement, - // then fetch all identifiers at this address - if len(identifiers) == 0 { - address := flow.Address(addressLocation.Address) - - getContractNames := m.GetContractNamesFunc - if getContractNames == nil { - return nil, errors.New("GetContractNamesFunc missing") - } - - contractNames, err := getContractNames(address) - if err != nil { - return nil, fmt.Errorf("ResolveLocation failed: %w", err) - } - - // if there are no contractNames deployed, - // then return no resolved locations - if len(contractNames) == 0 { - return nil, nil - } - - identifiers = make([]runtime.Identifier, len(contractNames)) - - for i := range identifiers { - identifiers[i] = runtime.Identifier{ - Identifier: contractNames[i], - } - } - } - - // return one resolved location per identifier. - // each resolved location is an address contract location - resolvedLocations := make([]runtime.ResolvedLocation, len(identifiers)) - for i := range resolvedLocations { - identifier := identifiers[i] - resolvedLocations[i] = runtime.ResolvedLocation{ - Location: common.AddressLocation{ - Address: addressLocation.Address, - Name: identifier.Identifier, - }, - Identifiers: []runtime.Identifier{identifier}, - } - } - - return resolvedLocations, nil + return environment.ResolveLocation( + identifiers, + location, + m.GetContractNamesFunc, + m.CryptoContractAddress, + ) } func (m *MigrationRuntimeInterface) GetCode(location runtime.Location) ([]byte, error) { diff --git a/consensus/hotstuff/verification/common.go b/consensus/hotstuff/verification/common.go index 4febede7412..04c355f4390 100644 --- a/consensus/hotstuff/verification/common.go +++ b/consensus/hotstuff/verification/common.go @@ -1,6 +1,7 @@ package verification import ( + "encoding/binary" "fmt" "github.com/onflow/crypto" @@ -8,8 +9,6 @@ import ( "github.com/onflow/flow-go/consensus/hotstuff/model" "github.com/onflow/flow-go/model/flow" - - "encoding/binary" ) // MakeVoteMessage generates the message we have to sign in order to be able diff --git a/engine/access/ingestion/engine.go b/engine/access/ingestion/engine.go index 21b6d313ef2..0e4ac42367e 100644 --- a/engine/access/ingestion/engine.go +++ b/engine/access/ingestion/engine.go @@ -79,7 +79,7 @@ type Engine struct { executionReceiptsQueue engine.MessageStore // Job queue finalizedBlockConsumer *jobqueue.ComponentConsumer - // Notifiers for queue consumer + // Notifier for queue consumer finalizedBlockNotifier engine.Notifier // txResultErrorMessagesChan is used to fetch and store transaction result error messages for blocks @@ -201,12 +201,20 @@ func New( } // Add workers - e.ComponentManager = component.NewComponentManagerBuilder(). + builder := component.NewComponentManagerBuilder(). AddWorker(e.processBackground). AddWorker(e.processExecutionReceipts). - AddWorker(e.runFinalizedBlockConsumer). - AddWorker(e.processTransactionResultErrorMessagesByReceipts). - Build() + AddWorker(e.runFinalizedBlockConsumer) + + // If txErrorMessagesCore is provided, add a worker responsible for processing + // transaction result error messages by receipts. This worker listens for blocks + // containing execution receipts and processes any associated transaction result + // error messages. The worker is added only when error message processing is enabled. + if txErrorMessagesCore != nil { + builder.AddWorker(e.processTransactionResultErrorMessagesByReceipts) + } + + e.ComponentManager = builder.Build() // register engine with the execution receipt provider _, err = net.Register(channels.ReceiveReceipts, e) @@ -348,8 +356,13 @@ func (e *Engine) processAvailableExecutionReceipts(ctx context.Context) error { return err } - // notify, to fetch and store transaction result error messages for block - e.txResultErrorMessagesChan <- receipt.BlockID + // Notify to fetch and store transaction result error messages for the block. + // If txErrorMessagesCore is enabled, the receipt's BlockID is sent to trigger + // transaction error message processing. This step is skipped if error message + // storage is not enabled. + if e.txErrorMessagesCore != nil { + e.txResultErrorMessagesChan <- receipt.BlockID + } } } @@ -368,10 +381,6 @@ func (e *Engine) processTransactionResultErrorMessagesByReceipts(ctx irrecoverab case <-ctx.Done(): return case blockID := <-e.txResultErrorMessagesChan: - if e.txErrorMessagesCore == nil { - return - } - err := e.txErrorMessagesCore.HandleTransactionResultErrorMessages(ctx, blockID) if err != nil { // TODO: we should revisit error handling here. diff --git a/engine/access/ingestion/tx_error_messages/tx_error_messages_core.go b/engine/access/ingestion/tx_error_messages/tx_error_messages_core.go index ff556d1c4d1..f41a49ab409 100644 --- a/engine/access/ingestion/tx_error_messages/tx_error_messages_core.go +++ b/engine/access/ingestion/tx_error_messages/tx_error_messages_core.go @@ -34,7 +34,7 @@ func NewTxErrorMessagesCore( execNodeIdentitiesProvider *commonrpc.ExecutionNodeIdentitiesProvider, ) *TxErrorMessagesCore { return &TxErrorMessagesCore{ - log: log.With().Str("engine", "tx_error_messages_core").Logger(), + log: log.With().Str("module", "tx_error_messages_core").Logger(), backend: backend, transactionResultErrorMessages: transactionResultErrorMessages, execNodeIdentitiesProvider: execNodeIdentitiesProvider, diff --git a/engine/access/ingestion/tx_error_messages/tx_error_messages_core_test.go b/engine/access/ingestion/tx_error_messages/tx_error_messages_core_test.go index acb21c7e484..aa8a51b42f8 100644 --- a/engine/access/ingestion/tx_error_messages/tx_error_messages_core_test.go +++ b/engine/access/ingestion/tx_error_messages/tx_error_messages_core_test.go @@ -259,13 +259,7 @@ func (s *TxErrorMessagesCoreSuite) initCore() *TxErrorMessagesCore { s.log, backend, s.txErrorMessages, - commonrpc.NewExecutionNodeIdentitiesProvider( - s.log, - s.proto.state, - s.receipts, - flow.IdentifierList{}, - flow.IdentifierList{}, - ), + execNodeIdentitiesProvider, ) return core } diff --git a/engine/access/ingestion/tx_error_messages/tx_error_messages_engine.go b/engine/access/ingestion/tx_error_messages/tx_error_messages_engine.go index 0318b3d416c..cdd65bdc0b3 100644 --- a/engine/access/ingestion/tx_error_messages/tx_error_messages_engine.go +++ b/engine/access/ingestion/tx_error_messages/tx_error_messages_engine.go @@ -95,7 +95,7 @@ func New( // it reads the `txErrorMessagesProcessedHeight` and resume from `txErrorMessagesProcessedHeight + 1`. // If the database is empty, rootHeight will be used to init the last processed height. e.txErrorMessagesConsumer, err = jobqueue.NewComponentConsumer( - e.log.With().Str("module", "ingestion_tx_error_messages_consumer").Logger(), + e.log.With().Str("engine", "tx_error_messages").Logger(), e.txErrorMessagesNotifier.Channel(), txErrorMessagesProcessedHeight, sealedBlockReader, diff --git a/engine/access/rpc/backend/backend.go b/engine/access/rpc/backend/backend.go index cbb26bf4d08..d4666af9529 100644 --- a/engine/access/rpc/backend/backend.go +++ b/engine/access/rpc/backend/backend.go @@ -3,6 +3,7 @@ package backend import ( "context" "crypto/md5" //nolint:gosec + "errors" "fmt" "time" @@ -372,3 +373,44 @@ func (b *Backend) GetNetworkParameters(_ context.Context) access.NetworkParamete ChainID: b.chainID, } } + +// resolveHeightError processes errors returned during height-based queries. +// If the error is due to a block not being found, this function determines whether the queried +// height falls outside the node's accessible range and provides context-sensitive error messages +// based on spork and node root block heights. +// +// Parameters: +// - stateParams: Protocol parameters that contain spork root and node root block heights. +// - height: The queried block height. +// - genericErr: The initial error returned when the block is not found. +// +// Expected errors during normal operation: +// - storage.ErrNotFound - Indicates that the queried block does not exist in the local database. +func resolveHeightError( + stateParams protocol.Params, + height uint64, + genericErr error, +) error { + if !errors.Is(genericErr, storage.ErrNotFound) { + return genericErr + } + + sporkRootBlockHeight := stateParams.SporkRootBlockHeight() + nodeRootBlockHeader := stateParams.SealedRoot().Height + + if height < sporkRootBlockHeight { + return fmt.Errorf("block height %d is less than the spork root block height %d. Try to use a historic node: %w", + height, + sporkRootBlockHeight, + genericErr, + ) + } else if height < nodeRootBlockHeader { + return fmt.Errorf("block height %d is less than the node's root block height %d. Try to use a different Access node: %w", + height, + nodeRootBlockHeader, + genericErr, + ) + } else { + return genericErr + } +} diff --git a/engine/access/rpc/backend/backend_accounts.go b/engine/access/rpc/backend/backend_accounts.go index ca52455f7ba..609d1c063a8 100644 --- a/engine/access/rpc/backend/backend_accounts.go +++ b/engine/access/rpc/backend/backend_accounts.go @@ -69,7 +69,7 @@ func (b *backendAccounts) GetAccountAtBlockHeight( ) (*flow.Account, error) { blockID, err := b.headers.BlockIDByHeight(height) if err != nil { - return nil, rpc.ConvertStorageError(err) + return nil, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } account, err := b.getAccountAtBlock(ctx, address, blockID, height) @@ -109,7 +109,7 @@ func (b *backendAccounts) GetAccountBalanceAtBlockHeight( ) (uint64, error) { blockID, err := b.headers.BlockIDByHeight(height) if err != nil { - return 0, rpc.ConvertStorageError(err) + return 0, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } balance, err := b.getAccountBalanceAtBlock(ctx, address, blockID, height) @@ -177,7 +177,7 @@ func (b *backendAccounts) GetAccountKeyAtBlockHeight( ) (*flow.AccountPublicKey, error) { blockID, err := b.headers.BlockIDByHeight(height) if err != nil { - return nil, rpc.ConvertStorageError(err) + return nil, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } accountKey, err := b.getAccountKeyAtBlock(ctx, address, keyIndex, blockID, height) @@ -197,7 +197,7 @@ func (b *backendAccounts) GetAccountKeysAtBlockHeight( ) ([]flow.AccountPublicKey, error) { blockID, err := b.headers.BlockIDByHeight(height) if err != nil { - return nil, rpc.ConvertStorageError(err) + return nil, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } accountKeys, err := b.getAccountKeysAtBlock(ctx, address, blockID, height) @@ -401,7 +401,7 @@ func (b *backendAccounts) getAccountFromLocalStorage( // make sure data is available for the requested block account, err := b.scriptExecutor.GetAccountAtBlockHeight(ctx, address, height) if err != nil { - return nil, convertAccountError(err, address, height) + return nil, convertAccountError(resolveHeightError(b.state.Params(), height, err), address, height) } return account, nil } diff --git a/engine/access/rpc/backend/backend_accounts_test.go b/engine/access/rpc/backend/backend_accounts_test.go index 1311b0330d5..129b5679e33 100644 --- a/engine/access/rpc/backend/backend_accounts_test.go +++ b/engine/access/rpc/backend/backend_accounts_test.go @@ -246,6 +246,8 @@ func (s *BackendAccountsSuite) TestGetAccountFromStorage_Fails() { scriptExecutor.On("GetAccountAtBlockHeight", mock.Anything, s.failingAddress, s.block.Header.Height). Return(nil, tt.err).Times(3) + s.state.On("Params").Return(s.params).Times(3) + s.Run(fmt.Sprintf("GetAccount - fails with %v", tt.err), func() { s.testGetAccount(ctx, backend, tt.statusCode) }) @@ -255,6 +257,9 @@ func (s *BackendAccountsSuite) TestGetAccountFromStorage_Fails() { }) s.Run(fmt.Sprintf("GetAccountAtBlockHeight - fails with %v", tt.err), func() { + s.params.On("SporkRootBlockHeight").Return(s.block.Header.Height-10, nil) + s.params.On("SealedRoot").Return(s.block.Header, nil) + s.testGetAccountAtBlockHeight(ctx, backend, tt.statusCode) }) } @@ -287,6 +292,9 @@ func (s *BackendAccountsSuite) TestGetAccountFromFailover_HappyPath() { }) s.Run(fmt.Sprintf("GetAccountAtBlockHeight - happy path - recovers %v", errToReturn), func() { + s.params.On("SporkRootBlockHeight").Return(s.block.Header.Height-10, nil) + s.params.On("SealedRoot").Return(s.block.Header, nil) + s.testGetAccountAtBlockHeight(ctx, backend, codes.OK) }) } diff --git a/engine/access/rpc/backend/backend_block_details.go b/engine/access/rpc/backend/backend_block_details.go index 698e66b0727..c0a21f97b76 100644 --- a/engine/access/rpc/backend/backend_block_details.go +++ b/engine/access/rpc/backend/backend_block_details.go @@ -80,7 +80,7 @@ func (b *backendBlockDetails) GetBlockByID(ctx context.Context, id flow.Identifi func (b *backendBlockDetails) GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, flow.BlockStatus, error) { block, err := b.blocks.ByHeight(height) if err != nil { - return nil, flow.BlockStatusUnknown, rpc.ConvertStorageError(err) + return nil, flow.BlockStatusUnknown, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } stat, err := b.getBlockStatus(ctx, block) diff --git a/engine/access/rpc/backend/backend_block_headers.go b/engine/access/rpc/backend/backend_block_headers.go index a61fcab711a..d77bdc57819 100644 --- a/engine/access/rpc/backend/backend_block_headers.go +++ b/engine/access/rpc/backend/backend_block_headers.go @@ -69,7 +69,7 @@ func (b *backendBlockHeaders) GetBlockHeaderByID(ctx context.Context, id flow.Id func (b *backendBlockHeaders) GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.Header, flow.BlockStatus, error) { header, err := b.headers.ByHeight(height) if err != nil { - return nil, flow.BlockStatusUnknown, rpc.ConvertStorageError(err) + return nil, flow.BlockStatusUnknown, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), height, err)) } stat, err := b.getBlockStatus(ctx, header) diff --git a/engine/access/rpc/backend/backend_events.go b/engine/access/rpc/backend/backend_events.go index c3b872b0ad1..56f3207e8b7 100644 --- a/engine/access/rpc/backend/backend_events.go +++ b/engine/access/rpc/backend/backend_events.go @@ -104,7 +104,7 @@ func (b *backendEvents) GetEventsForHeightRange( // and avoids calculating header.ID() for each block. blockID, err := b.headers.BlockIDByHeight(i) if err != nil { - return nil, rpc.ConvertStorageError(fmt.Errorf("failed to get blockID for %d: %w", i, err)) + return nil, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), i, err)) } header, err := b.headers.ByBlockID(blockID) if err != nil { diff --git a/engine/access/rpc/backend/backend_events_test.go b/engine/access/rpc/backend/backend_events_test.go index a183c2bb0ab..11b2d52ea99 100644 --- a/engine/access/rpc/backend/backend_events_test.go +++ b/engine/access/rpc/backend/backend_events_test.go @@ -439,6 +439,39 @@ func (s *BackendEventsSuite) TestGetEventsForHeightRange_HandlesErrors() { s.Assert().Equal(codes.OutOfRange, status.Code(err)) s.Assert().Nil(response) }) + + s.state.On("Params").Return(s.params) + + s.Run("returns error for startHeight < spork root height", func() { + backend := s.defaultBackend() + + sporkRootHeight := s.blocks[0].Header.Height - 10 + startHeight := sporkRootHeight - 1 + + s.params.On("SporkRootBlockHeight").Return(sporkRootHeight).Once() + s.params.On("SealedRoot").Return(s.rootHeader, nil).Once() + + response, err := backend.GetEventsForHeightRange(ctx, targetEvent, startHeight, endHeight, encoding) + s.Assert().Equal(codes.NotFound, status.Code(err)) + s.Assert().ErrorContains(err, "Try to use a historic node") + s.Assert().Nil(response) + }) + + s.Run("returns error for startHeight < node root height", func() { + backend := s.defaultBackend() + + sporkRootHeight := s.blocks[0].Header.Height - 10 + nodeRootHeader := unittest.BlockHeaderWithHeight(s.blocks[0].Header.Height) + startHeight := nodeRootHeader.Height - 5 + + s.params.On("SporkRootBlockHeight").Return(sporkRootHeight).Once() + s.params.On("SealedRoot").Return(nodeRootHeader, nil).Once() + + response, err := backend.GetEventsForHeightRange(ctx, targetEvent, startHeight, endHeight, encoding) + s.Assert().Equal(codes.NotFound, status.Code(err)) + s.Assert().ErrorContains(err, "Try to use a different Access node") + s.Assert().Nil(response) + }) } func (s *BackendEventsSuite) TestGetEventsForBlockIDs_HandlesErrors() { diff --git a/engine/access/rpc/backend/backend_scripts.go b/engine/access/rpc/backend/backend_scripts.go index bea33fb5181..b0237447d46 100644 --- a/engine/access/rpc/backend/backend_scripts.go +++ b/engine/access/rpc/backend/backend_scripts.go @@ -105,7 +105,7 @@ func (b *backendScripts) ExecuteScriptAtBlockHeight( ) ([]byte, error) { header, err := b.headers.ByHeight(blockHeight) if err != nil { - return nil, rpc.ConvertStorageError(err) + return nil, rpc.ConvertStorageError(resolveHeightError(b.state.Params(), blockHeight, err)) } return b.executeScript(ctx, newScriptExecutionRequest(header.ID(), blockHeight, script, arguments)) diff --git a/engine/access/rpc/backend/backend_test.go b/engine/access/rpc/backend/backend_test.go index 93f3d24eeb1..a3068e32645 100644 --- a/engine/access/rpc/backend/backend_test.go +++ b/engine/access/rpc/backend/backend_test.go @@ -17,7 +17,6 @@ import ( execproto "github.com/onflow/flow/protobuf/go/flow/execution" "github.com/rs/zerolog" "github.com/sony/gobreaker" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -1487,7 +1486,7 @@ func (suite *Suite) TestGetExecutionResultByID() { // execute request _, err = backend.GetExecutionResultByID(ctx, nonexistingID) - assert.Error(suite.T(), err) + suite.Assert().Error(err) }) suite.Run("existing execution result id", func() { @@ -1551,7 +1550,7 @@ func (suite *Suite) TestGetExecutionResultByBlockID() { // execute request _, err = backend.GetExecutionResultForBlockID(ctx, nonexistingBlockID) - assert.Error(suite.T(), err) + suite.Assert().Error(err) }) suite.Run("existing execution results", func() { @@ -2042,3 +2041,80 @@ func (suite *Suite) defaultBackendParams() Params { ), } } + +// TestResolveHeightError tests the resolveHeightError function for various scenarios where the block height +// is below the spork root height, below the node root height, above the node root height, or when a different +// error is provided. It validates that resolveHeightError returns an appropriate error message for each case. +// +// Test cases: +// 1) If height is below the spork root height, it suggests using a historic node. +// 2) If height is below the node root height, it suggests using a different Access node. +// 3) If height is above the node root height, it returns the original error without modification. +// 4) If a non-storage-related error is provided, it returns the error as is. +func (suite *Suite) TestResolveHeightError() { + tests := []struct { + name string + height uint64 + sporkRootHeight uint64 + nodeRootHeight uint64 + genericErr error + expectedErrorMsg string + expectOriginalErr bool + }{ + { + name: "height below spork root height", + height: uint64(50), + sporkRootHeight: uint64(100), + nodeRootHeight: uint64(200), + genericErr: storage.ErrNotFound, + expectedErrorMsg: "block height %d is less than the spork root block height 100. Try to use a historic node: %v"}, + { + name: "height below node root height", + height: uint64(150), + sporkRootHeight: uint64(100), + nodeRootHeight: uint64(200), + genericErr: storage.ErrNotFound, + expectedErrorMsg: "block height %d is less than the node's root block height 200. Try to use a different Access node: %v", + expectOriginalErr: false, + }, + { + name: "height above node root height", + height: uint64(205), + sporkRootHeight: uint64(100), + nodeRootHeight: uint64(200), + genericErr: storage.ErrNotFound, + expectedErrorMsg: "%v", + expectOriginalErr: true, + }, + { + name: "non-storage related error", + height: uint64(150), + sporkRootHeight: uint64(100), + nodeRootHeight: uint64(200), + genericErr: fmt.Errorf("some other error"), + expectedErrorMsg: "%v", + expectOriginalErr: true, + }, + } + + for _, test := range tests { + suite.T().Run(test.name, func(t *testing.T) { + stateParams := protocol.NewParams(suite.T()) + + if errors.Is(test.genericErr, storage.ErrNotFound) { + stateParams.On("SporkRootBlockHeight").Return(test.sporkRootHeight).Once() + sealedRootHeader := unittest.BlockHeaderWithHeight(test.nodeRootHeight) + stateParams.On("SealedRoot").Return(sealedRootHeader, nil).Once() + } + + err := resolveHeightError(stateParams, test.height, test.genericErr) + + if test.expectOriginalErr { + suite.Assert().True(errors.Is(err, test.genericErr)) + } else { + expectedError := fmt.Sprintf(test.expectedErrorMsg, test.height, test.genericErr) + suite.Assert().Equal(err.Error(), expectedError) + } + }) + } +} diff --git a/engine/common/rpc/execution_node_identities_provider.go b/engine/common/rpc/execution_node_identities_provider.go index 0a56c53a08a..75a1f0b33bf 100644 --- a/engine/common/rpc/execution_node_identities_provider.go +++ b/engine/common/rpc/execution_node_identities_provider.go @@ -58,8 +58,6 @@ type ExecutionNodeIdentitiesProvider struct { // are prioritized during selection. // - fixedENIdentifiers: A flow.IdentifierList of fixed execution node identifiers that are // always considered if available. -// -// No error returns are expected during normal operations. func NewExecutionNodeIdentitiesProvider( log zerolog.Logger, state protocol.State, diff --git a/engine/common/rpc/execution_node_identities_provider_test.go b/engine/common/rpc/execution_node_identities_provider_test.go index eb23faf34a6..2b033e3dac0 100644 --- a/engine/common/rpc/execution_node_identities_provider_test.go +++ b/engine/common/rpc/execution_node_identities_provider_test.go @@ -17,7 +17,8 @@ import ( "github.com/onflow/flow-go/utils/unittest" ) -type Suite struct { +// ENIdentitiesProviderSuite is a test suite for testing the ExecutionNodeIdentitiesProvider. +type ENIdentitiesProviderSuite struct { suite.Suite state *protocol.State @@ -28,10 +29,11 @@ type Suite struct { } func TestHandler(t *testing.T) { - suite.Run(t, new(Suite)) + suite.Run(t, new(ENIdentitiesProviderSuite)) } -func (suite *Suite) SetupTest() { +// SetupTest initializes the test suite with mock state and receipts storage. +func (suite *ENIdentitiesProviderSuite) SetupTest() { suite.log = zerolog.New(zerolog.NewConsoleWriter()) suite.state = new(protocol.State) suite.snapshot = new(protocol.Snapshot) @@ -43,9 +45,10 @@ func (suite *Suite) SetupTest() { suite.state.On("Params").Return(params) } -// TestExecutionNodesForBlockID tests the ExecutionNodesForBlockID used for serving all API calls -// that need to talk to an execution node. -func (suite *Suite) TestExecutionNodesForBlockID() { +// TestExecutionNodesForBlockID tests the ExecutionNodesForBlockID function. +// This function is responsible for retrieving execution nodes used to serve +// all API calls that interact with execution nodes. +func (suite *ENIdentitiesProviderSuite) TestExecutionNodesForBlockID() { totalReceipts := 5 block := unittest.BlockFixture() diff --git a/engine/execution/state/bootstrap/bootstrap_test.go b/engine/execution/state/bootstrap/bootstrap_test.go index 96457ebda93..5a7a99dc417 100644 --- a/engine/execution/state/bootstrap/bootstrap_test.go +++ b/engine/execution/state/bootstrap/bootstrap_test.go @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) { } func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) { - expectedStateCommitmentBytes, _ := hex.DecodeString("edc0ffd7e797e2383bc68b694645e6b62b0d996498bcff9b492bf4d426798ec5") + expectedStateCommitmentBytes, _ := hex.DecodeString("543fa7112081094b66871692c5a7784f40a9e5cdb9cfda10d1d9b81653966409") expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes) require.NoError(t, err) diff --git a/follower/follower_builder.go b/follower/follower_builder.go index 2988ee2767e..6d7b909125c 100644 --- a/follower/follower_builder.go +++ b/follower/follower_builder.go @@ -1,16 +1,12 @@ package follower import ( - "context" "encoding/json" "errors" "fmt" "strings" - dht "github.com/libp2p/go-libp2p-kad-dht" - "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/routing" "github.com/onflow/crypto" "github.com/rs/zerolog" @@ -44,17 +40,12 @@ import ( cborcodec "github.com/onflow/flow-go/network/codec/cbor" "github.com/onflow/flow-go/network/converter" "github.com/onflow/flow-go/network/p2p" - p2pbuilder "github.com/onflow/flow-go/network/p2p/builder" - p2pbuilderconfig "github.com/onflow/flow-go/network/p2p/builder/config" "github.com/onflow/flow-go/network/p2p/cache" "github.com/onflow/flow-go/network/p2p/conduit" - p2pdht "github.com/onflow/flow-go/network/p2p/dht" "github.com/onflow/flow-go/network/p2p/keyutils" p2plogging "github.com/onflow/flow-go/network/p2p/logging" - "github.com/onflow/flow-go/network/p2p/subscription" "github.com/onflow/flow-go/network/p2p/translator" "github.com/onflow/flow-go/network/p2p/unicast/protocols" - "github.com/onflow/flow-go/network/p2p/utils" "github.com/onflow/flow-go/network/slashing" "github.com/onflow/flow-go/network/underlay" "github.com/onflow/flow-go/network/validator" @@ -84,19 +75,14 @@ import ( // For a node running as a standalone process, the config fields will be populated from the command line params, // while for a node running as a library, the config fields are expected to be initialized by the caller. type FollowerServiceConfig struct { - bootstrapNodeAddresses []string - bootstrapNodePublicKeys []string - bootstrapIdentities flow.IdentitySkeletonList // the identity list of bootstrap peers the node uses to discover other nodes - NetworkKey crypto.PrivateKey // the networking key passed in by the caller when being used as a library - baseOptions []cmd.Option + bootstrapIdentities flow.IdentitySkeletonList // the identity list of bootstrap peers the node uses to discover other nodes + NetworkKey crypto.PrivateKey // the networking key passed in by the caller when being used as a library + baseOptions []cmd.Option } // DefaultFollowerServiceConfig defines all the default values for the FollowerServiceConfig func DefaultFollowerServiceConfig() *FollowerServiceConfig { - return &FollowerServiceConfig{ - bootstrapNodeAddresses: []string{}, - bootstrapNodePublicKeys: []string{}, - } + return &FollowerServiceConfig{} } // FollowerServiceBuilder provides the common functionality needed to bootstrap a Flow staked and observer @@ -136,7 +122,7 @@ func (builder *FollowerServiceBuilder) deriveBootstrapPeerIdentities() error { return nil } - ids, err := BootstrapIdentities(builder.bootstrapNodeAddresses, builder.bootstrapNodePublicKeys) + ids, err := builder.DeriveBootstrapPeerIdentities() if err != nil { return fmt.Errorf("failed to derive bootstrap peer identities: %w", err) } @@ -535,86 +521,15 @@ func (builder *FollowerServiceBuilder) validateParams() error { if len(builder.bootstrapIdentities) > 0 { return nil } - if len(builder.bootstrapNodeAddresses) == 0 { + if len(builder.BootstrapNodeAddresses) == 0 { return errors.New("no bootstrap node address provided") } - if len(builder.bootstrapNodeAddresses) != len(builder.bootstrapNodePublicKeys) { + if len(builder.BootstrapNodeAddresses) != len(builder.BootstrapNodePublicKeys) { return errors.New("number of bootstrap node addresses and public keys should match") } return nil } -// initPublicLibp2pNode creates a libp2p node for the follower service in public (unstaked) network. -// The LibP2P host is created with the following options: -// - DHT as client and seeded with the given bootstrap peers -// - The specified bind address as the listen address -// - The passed in private key as the libp2p key -// - No connection gater -// - No connection manager -// - No peer manager -// - Default libp2p pubsub options -// -// Args: -// - networkKey: the private key to use for the libp2p node -// -// Returns: -// - p2p.LibP2PNode: the libp2p node -// - error: if any error occurs. Any error returned from this function is irrecoverable. -func (builder *FollowerServiceBuilder) initPublicLibp2pNode(networkKey crypto.PrivateKey) (p2p.LibP2PNode, error) { - var pis []peer.AddrInfo - - for _, b := range builder.bootstrapIdentities { - pi, err := utils.PeerAddressInfo(*b) - if err != nil { - return nil, fmt.Errorf("could not extract peer address info from bootstrap identity %v: %w", b, err) - } - - pis = append(pis, pi) - } - - node, err := p2pbuilder.NewNodeBuilder( - builder.Logger, - &builder.FlowConfig.NetworkConfig.GossipSub, - &p2pbuilderconfig.MetricsConfig{ - HeroCacheFactory: builder.HeroCacheMetricsFactory(), - Metrics: builder.Metrics.Network, - }, - network.PublicNetwork, - builder.BaseConfig.BindAddr, - networkKey, - builder.SporkID, - builder.IdentityProvider, - &builder.FlowConfig.NetworkConfig.ResourceManager, - p2pbuilderconfig.PeerManagerDisableConfig(), // disable peer manager for follower - &p2p.DisallowListCacheConfig{ - MaxSize: builder.FlowConfig.NetworkConfig.DisallowListNotificationCacheSize, - Metrics: metrics.DisallowListCacheMetricsFactory(builder.HeroCacheMetricsFactory(), network.PublicNetwork), - }, - &p2pbuilderconfig.UnicastConfig{ - Unicast: builder.FlowConfig.NetworkConfig.Unicast, - }). - SetSubscriptionFilter( - subscription.NewRoleBasedFilter( - subscription.UnstakedRole, builder.IdentityProvider, - ), - ). - SetRoutingSystem(func(ctx context.Context, h host.Host) (routing.Routing, error) { - return p2pdht.NewDHT(ctx, h, protocols.FlowPublicDHTProtocolID(builder.SporkID), - builder.Logger, - builder.Metrics.Network, - p2pdht.AsClient(), - dht.BootstrapPeers(pis...), - ) - }).Build() - if err != nil { - return nil, fmt.Errorf("could not build public libp2p node: %w", err) - } - - builder.LibP2PNode = node - - return builder.LibP2PNode, nil -} - // initObserverLocal initializes the observer's ID, network key and network address // Currently, it reads a node-info.priv.json like any other node. // TODO: read the node ID from the special bootstrap files @@ -651,11 +566,12 @@ func (builder *FollowerServiceBuilder) enqueuePublicNetworkInit() { builder. Component("public libp2p node", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) { var err error - publicLibp2pNode, err = builder.initPublicLibp2pNode(node.NetworkKey) + publicLibp2pNode, err = builder.BuildPublicLibp2pNode(builder.BaseConfig.BindAddr, builder.bootstrapIdentities) if err != nil { - return nil, fmt.Errorf("could not create public libp2p node: %w", err) + return nil, fmt.Errorf("could not build public libp2p node: %w", err) } + builder.LibP2PNode = publicLibp2pNode return publicLibp2pNode, nil }). Component("public network", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) { diff --git a/fvm/bootstrap.go b/fvm/bootstrap.go index 5c7e09d31ed..0f3526c8d83 100644 --- a/fvm/bootstrap.go +++ b/fvm/bootstrap.go @@ -351,6 +351,7 @@ func (b *bootstrapExecutor) Execute() error { b.deployViewResolver(service, &env) b.deployBurner(service, &env) + b.deployCrypto(service, &env) err = expectAccounts(1) if err != nil { @@ -523,6 +524,22 @@ func (b *bootstrapExecutor) deployBurner(deployTo flow.Address, env *templates.E panicOnMetaInvokeErrf("failed to deploy burner contract: %s", txError, err) } +func (b *bootstrapExecutor) deployCrypto(deployTo flow.Address, env *templates.Environment) { + contract := contracts.Crypto() + + txError, err := b.invokeMetaTransaction( + b.ctx, + Transaction( + blueprints.DeployContractTransaction( + deployTo, + contract, + "Crypto"), + 0), + ) + env.CryptoAddress = deployTo.String() + panicOnMetaInvokeErrf("failed to deploy crypto contract: %s", txError, err) +} + func (b *bootstrapExecutor) deployMetadataViews(fungibleToken, nonFungibleToken flow.Address, env *templates.Environment) { mvContract := contracts.MetadataViews(*env) diff --git a/fvm/crypto/hash_test.go b/fvm/crypto/hash_test.go index 29eeb7ec09c..6c8ba0354c8 100644 --- a/fvm/crypto/hash_test.go +++ b/fvm/crypto/hash_test.go @@ -2,10 +2,9 @@ package crypto_test import ( "crypto/rand" - "testing" - "crypto/sha256" "crypto/sha512" + "testing" "github.com/onflow/crypto/hash" "github.com/stretchr/testify/assert" diff --git a/fvm/environment/contract_reader.go b/fvm/environment/contract_reader.go index e3c868ee2e9..5c8aba5cc25 100644 --- a/fvm/environment/contract_reader.go +++ b/fvm/environment/contract_reader.go @@ -6,6 +6,7 @@ import ( "github.com/onflow/cadence/ast" "github.com/onflow/cadence/common" "github.com/onflow/cadence/runtime" + "github.com/onflow/cadence/stdlib" "github.com/onflow/flow-go/fvm/errors" "github.com/onflow/flow-go/fvm/tracing" @@ -15,21 +16,23 @@ import ( // ContractReader provide read access to contracts. type ContractReader struct { - tracer tracing.TracerSpan - meter Meter - - accounts Accounts + tracer tracing.TracerSpan + meter Meter + accounts Accounts + cryptoContractAddress common.Address } func NewContractReader( tracer tracing.TracerSpan, meter Meter, accounts Accounts, + cryptoContractAddress common.Address, ) *ContractReader { return &ContractReader{ - tracer: tracer, - meter: meter, - accounts: accounts, + tracer: tracer, + meter: meter, + accounts: accounts, + cryptoContractAddress: cryptoContractAddress, } } @@ -69,12 +72,37 @@ func (reader *ContractReader) ResolveLocation( return nil, fmt.Errorf("resolve location failed: %w", err) } + return ResolveLocation( + identifiers, + location, + reader.accounts.GetContractNames, + reader.cryptoContractAddress, + ) +} + +func ResolveLocation( + identifiers []ast.Identifier, + location common.Location, + getContractNames func(flow.Address) ([]string, error), + cryptoContractAddress common.Address, +) ([]runtime.ResolvedLocation, error) { + addressLocation, isAddress := location.(common.AddressLocation) // if the location is not an address location, e.g. an identifier location - // (`import Crypto`), then return a single resolved location which declares - // all identifiers. + // then return a single resolved location which declares all identifiers. if !isAddress { + + // if the location is the Crypto contract, + // translate it to the address of the Crypto contract on the chain + + if location == stdlib.CryptoContractLocation { + location = common.AddressLocation{ + Address: cryptoContractAddress, + Name: string(stdlib.CryptoContractLocation), + } + } + return []runtime.ResolvedLocation{ { Location: location, @@ -87,9 +115,13 @@ func (reader *ContractReader) ResolveLocation( // and no specific identifiers where requested in the import statement, // then fetch all identifiers at this address if len(identifiers) == 0 { + if getContractNames == nil { + return nil, fmt.Errorf("no identifiers provided") + } + address := flow.ConvertAddress(addressLocation.Address) - contractNames, err := reader.accounts.GetContractNames(address) + contractNames, err := getContractNames(address) if err != nil { return nil, fmt.Errorf("resolving location failed: %w", err) } diff --git a/fvm/environment/facade_env.go b/fvm/environment/facade_env.go index 2f101b9aa9d..67e20e02394 100644 --- a/fvm/environment/facade_env.go +++ b/fvm/environment/facade_env.go @@ -11,6 +11,7 @@ import ( "github.com/onflow/flow-go/fvm/storage" "github.com/onflow/flow-go/fvm/storage/snapshot" "github.com/onflow/flow-go/fvm/storage/state" + "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/fvm/tracing" ) @@ -63,12 +64,15 @@ func newFacadeEnvironment( accounts := NewAccounts(txnState) logger := NewProgramLogger(tracer, params.ProgramLoggerParams) runtime := NewRuntime(params.RuntimeParams) + chain := params.Chain systemContracts := NewSystemContracts( - params.Chain, + chain, tracer, logger, runtime) + sc := systemcontracts.SystemContractsForChain(chain.ChainID()) + env := &facadeEnvironment{ Runtime: runtime, @@ -130,6 +134,7 @@ func newFacadeEnvironment( tracer, meter, accounts, + common.Address(sc.Crypto.Address), ), ContractUpdater: NoContractUpdater{}, Programs: NewPrograms( diff --git a/fvm/evm/stdlib/checking.go b/fvm/evm/stdlib/checking.go index 03819737de1..81faed8c298 100644 --- a/fvm/evm/stdlib/checking.go +++ b/fvm/evm/stdlib/checking.go @@ -1,11 +1,11 @@ package stdlib import ( - "fmt" - "github.com/onflow/cadence/common" "github.com/onflow/cadence/interpreter" "github.com/onflow/cadence/runtime" + + "github.com/onflow/flow-go/fvm/environment" ) // checkingInterface is a runtime.Interface implementation @@ -13,68 +13,41 @@ import ( // It is not suitable for execution. type checkingInterface struct { runtime.EmptyRuntimeInterface - SystemContractCodes map[common.AddressLocation][]byte - Programs map[runtime.Location]*interpreter.Program + SystemContractCodes map[common.Location][]byte + Programs map[runtime.Location]*interpreter.Program + cryptoContractAddress common.Address } var _ runtime.Interface = &checkingInterface{} -func (*checkingInterface) ResolveLocation( +func (i *checkingInterface) ResolveLocation( identifiers []runtime.Identifier, location runtime.Location, ) ( []runtime.ResolvedLocation, error, ) { - - addressLocation, isAddress := location.(common.AddressLocation) - - // if the location is not an address location, e.g. an identifier location - // (`import Crypto`), then return a single resolved location which declares - // all identifiers. - if !isAddress { - return []runtime.ResolvedLocation{ - { - Location: location, - Identifiers: identifiers, - }, - }, nil - } - - if len(identifiers) == 0 { - return nil, fmt.Errorf("no identifiers provided") - } - - // return one resolved location per identifier. - // each resolved location is an address contract location - resolvedLocations := make([]runtime.ResolvedLocation, len(identifiers)) - for i := range resolvedLocations { - identifier := identifiers[i] - resolvedLocations[i] = runtime.ResolvedLocation{ - Location: common.AddressLocation{ - Address: addressLocation.Address, - Name: identifier.Identifier, - }, - Identifiers: []runtime.Identifier{identifier}, - } - } - - return resolvedLocations, nil + return environment.ResolveLocation( + identifiers, + location, + nil, + i.cryptoContractAddress, + ) } -func (r *checkingInterface) GetOrLoadProgram( +func (i *checkingInterface) GetOrLoadProgram( location runtime.Location, load func() (*interpreter.Program, error), ) ( program *interpreter.Program, err error, ) { - if r.Programs == nil { - r.Programs = map[runtime.Location]*interpreter.Program{} + if i.Programs == nil { + i.Programs = map[runtime.Location]*interpreter.Program{} } var ok bool - program, ok = r.Programs[location] + program, ok = i.Programs[location] if ok { return } @@ -84,11 +57,15 @@ func (r *checkingInterface) GetOrLoadProgram( // NOTE: important: still set empty program, // even if error occurred - r.Programs[location] = program + i.Programs[location] = program return } -func (r *checkingInterface) GetAccountContractCode(location common.AddressLocation) (code []byte, err error) { - return r.SystemContractCodes[location], nil +func (i *checkingInterface) GetCode(location common.Location) ([]byte, error) { + return i.SystemContractCodes[location], nil +} + +func (i *checkingInterface) GetAccountContractCode(location common.AddressLocation) (code []byte, err error) { + return i.SystemContractCodes[location], nil } diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index 986313c50df..618f9b0b9fa 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -74,7 +74,7 @@ contract EVM { /// This data helps to replay the transactions without the need to /// have access to the full cadence state data. precompiledCalls: [UInt8], - /// stateUpdateChecksum provides a mean to validate + /// stateUpdateChecksum provides a mean to validate /// the updates to the storage when re-executing a transaction off-chain. stateUpdateChecksum: [UInt8; 4] ) diff --git a/fvm/evm/stdlib/contract_test.go b/fvm/evm/stdlib/contract_test.go index 619e8d7a63f..bdffe56846b 100644 --- a/fvm/evm/stdlib/contract_test.go +++ b/fvm/evm/stdlib/contract_test.go @@ -30,6 +30,26 @@ import ( "github.com/onflow/flow-go/model/flow" ) +func newLocationResolver( + cryptoContractAddress flow.Address, +) func( + identifiers []runtime.Identifier, + location runtime.Location, +) ([]runtime.ResolvedLocation, error) { + cryptoContractAddress2 := common.Address(cryptoContractAddress) + return func( + identifiers []runtime.Identifier, + location runtime.Location, + ) ([]runtime.ResolvedLocation, error) { + return environment.ResolveLocation( + identifiers, + location, + nil, + cryptoContractAddress2, + ) + } +} + type testContractHandler struct { flowTokenAddress common.Address evmContractAddress common.Address @@ -222,6 +242,7 @@ func deployContracts( NonFungibleTokenAddress: contractsAddressHex, MetadataViewsAddress: contractsAddressHex, FungibleTokenMetadataViewsAddress: contractsAddressHex, + CryptoAddress: contractsAddressHex, } contracts := []struct { @@ -229,6 +250,10 @@ func deployContracts( code []byte deployTx []byte }{ + { + name: "Crypto", + code: coreContracts.Crypto(), + }, { name: "ViewResolver", code: coreContracts.ViewResolver(), @@ -373,7 +398,7 @@ func TestEVMEncodeABI(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -474,7 +499,7 @@ func TestEVMEncodeABIByteTypes(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -921,7 +946,7 @@ func TestEVMEncodeABIBytesRoundtrip(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1279,7 +1304,7 @@ func TestEVMEncodeABIComputation(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1374,7 +1399,7 @@ func TestEVMEncodeABIComputationEmptyDynamicVariables(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1478,7 +1503,7 @@ func TestEVMEncodeABIComputationDynamicVariablesAboveChunkSize(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1576,7 +1601,7 @@ func TestEVMDecodeABI(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1709,7 +1734,7 @@ func TestEVMDecodeABIComputation(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -1786,7 +1811,7 @@ func TestEVMEncodeDecodeABIRoundtripForUintIntTypes(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2252,7 +2277,7 @@ func TestEVMEncodeDecodeABIRoundtrip(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2330,7 +2355,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2416,7 +2441,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2501,7 +2526,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2587,7 +2612,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2673,7 +2698,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2769,7 +2794,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2855,7 +2880,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -2941,7 +2966,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3027,7 +3052,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3113,7 +3138,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3199,7 +3224,7 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3315,7 +3340,7 @@ func TestEVMEncodeABIWithSignature(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3448,7 +3473,7 @@ func TestEVMDecodeABIWithSignature(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3568,7 +3593,7 @@ func TestEVMDecodeABIWithSignatureMismatch(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3671,7 +3696,7 @@ func TestEVMAddressConstructionAndReturn(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3773,7 +3798,7 @@ func TestEVMAddressSerializationAndDeserialization(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -3950,7 +3975,7 @@ func TestBalanceConstructionAndReturn(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4080,7 +4105,7 @@ func TestEVMRun(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4197,7 +4222,7 @@ func TestEVMDryRun(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4336,7 +4361,7 @@ func TestEVMBatchRun(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4436,7 +4461,7 @@ func TestEVMCreateCadenceOwnedAccount(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4592,7 +4617,7 @@ func TestCadenceOwnedAccountCall(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4711,7 +4736,7 @@ func TestEVMAddressDeposit(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4824,7 +4849,7 @@ func TestCOADeposit(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -4995,7 +5020,7 @@ func TestCadenceOwnedAccountWithdraw(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -5148,7 +5173,7 @@ func TestCadenceOwnedAccountDeploy(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -5223,7 +5248,7 @@ func RunEVMScript( OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -5461,7 +5486,7 @@ func TestEVMValidateCOAOwnershipProof(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil @@ -5609,7 +5634,7 @@ func TestInternalEVMAccess(t *testing.T) { OnGetSigningAccounts: func() ([]runtime.Address, error) { return []runtime.Address{runtime.Address(contractsAddress)}, nil }, - OnResolveLocation: LocationResolver, + OnResolveLocation: newLocationResolver(contractsAddress), OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { accountCodes[location] = code return nil diff --git a/fvm/evm/stdlib/type.go b/fvm/evm/stdlib/type.go index ed3c1825f16..5ad44909bb4 100644 --- a/fvm/evm/stdlib/type.go +++ b/fvm/evm/stdlib/type.go @@ -32,8 +32,11 @@ func newContractType(chainID flow.ChainID) *sema.CompositeType { templatesEnv := contracts.AsTemplateEnv() + cryptoContractLocation := contracts.Crypto.Location() + runtimeInterface := &checkingInterface{ - SystemContractCodes: map[common.AddressLocation][]byte{ + cryptoContractAddress: cryptoContractLocation.Address, + SystemContractCodes: map[common.Location][]byte{ contracts.ViewResolver.Location(): coreContracts.ViewResolver(), contracts.Burner.Location(): coreContracts.Burner(), contracts.FungibleToken.Location(): coreContracts.FungibleToken(templatesEnv), @@ -41,6 +44,7 @@ func newContractType(chainID flow.ChainID) *sema.CompositeType { contracts.MetadataViews.Location(): coreContracts.MetadataViews(templatesEnv), contracts.FlowToken.Location(): coreContracts.FlowToken(templatesEnv), contracts.FungibleTokenMetadataViews.Location(): coreContracts.FungibleTokenMetadataViews(templatesEnv), + cryptoContractLocation: coreContracts.Crypto(), }, } diff --git a/fvm/evm/testutils/cadence.go b/fvm/evm/testutils/cadence.go index 3af633e74d7..12f4889a428 100644 --- a/fvm/evm/testutils/cadence.go +++ b/fvm/evm/testutils/cadence.go @@ -5,64 +5,10 @@ import ( "testing" "github.com/onflow/cadence" - "github.com/onflow/cadence/ast" - "github.com/onflow/cadence/common" "github.com/onflow/cadence/encoding/json" - "github.com/onflow/cadence/runtime" - "github.com/onflow/cadence/sema" "github.com/stretchr/testify/require" ) -// LocationResolver is a location Cadence runtime interface location resolver -// very similar to ContractReader.ResolveLocation, -// but it does not look up available contract names -func LocationResolver( - identifiers []ast.Identifier, - location common.Location, -) ( - result []sema.ResolvedLocation, - err error, -) { - addressLocation, isAddress := location.(common.AddressLocation) - - // if the location is not an address location, e.g. an identifier location - // (`import Crypto`), then return a single resolved location which declares - // all identifiers. - if !isAddress { - return []runtime.ResolvedLocation{ - { - Location: location, - Identifiers: identifiers, - }, - }, nil - } - - // if the location is an address, - // and no specific identifiers where requested in the import statement, - // then assume the imported identifier is the address location's identifier (the contract) - if len(identifiers) == 0 { - identifiers = []ast.Identifier{ - {Identifier: addressLocation.Name}, - } - } - - // return one resolved location per identifier. - // each resolved location is an address contract location - resolvedLocations := make([]runtime.ResolvedLocation, len(identifiers)) - for i := range resolvedLocations { - identifier := identifiers[i] - resolvedLocations[i] = runtime.ResolvedLocation{ - Location: common.AddressLocation{ - Address: addressLocation.Address, - Name: identifier.Identifier, - }, - Identifiers: []runtime.Identifier{identifier}, - } - } - - return resolvedLocations, nil -} - func EncodeArgs(argValues []cadence.Value) [][]byte { args := make([][]byte, len(argValues)) for i, arg := range argValues { diff --git a/fvm/fvm_bench_test.go b/fvm/fvm_bench_test.go index 33ff347a6f1..566cf81653a 100644 --- a/fvm/fvm_bench_test.go +++ b/fvm/fvm_bench_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - flow2 "github.com/onflow/flow-go-sdk" + flowsdk "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/templates" "github.com/onflow/flow-go/engine/execution" @@ -315,13 +315,13 @@ func (b *BasicBlockExecutor) SetupAccounts(tb testing.TB, privateKeys []flow.Acc serviceAddress := b.Chain(tb).ServiceAddress() for _, privateKey := range privateKeys { - accountKey := flow2.NewAccountKey(). + accountKey := flowsdk.NewAccountKey(). FromPrivateKey(privateKey.PrivateKey). SetWeight(fvm.AccountKeyWeightThreshold). SetHashAlgo(privateKey.HashAlgo). SetSigAlgo(privateKey.SignAlgo) - sdkTX, err := templates.CreateAccount([]*flow2.AccountKey{accountKey}, []templates.Contract{}, flow2.BytesToAddress(serviceAddress.Bytes())) + sdkTX, err := templates.CreateAccount([]*flowsdk.AccountKey{accountKey}, []templates.Contract{}, flowsdk.BytesToAddress(serviceAddress.Bytes())) require.NoError(tb, err) txBody := flow.NewTransactionBody(). diff --git a/fvm/fvm_test.go b/fvm/fvm_test.go index 2fc6c9ccd2d..cb0d270f725 100644 --- a/fvm/fvm_test.go +++ b/fvm/fvm_test.go @@ -9,7 +9,10 @@ import ( "strings" "testing" - stdlib2 "github.com/onflow/cadence/stdlib" + cadenceStdlib "github.com/onflow/cadence/stdlib" + + flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go-sdk/test" envMock "github.com/onflow/flow-go/fvm/environment/mock" "github.com/onflow/flow-go/fvm/evm/events" @@ -971,7 +974,7 @@ func TestTransactionFeeDeduction(t *testing.T) { address := flow.ConvertAddress( cadence.SearchFieldByName( data.(cadence.Event), - stdlib2.AccountEventAddressParameter.Identifier, + cadenceStdlib.AccountEventAddressParameter.Identifier, ).(cadence.Address), ) @@ -1528,17 +1531,17 @@ func TestSettingExecutionWeights(t *testing.T) { SetScript([]byte(fmt.Sprintf(` import FungibleToken from 0x%s import FlowToken from 0x%s - + transaction() { let sentVault: @{FungibleToken.Vault} - + prepare(signer: auth(BorrowValue) &Account) { let vaultRef = signer.storage.borrow(from: /storage/flowTokenVault) ?? panic("Could not borrow reference to the owner's Vault!") - + self.sentVault <- vaultRef.withdraw(amount: 5.0) } - + execute { let recipient1 = getAccount(%s) let recipient2 = getAccount(%s) @@ -1556,7 +1559,7 @@ func TestSettingExecutionWeights(t *testing.T) { ?? panic("Could not borrow receiver reference to the recipient's Vault") let receiverRef5 = recipient5.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver) ?? panic("Could not borrow receiver reference to the recipient's Vault") - + receiverRef1.deposit(from: <-self.sentVault.withdraw(amount: 1.0)) receiverRef2.deposit(from: <-self.sentVault.withdraw(amount: 1.0)) receiverRef3.deposit(from: <-self.sentVault.withdraw(amount: 1.0)) @@ -2332,7 +2335,7 @@ func TestInteractionLimit(t *testing.T) { address = flow.ConvertAddress( cadence.SearchFieldByName( data.(cadence.Event), - stdlib2.AccountEventAddressParameter.Identifier, + cadenceStdlib.AccountEventAddressParameter.Identifier, ).(cadence.Address), ) @@ -2916,7 +2919,7 @@ func TestEVM(t *testing.T) { sc := systemcontracts.SystemContractsForChain(chain.ChainID()) script := fvm.Script([]byte(fmt.Sprintf(` import EVM from %s - + access(all) fun main() { let bal = EVM.Balance(attoflow: 1000000000000000000) let acc <- EVM.createCadenceOwnedAccount() @@ -2979,7 +2982,7 @@ func TestEVM(t *testing.T) { script := fvm.Script([]byte(fmt.Sprintf(` import EVM from %s - + access(all) fun main() { destroy <- EVM.createCadenceOwnedAccount() @@ -3011,7 +3014,7 @@ func TestEVM(t *testing.T) { txBody := flow.NewTransactionBody(). SetScript([]byte(fmt.Sprintf(` import FungibleToken from %s - import FlowToken from %s + import FlowToken from %s import EVM from %s transaction() { @@ -3029,7 +3032,7 @@ func TestEVM(t *testing.T) { acc.deposit(from: <- amount) destroy acc - // commit blocks + // commit blocks evmHeartbeat.heartbeat() } }`, @@ -3229,3 +3232,175 @@ func TestAccountCapabilitiesPublishEntitledRejection(t *testing.T) { }), ) } + +func TestCrypto(t *testing.T) { + t.Parallel() + + const chainID = flow.Testnet + + test := func(t *testing.T, importDecl string) { + + chain, vm := createChainAndVm(chainID) + + ctx := fvm.NewContext( + fvm.WithChain(chain), + fvm.WithCadenceLogging(true), + ) + + script := []byte(fmt.Sprintf( + ` + %s + + access(all) + fun main( + rawPublicKeys: [String], + weights: [UFix64], + domainSeparationTag: String, + signatures: [String], + toAddress: Address, + fromAddress: Address, + amount: UFix64 + ): Bool { + let keyList = Crypto.KeyList() + + var i = 0 + for rawPublicKey in rawPublicKeys { + keyList.add( + PublicKey( + publicKey: rawPublicKey.decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ), + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: weights[i], + ) + i = i + 1 + } + + let signatureSet: [Crypto.KeyListSignature] = [] + + var j = 0 + for signature in signatures { + signatureSet.append( + Crypto.KeyListSignature( + keyIndex: j, + signature: signature.decodeHex() + ) + ) + j = j + 1 + } + + // assemble the same message in cadence + let message = toAddress.toBytes() + .concat(fromAddress.toBytes()) + .concat(amount.toBigEndianBytes()) + + return keyList.verify( + signatureSet: signatureSet, + signedData: message, + domainSeparationTag: domainSeparationTag + ) + } + `, + importDecl, + )) + + accountKeys := test.AccountKeyGenerator() + + // create the keys + keyAlice, signerAlice := accountKeys.NewWithSigner() + keyBob, signerBob := accountKeys.NewWithSigner() + + // create the message that will be signed + addresses := test.AddressGenerator() + + toAddress := cadence.Address(addresses.New()) + fromAddress := cadence.Address(addresses.New()) + + amount, err := cadence.NewUFix64("100.00") + require.NoError(t, err) + + var message []byte + message = append(message, toAddress.Bytes()...) + message = append(message, fromAddress.Bytes()...) + message = append(message, amount.ToBigEndianBytes()...) + + // sign the message with Alice and Bob + signatureAlice, err := flowsdk.SignUserMessage(signerAlice, message) + require.NoError(t, err) + + signatureBob, err := flowsdk.SignUserMessage(signerBob, message) + require.NoError(t, err) + + publicKeys := cadence.NewArray([]cadence.Value{ + cadence.String(hex.EncodeToString(keyAlice.PublicKey.Encode())), + cadence.String(hex.EncodeToString(keyBob.PublicKey.Encode())), + }) + + // each signature has half weight + weightAlice, err := cadence.NewUFix64("0.5") + require.NoError(t, err) + + weightBob, err := cadence.NewUFix64("0.5") + require.NoError(t, err) + + weights := cadence.NewArray([]cadence.Value{ + weightAlice, + weightBob, + }) + + signatures := cadence.NewArray([]cadence.Value{ + cadence.String(hex.EncodeToString(signatureAlice)), + cadence.String(hex.EncodeToString(signatureBob)), + }) + + domainSeparationTag := cadence.String("FLOW-V0.0-user") + + arguments := []cadence.Value{ + publicKeys, + weights, + domainSeparationTag, + signatures, + toAddress, + fromAddress, + amount, + } + + encodedArguments := make([][]byte, 0, len(arguments)) + for _, argument := range arguments { + encodedArguments = append(encodedArguments, jsoncdc.MustEncode(argument)) + } + + snapshotTree := testutil.RootBootstrappedLedger(vm, ctx) + + _, output, err := vm.Run( + ctx, + fvm.Script(script). + WithArguments(encodedArguments...), + snapshotTree) + require.NoError(t, err) + + require.NoError(t, output.Err) + + result := output.Value + + assert.Equal(t, + cadence.NewBool(true), + result, + ) + } + + t.Run("identifier location", func(t *testing.T) { + t.Parallel() + + test(t, "import Crypto") + }) + + t.Run("address location", func(t *testing.T) { + t.Parallel() + + sc := systemcontracts.SystemContractsForChain(chainID) + cryptoContractAddress := sc.Crypto.Address.HexWithPrefix() + + test(t, fmt.Sprintf("import Crypto from %s", cryptoContractAddress)) + }) +} diff --git a/fvm/systemcontracts/system_contracts.go b/fvm/systemcontracts/system_contracts.go index 233c8bd0fb0..3760044698e 100644 --- a/fvm/systemcontracts/system_contracts.go +++ b/fvm/systemcontracts/system_contracts.go @@ -43,6 +43,7 @@ const ( ContractNameViewResolver = "ViewResolver" ContractNameEVM = "EVM" ContractNameBurner = "Burner" + ContractNameCrypto = "Crypto" // AccountNameEVMStorage is not a contract, but a special account that is used to store EVM state AccountNameEVMStorage = "EVMStorageAccount" @@ -171,6 +172,7 @@ type SystemContracts struct { // Utility contracts Burner SystemContract + Crypto SystemContract } // AsTemplateEnv returns a template environment with all system contracts filled in. @@ -198,6 +200,7 @@ func (c SystemContracts) AsTemplateEnv() templates.Environment { ViewResolverAddress: c.ViewResolver.Address.Hex(), BurnerAddress: c.Burner.Address.Hex(), + CryptoAddress: c.Crypto.Address.Hex(), } } @@ -228,6 +231,7 @@ func (c SystemContracts) All() []SystemContract { // EVMStorage is not included here, since it is not a contract c.Burner, + c.Crypto, } } @@ -365,6 +369,7 @@ func init() { AccountNameEVMStorage: evmStorageEVMFunc, ContractNameBurner: burnerAddressFunc, + ContractNameCrypto: serviceAddressFunc, } getSystemContractsForChain := func(chainID flow.ChainID) *SystemContracts { @@ -420,6 +425,7 @@ func init() { EVMStorage: addressOfAccount(AccountNameEVMStorage), Burner: addressOfContract(ContractNameBurner), + Crypto: addressOfContract(ContractNameCrypto), } return contracts diff --git a/go.mod b/go.mod index 8ac883df3aa..c9beac7c5b5 100644 --- a/go.mod +++ b/go.mod @@ -48,12 +48,12 @@ require ( github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 github.com/onflow/atree v0.8.0 - github.com/onflow/cadence v1.1.0 + github.com/onflow/cadence v1.2.1 github.com/onflow/crypto v0.25.2 github.com/onflow/flow v0.3.4 - github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 - github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 - github.com/onflow/flow-go-sdk v1.1.0 + github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 + github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 + github.com/onflow/flow-go-sdk v1.2.2 github.com/onflow/flow/protobuf/go/flow v0.4.7 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/pierrec/lz4 v2.6.1+incompatible diff --git a/go.sum b/go.sum index 79da2652571..036ed5849f6 100644 --- a/go.sum +++ b/go.sum @@ -913,22 +913,22 @@ github.com/onflow/atree v0.8.0 h1:qg5c6J1gVDNObughpEeWm8oxqhPGdEyGrda121GM4u0= github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo= github.com/onflow/boxo v0.0.0-20240201202436-f2477b92f483 h1:LpiQhTAfM9CAmNVEs0n//cBBgCg+vJSiIxTHYUklZ84= github.com/onflow/boxo v0.0.0-20240201202436-f2477b92f483/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80= -github.com/onflow/cadence v1.1.0 h1:wPg86IX1kRv6DWjdETxKa4tv6A3iAwJVzzKAwaGdtDA= -github.com/onflow/cadence v1.1.0/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= +github.com/onflow/cadence v1.2.1 h1:hmSsgX3rTsp2E5qTSl1JXINt8qepdRrHTwDSYqN5Nxs= +github.com/onflow/cadence v1.2.1/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= github.com/onflow/crypto v0.25.2 h1:GjHunqVt+vPcdqhxxhAXiMIF3YiLX7gTuTR5O+VG2ns= github.com/onflow/crypto v0.25.2/go.mod h1:fY7eLqUdMKV8EGOw301unP8h7PvLVy8/6gVR++/g0BY= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= github.com/onflow/flow v0.3.4/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 h1:My0EZLNXlzjN5tT81wD+wNb+PSqfOLJKHA1crXBNu5U= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 h1:YNHTonFhPSCuPJFYhIYZ1okSZmXEeQ07eKaoryrjHQI= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 h1:R86HaOuk6vpuECZnriEUE7bw9inC2AtdSn8lL/iwQLQ= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 h1:u2DAG8pk0xFH7TwS70t1gSZ/FtIIZWMSNyiu4SeXBYg= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3SsEftzXG2JlmSe24= github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM= github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE= -github.com/onflow/flow-go-sdk v1.1.0 h1:DT8P3B3oAicOOXugdev4s1IEKHsiLS9T7MovFcTzB2s= -github.com/onflow/flow-go-sdk v1.1.0/go.mod h1:21g1pqP9Wy8RBXdenNsjzADwbtWNOViUCnfNZwr3trM= +github.com/onflow/flow-go-sdk v1.2.2 h1:F78Sq/VaExgtaQv739k06gnx2aIyLF5wVE0XwxFpmsc= +github.com/onflow/flow-go-sdk v1.2.2/go.mod h1:yhQ5+Sp2xWoCQ1fuRDswawTDQ0ng0z5nTkFVH82xL7E= github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80mO1PzUJYPfdhXFsGbQ= github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE= diff --git a/insecure/go.mod b/insecure/go.mod index 33d8e855071..f6381343701 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -203,12 +203,12 @@ require ( github.com/nxadm/tail v1.4.8 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onflow/atree v0.8.0 // indirect - github.com/onflow/cadence v1.1.0 // indirect - github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 // indirect - github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 // indirect + github.com/onflow/cadence v1.2.1 // indirect + github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 // indirect + github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 // indirect github.com/onflow/flow-ft/lib/go/contracts v1.0.1 // indirect github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect - github.com/onflow/flow-go-sdk v1.1.0 // indirect + github.com/onflow/flow-go-sdk v1.2.2 // indirect github.com/onflow/flow-nft/lib/go/contracts v1.2.2 // indirect github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect diff --git a/insecure/go.sum b/insecure/go.sum index 27949c5063a..11976c45d95 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -856,20 +856,20 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.8.0 h1:qg5c6J1gVDNObughpEeWm8oxqhPGdEyGrda121GM4u0= github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo= -github.com/onflow/cadence v1.1.0 h1:wPg86IX1kRv6DWjdETxKa4tv6A3iAwJVzzKAwaGdtDA= -github.com/onflow/cadence v1.1.0/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= +github.com/onflow/cadence v1.2.1 h1:hmSsgX3rTsp2E5qTSl1JXINt8qepdRrHTwDSYqN5Nxs= +github.com/onflow/cadence v1.2.1/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= github.com/onflow/crypto v0.25.2 h1:GjHunqVt+vPcdqhxxhAXiMIF3YiLX7gTuTR5O+VG2ns= github.com/onflow/crypto v0.25.2/go.mod h1:fY7eLqUdMKV8EGOw301unP8h7PvLVy8/6gVR++/g0BY= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 h1:My0EZLNXlzjN5tT81wD+wNb+PSqfOLJKHA1crXBNu5U= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 h1:YNHTonFhPSCuPJFYhIYZ1okSZmXEeQ07eKaoryrjHQI= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 h1:R86HaOuk6vpuECZnriEUE7bw9inC2AtdSn8lL/iwQLQ= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 h1:u2DAG8pk0xFH7TwS70t1gSZ/FtIIZWMSNyiu4SeXBYg= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3SsEftzXG2JlmSe24= github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM= github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE= -github.com/onflow/flow-go-sdk v1.1.0 h1:DT8P3B3oAicOOXugdev4s1IEKHsiLS9T7MovFcTzB2s= -github.com/onflow/flow-go-sdk v1.1.0/go.mod h1:21g1pqP9Wy8RBXdenNsjzADwbtWNOViUCnfNZwr3trM= +github.com/onflow/flow-go-sdk v1.2.2 h1:F78Sq/VaExgtaQv739k06gnx2aIyLF5wVE0XwxFpmsc= +github.com/onflow/flow-go-sdk v1.2.2/go.mod h1:yhQ5+Sp2xWoCQ1fuRDswawTDQ0ng0z5nTkFVH82xL7E= github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80mO1PzUJYPfdhXFsGbQ= github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE= diff --git a/integration/benchmark/account/account_provider.go b/integration/benchmark/account/account_provider.go index cdbd743d025..d46ecd42dbe 100644 --- a/integration/benchmark/account/account_provider.go +++ b/integration/benchmark/account/account_provider.go @@ -10,9 +10,11 @@ import ( "golang.org/x/sync/errgroup" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/module/util" "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/fvm/blueprints" "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/integration/benchmark/common" diff --git a/integration/benchmark/contLoadGenerator.go b/integration/benchmark/contLoadGenerator.go index 2ca1cee974c..7f1c31562cf 100644 --- a/integration/benchmark/contLoadGenerator.go +++ b/integration/benchmark/contLoadGenerator.go @@ -12,6 +12,7 @@ import ( flowsdk "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/access" "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/integration/benchmark/account" "github.com/onflow/flow-go/integration/benchmark/common" diff --git a/integration/benchmark/follower.go b/integration/benchmark/follower.go index 746c5b17b40..0681570b491 100644 --- a/integration/benchmark/follower.go +++ b/integration/benchmark/follower.go @@ -10,6 +10,7 @@ import ( flowsdk "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/access" + "github.com/onflow/flow-go/module/metrics" "github.com/rs/zerolog" diff --git a/integration/benchmark/follower_test.go b/integration/benchmark/follower_test.go index 1b5b942e497..8ae218a6885 100644 --- a/integration/benchmark/follower_test.go +++ b/integration/benchmark/follower_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" flowsdk "github.com/onflow/flow-go-sdk" + mockClient "github.com/onflow/flow-go/integration/benchmark/mock" "github.com/onflow/flow-go/utils/unittest" ) diff --git a/integration/benchmark/load/common.go b/integration/benchmark/load/common.go index 93882d96757..4ce4e589fc8 100644 --- a/integration/benchmark/load/common.go +++ b/integration/benchmark/load/common.go @@ -7,6 +7,7 @@ import ( "github.com/rs/zerolog" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/integration/benchmark/common" "github.com/onflow/flow-go/integration/benchmark/account" diff --git a/integration/benchmark/load/simple_load.go b/integration/benchmark/load/simple_load.go index e10927d5493..b1b05cf9005 100644 --- a/integration/benchmark/load/simple_load.go +++ b/integration/benchmark/load/simple_load.go @@ -7,6 +7,7 @@ import ( "github.com/rs/zerolog" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/fvm/blueprints" "github.com/onflow/flow-go/integration/benchmark/account" ) diff --git a/integration/benchmark/load/token_transfer_load.go b/integration/benchmark/load/token_transfer_load.go index e382c58611f..703b013900b 100644 --- a/integration/benchmark/load/token_transfer_load.go +++ b/integration/benchmark/load/token_transfer_load.go @@ -5,6 +5,7 @@ import ( "github.com/rs/zerolog" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/fvm/errors" "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/integration/benchmark/account" diff --git a/integration/benchmark/load/token_transfer_multiple_load.go b/integration/benchmark/load/token_transfer_multiple_load.go index 3e7ab6930a1..05bd4d6ca5b 100644 --- a/integration/benchmark/load/token_transfer_multiple_load.go +++ b/integration/benchmark/load/token_transfer_multiple_load.go @@ -9,6 +9,7 @@ import ( "github.com/onflow/flow-go/model/flow" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/fvm/systemcontracts" "github.com/onflow/flow-go/integration/benchmark/account" "github.com/onflow/flow-go/integration/benchmark/scripts" diff --git a/integration/benchmark/scripts/scripts.go b/integration/benchmark/scripts/scripts.go index 105b5285c1f..b21b564ee20 100644 --- a/integration/benchmark/scripts/scripts.go +++ b/integration/benchmark/scripts/scripts.go @@ -8,6 +8,7 @@ import ( "github.com/onflow/cadence" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/model/flow" ) diff --git a/integration/dkg/node.go b/integration/dkg/node.go index cbea2b7f44a..5c16acba499 100644 --- a/integration/dkg/node.go +++ b/integration/dkg/node.go @@ -8,6 +8,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/engine/consensus/dkg" testmock "github.com/onflow/flow-go/engine/testutil/mock" "github.com/onflow/flow-go/model/bootstrap" diff --git a/integration/go.mod b/integration/go.mod index 8e5e807dc01..92956116a7e 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -20,13 +20,13 @@ require ( github.com/ipfs/go-ds-badger2 v0.1.3 github.com/ipfs/go-ds-pebble v0.3.1-0.20240828032824-d745b9d3200b github.com/libp2p/go-libp2p v0.32.2 - github.com/onflow/cadence v1.1.0 + github.com/onflow/cadence v1.2.1 github.com/onflow/crypto v0.25.2 - github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 - github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 - github.com/onflow/flow-emulator v1.0.2-0.20241018193523-2601797fe0f2 - github.com/onflow/flow-go v0.38.0-preview.0.0.20241018193026-4b778232480b - github.com/onflow/flow-go-sdk v1.1.0 + github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 + github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 + github.com/onflow/flow-emulator v1.0.2-0.20241021223526-a545558d37a2 + github.com/onflow/flow-go v0.38.0-preview.0.0.20241021221952-af9cd6e99de1 + github.com/onflow/flow-go-sdk v1.2.2 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 github.com/onflow/flow/protobuf/go/flow v0.4.7 github.com/onflow/go-ethereum v1.14.7 diff --git a/integration/go.sum b/integration/go.sum index 7033bc72121..7e114711f03 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -742,22 +742,22 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.8.0 h1:qg5c6J1gVDNObughpEeWm8oxqhPGdEyGrda121GM4u0= github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo= -github.com/onflow/cadence v1.1.0 h1:wPg86IX1kRv6DWjdETxKa4tv6A3iAwJVzzKAwaGdtDA= -github.com/onflow/cadence v1.1.0/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= +github.com/onflow/cadence v1.2.1 h1:hmSsgX3rTsp2E5qTSl1JXINt8qepdRrHTwDSYqN5Nxs= +github.com/onflow/cadence v1.2.1/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg= github.com/onflow/crypto v0.25.2 h1:GjHunqVt+vPcdqhxxhAXiMIF3YiLX7gTuTR5O+VG2ns= github.com/onflow/crypto v0.25.2/go.mod h1:fY7eLqUdMKV8EGOw301unP8h7PvLVy8/6gVR++/g0BY= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2 h1:My0EZLNXlzjN5tT81wD+wNb+PSqfOLJKHA1crXBNu5U= -github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2 h1:YNHTonFhPSCuPJFYhIYZ1okSZmXEeQ07eKaoryrjHQI= -github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= -github.com/onflow/flow-emulator v1.0.2-0.20241018193523-2601797fe0f2 h1:bCp07I6BKfDGu8CFiWS0OY7FiqELAZNbeZ2M70o1gXY= -github.com/onflow/flow-emulator v1.0.2-0.20241018193523-2601797fe0f2/go.mod h1:QMKsUPYQh4PPvSF3ryYzkbL6HzWAhoRr55FtbKCC5Jc= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0 h1:R86HaOuk6vpuECZnriEUE7bw9inC2AtdSn8lL/iwQLQ= +github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0/go.mod h1:9asTBnB6Tw2UlVVtQKyS/egYv3xr4zVlJnJ75z1dfac= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 h1:u2DAG8pk0xFH7TwS70t1gSZ/FtIIZWMSNyiu4SeXBYg= +github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= +github.com/onflow/flow-emulator v1.0.2-0.20241021223526-a545558d37a2 h1:zs3/ctgI1KNFTcA1HpkDmyNuUybY/oFXDE1S+cYR9lU= +github.com/onflow/flow-emulator v1.0.2-0.20241021223526-a545558d37a2/go.mod h1:HgcZT9TZVOqmNGqN3fX+QqoiVovIHfLwqbXwuaEJiXE= github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3SsEftzXG2JlmSe24= github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM= github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE= -github.com/onflow/flow-go-sdk v1.1.0 h1:DT8P3B3oAicOOXugdev4s1IEKHsiLS9T7MovFcTzB2s= -github.com/onflow/flow-go-sdk v1.1.0/go.mod h1:21g1pqP9Wy8RBXdenNsjzADwbtWNOViUCnfNZwr3trM= +github.com/onflow/flow-go-sdk v1.2.2 h1:F78Sq/VaExgtaQv739k06gnx2aIyLF5wVE0XwxFpmsc= +github.com/onflow/flow-go-sdk v1.2.2/go.mod h1:yhQ5+Sp2xWoCQ1fuRDswawTDQ0ng0z5nTkFVH82xL7E= github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80mO1PzUJYPfdhXFsGbQ= github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE= diff --git a/integration/localnet/builder/bootstrap.go b/integration/localnet/builder/bootstrap.go index 200926bf83a..e3ed2c91ea2 100644 --- a/integration/localnet/builder/bootstrap.go +++ b/integration/localnet/builder/bootstrap.go @@ -454,8 +454,8 @@ func prepareObserverService(i int, observerName string, agPublicKey string) Serv service := defaultService(observerName, DefaultObserverRole, dataDir, profilerDir, i) service.Command = append(service.Command, - fmt.Sprintf("--bootstrap-node-addresses=%s:%s", testnet.PrimaryAN, testnet.PublicNetworkPort), - fmt.Sprintf("--bootstrap-node-public-keys=%s", agPublicKey), + fmt.Sprintf("--observer-mode-bootstrap-node-addresses=%s:%s", testnet.PrimaryAN, testnet.PublicNetworkPort), + fmt.Sprintf("--observer-mode-bootstrap-node-public-keys=%s", agPublicKey), fmt.Sprintf("--upstream-node-addresses=%s:%s", testnet.PrimaryAN, testnet.GRPCSecurePort), fmt.Sprintf("--upstream-node-public-keys=%s", agPublicKey), fmt.Sprintf("--observer-networking-key-path=/bootstrap/private-root-information/%s_key", observerName), diff --git a/integration/testnet/network.go b/integration/testnet/network.go index bc5fdc2f48b..250e7eabe53 100644 --- a/integration/testnet/network.go +++ b/integration/testnet/network.go @@ -31,6 +31,7 @@ import ( "github.com/onflow/cadence" "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/cmd/bootstrap/dkg" "github.com/onflow/flow-go/cmd/bootstrap/run" "github.com/onflow/flow-go/cmd/bootstrap/utils" @@ -756,8 +757,8 @@ func (net *FlowNetwork) AddObserver(t *testing.T, conf ObserverConfig) *Containe fmt.Sprintf("--secretsdir=%s", DefaultFlowSecretsDBDir), fmt.Sprintf("--profiler-dir=%s", DefaultProfilerDir), fmt.Sprintf("--loglevel=%s", conf.LogLevel.String()), - fmt.Sprintf("--bootstrap-node-addresses=%s", accessNode.ContainerAddr(PublicNetworkPort)), - fmt.Sprintf("--bootstrap-node-public-keys=%s", accessPublicKey), + fmt.Sprintf("--observer-mode-bootstrap-node-addresses=%s", accessNode.ContainerAddr(PublicNetworkPort)), + fmt.Sprintf("--observer-mode-bootstrap-node-public-keys=%s", accessPublicKey), fmt.Sprintf("--upstream-node-addresses=%s", accessNode.ContainerAddr(GRPCSecurePort)), fmt.Sprintf("--upstream-node-public-keys=%s", accessPublicKey), fmt.Sprintf("--observer-networking-key-path=%s/private-root-information/%s_key", DefaultBootstrapDir, conf.ContainerName), diff --git a/integration/tests/access/cohort2/observer_indexer_enabled_test.go b/integration/tests/access/cohort2/observer_indexer_enabled_test.go index 43f784669bc..cc2709f9780 100644 --- a/integration/tests/access/cohort2/observer_indexer_enabled_test.go +++ b/integration/tests/access/cohort2/observer_indexer_enabled_test.go @@ -17,6 +17,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" "github.com/onflow/flow-go-sdk/templates" + "github.com/onflow/flow-go/engine/access/rpc/backend" "github.com/onflow/flow-go/engine/common/rpc/convert" "github.com/onflow/flow-go/integration/testnet" diff --git a/integration/tests/access/cohort3/access_circuit_breaker_test.go b/integration/tests/access/cohort3/access_circuit_breaker_test.go index 772a56e6c8c..8cb745bd569 100644 --- a/integration/tests/access/cohort3/access_circuit_breaker_test.go +++ b/integration/tests/access/cohort3/access_circuit_breaker_test.go @@ -16,6 +16,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" "github.com/onflow/flow-go-sdk/templates" + "github.com/onflow/flow-go/integration/testnet" "github.com/onflow/flow-go/integration/tests/lib" "github.com/onflow/flow-go/model/flow" diff --git a/integration/tests/collection/recovery_test.go b/integration/tests/collection/recovery_test.go index 6d1309df18c..d1812e83c7a 100644 --- a/integration/tests/collection/recovery_test.go +++ b/integration/tests/collection/recovery_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" client "github.com/onflow/flow-go-sdk/access/grpc" + "github.com/onflow/flow-go/integration/convert" "github.com/onflow/flow-go/model/flow" "github.com/onflow/flow-go/utils/unittest" diff --git a/integration/utils/emulator_client.go b/integration/utils/emulator_client.go index 8d42e1388fd..1af763e6cff 100644 --- a/integration/utils/emulator_client.go +++ b/integration/utils/emulator_client.go @@ -12,6 +12,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/templates" + "github.com/onflow/flow-go/model/flow" ) diff --git a/ledger/common/bitutils/utils_test.go b/ledger/common/bitutils/utils_test.go index d8f23dfd1a4..f168c058ffa 100644 --- a/ledger/common/bitutils/utils_test.go +++ b/ledger/common/bitutils/utils_test.go @@ -5,9 +5,8 @@ import ( "math/big" "math/bits" "math/rand" - "time" - "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/module/epochs/base_client.go b/module/epochs/base_client.go index 5b372d80141..a0b845fd19a 100644 --- a/module/epochs/base_client.go +++ b/module/epochs/base_client.go @@ -12,6 +12,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/network" "github.com/onflow/flow-go/module" diff --git a/module/epochs/qc_client.go b/module/epochs/qc_client.go index 8bdf32d6a57..4f891361063 100644 --- a/module/epochs/qc_client.go +++ b/module/epochs/qc_client.go @@ -13,6 +13,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" sdkcrypto "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/network" "github.com/onflow/flow-go/consensus/hotstuff/model" diff --git a/storage/badger/payloads_test.go b/storage/badger/payloads_test.go index cb11074f88b..d92a593526e 100644 --- a/storage/badger/payloads_test.go +++ b/storage/badger/payloads_test.go @@ -2,7 +2,6 @@ package badger_test import ( "errors" - "testing" "github.com/dgraph-io/badger/v2" diff --git a/utils/unittest/execution_state.go b/utils/unittest/execution_state.go index 425527670dc..7265fb895fa 100644 --- a/utils/unittest/execution_state.go +++ b/utils/unittest/execution_state.go @@ -23,7 +23,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256 const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256 // Pre-calculated state commitment with root account with the above private key -const GenesisStateCommitmentHex = "d2a7db1fa0cc1eee36e8769c11095fbaa440ab7916e5923afa10e760fd5eae2b" +const GenesisStateCommitmentHex = "b921d979dd58c55c43f8918cf653578697ec75d8cc2782a0c447b8ee0c39b544" var GenesisStateCommitment flow.StateCommitment @@ -87,10 +87,10 @@ func genesisCommitHexByChainID(chainID flow.ChainID) string { return GenesisStateCommitmentHex } if chainID == flow.Testnet { - return "719c12f8e28a40d822e43873d8a188daa7a3f81dc530c4c61f4141d76985bd46" + return "042170743acd6c7e8d14bb91b7296719cb61448c222a30163feb108d9994fd58" } if chainID == flow.Sandboxnet { return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1" } - return "5efd4c97fa23bd76769ab891a2681a839f8bdd0a2be0e07ab841f51b2e3a2f51" + return "c67d4b16a38b4bf0d9d5b6c5f75c55079af969b847538ceec87bc00af1c50516" } diff --git a/utils/unittest/fixtures.go b/utils/unittest/fixtures.go index 0bce5e99b41..9c3f9784493 100644 --- a/utils/unittest/fixtures.go +++ b/utils/unittest/fixtures.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/onflow/flow-go-sdk" + hotstuff "github.com/onflow/flow-go/consensus/hotstuff/model" "github.com/onflow/flow-go/engine" "github.com/onflow/flow-go/engine/access/rest/util"