Skip to content

Commit

Permalink
Merge pull request #5260 from onflow/supun/stable-cadence-sync
Browse files Browse the repository at this point in the history
Sync stable-cadence branch with master
  • Loading branch information
SupunS authored Jan 23, 2024
2 parents 7dca2e8 + 6806845 commit 5304857
Show file tree
Hide file tree
Showing 279 changed files with 13,917 additions and 6,514 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifeq (${IMAGE_TAG},)
IMAGE_TAG := ${SHORT_COMMIT}
endif

IMAGE_TAG_NO_NETGO := $(IMAGE_TAG)-without-netgo
IMAGE_TAG_NO_NETGO := $(IMAGE_TAG)+without-netgo

# Name of the cover profile
COVER_PROFILE := coverage.txt
Expand Down Expand Up @@ -207,11 +207,14 @@ generate-mocks: install-mock-generators
mockery --name '.*' --dir=./cmd/util/ledger/reporters --case=underscore --output="./cmd/util/ledger/reporters/mock" --outpkg="mock"
mockery --name 'Storage' --dir=module/executiondatasync/tracker --case=underscore --output="module/executiondatasync/tracker/mock" --outpkg="mocktracker"
mockery --name 'ScriptExecutor' --dir=module/execution --case=underscore --output="module/execution/mock" --outpkg="mock"
mockery --name 'StorageSnapshot' --dir=fvm/storage/snapshot --case=underscore --output="fvm/storage/snapshot/mock" --outpkg="mock"

#temporarily make insecure/ a non-module to allow mockery to create mocks
mv insecure/go.mod insecure/go2.mod
if [ -f go.work ]; then mv go.work go2.work; fi
mockery --name '.*' --dir=insecure/ --case=underscore --output="./insecure/mock" --outpkg="mockinsecure"
mv insecure/go2.mod insecure/go.mod
if [ -f go2.work ]; then mv go2.work go.work; fi

# this ensures there is no unused dependency being added by accident
.PHONY: tidy
Expand Down
67 changes: 54 additions & 13 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func DefaultAccessNodeConfig() *AccessNodeConfig {
MaxFailures: 5,
MaxRequests: 1,
},
ScriptExecutionMode: backend.ScriptExecutionModeExecutionNodesOnly.String(), // default to ENs only for now
ScriptExecutionMode: backend.IndexQueryModeExecutionNodesOnly.String(), // default to ENs only for now
EventQueryMode: backend.IndexQueryModeExecutionNodesOnly.String(), // default to ENs only for now
},
RestConfig: rest.Config{
ListenAddress: "",
Expand Down Expand Up @@ -273,6 +274,7 @@ type FlowAccessNodeBuilder struct {
ExecutionIndexerCore *indexer.IndexerCore
ScriptExecutor *backend.ScriptExecutor
RegistersAsyncStore *execution.RegistersAsyncStore
IndexerDependencies *cmd.DependencyList

// The sync engine participants provider is the libp2p peer store for the access node
// which is not available until after the network has started.
Expand Down Expand Up @@ -488,8 +490,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess

// setup dependency chain to ensure indexer starts after the requester
requesterDependable := module.NewProxiedReadyDoneAware()
indexerDependencies := cmd.NewDependencyList()
indexerDependencies.Add(requesterDependable)
builder.IndexerDependencies.Add(requesterDependable)

builder.
AdminCommand("read-execution-data", func(config *cmd.NodeConfig) commands.AdminCommand {
Expand Down Expand Up @@ -669,10 +670,6 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
indexedBlockHeight = bstorage.NewConsumerProgress(builder.DB, module.ConsumeProgressExecutionDataIndexerBlockHeight)
return nil
}).
Module("events storage", func(node *cmd.NodeConfig) error {
builder.Storage.Events = bstorage.NewEvents(node.Metrics.Cache, node.DB)
return nil
}).
Module("transaction results storage", func(node *cmd.NodeConfig) error {
builder.Storage.LightTransactionResults = bstorage.NewLightTransactionResults(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize)
return nil
Expand Down Expand Up @@ -716,14 +713,20 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess

checkpointHeight := builder.SealedRootBlock.Header.Height

buutstrap, err := pStorage.NewRegisterBootstrap(pdb, checkpointFile, checkpointHeight, builder.Logger)
if builder.SealedRootBlock.ID() != builder.RootSeal.BlockID {
return nil, fmt.Errorf("mismatching sealed root block and root seal: %v != %v",
builder.SealedRootBlock.ID(), builder.RootSeal.BlockID)
}

rootHash := ledger.RootHash(builder.RootSeal.FinalState)
bootstrap, err := pStorage.NewRegisterBootstrap(pdb, checkpointFile, checkpointHeight, rootHash, builder.Logger)
if err != nil {
return nil, fmt.Errorf("could not create registers bootstrapper: %w", err)
return nil, fmt.Errorf("could not create registers bootstrap: %w", err)
}

// TODO: find a way to hook a context up to this to allow a graceful shutdown
workerCount := 10
err = buutstrap.IndexCheckpointFile(context.Background(), workerCount)
err = bootstrap.IndexCheckpointFile(context.Background(), workerCount)
if err != nil {
return nil, fmt.Errorf("could not load checkpoint file: %w", err)
}
Expand All @@ -744,6 +747,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
builder.Storage.Headers,
builder.Storage.Events,
builder.Storage.LightTransactionResults,
builder.IngestEng.OnCollection,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -790,7 +794,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
builder.ScriptExecutor.InitReporter(builder.ExecutionIndexer, scripts)

return builder.ExecutionIndexer, nil
}, indexerDependencies)
}, builder.IndexerDependencies)
}

if builder.stateStreamConf.ListenAddr != "" {
Expand All @@ -813,19 +817,32 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
}
broadcaster := engine.NewBroadcaster()

eventQueryMode, err := backend.ParseIndexQueryMode(builder.rpcConf.BackendConfig.EventQueryMode)
if err != nil {
return nil, fmt.Errorf("could not parse event query mode: %w", err)
}

// use the events index for events if enabled and the node is configured to use it for
// regular event queries
useIndex := builder.executionDataIndexingEnabled &&
eventQueryMode != backend.IndexQueryModeExecutionNodesOnly

builder.stateStreamBackend, err = statestreambackend.New(
node.Logger,
builder.stateStreamConf,
node.State,
node.Storage.Headers,
node.Storage.Events,
node.Storage.Seals,
node.Storage.Results,
builder.ExecutionDataStore,
executionDataStoreCache,
broadcaster,
builder.executionDataConfig.InitialBlockHeight,
highestAvailableHeight,
builder.RegistersAsyncStore)
builder.RegistersAsyncStore,
useIndex,
)
if err != nil {
return nil, fmt.Errorf("could not create state stream backend: %w", err)
}
Expand Down Expand Up @@ -861,6 +878,7 @@ func FlowAccessNode(nodeBuilder *cmd.FlowNodeBuilder) *FlowAccessNodeBuilder {
AccessNodeConfig: DefaultAccessNodeConfig(),
FlowNodeBuilder: nodeBuilder,
FollowerDistributor: dist,
IndexerDependencies: cmd.NewDependencyList(),
}
}

Expand Down Expand Up @@ -1063,6 +1081,11 @@ func (builder *FlowAccessNodeBuilder) extraFlags() {
flags.StringVar(&builder.registersDBPath, "execution-state-dir", defaultConfig.registersDBPath, "directory to use for execution-state database")
flags.StringVar(&builder.checkpointFile, "execution-state-checkpoint", defaultConfig.checkpointFile, "execution-state checkpoint file")

flags.StringVar(&builder.rpcConf.BackendConfig.EventQueryMode,
"event-query-mode",
defaultConfig.rpcConf.BackendConfig.EventQueryMode,
"mode to use when querying events. one of [local-only, execution-nodes-only(default), failover]")

// Script Execution
flags.StringVar(&builder.rpcConf.BackendConfig.ScriptExecutionMode,
"script-execution-mode",
Expand Down Expand Up @@ -1259,6 +1282,9 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
builder.BuildExecutionSyncComponents()
}

ingestionDependable := module.NewProxiedReadyDoneAware()
builder.IndexerDependencies.Add(ingestionDependable)

builder.
BuildConsensusFollower().
Module("collection node client", func(node *cmd.NodeConfig) error {
Expand Down Expand Up @@ -1402,6 +1428,10 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
builder.RegistersAsyncStore = execution.NewRegistersAsyncStore()
return nil
}).
Module("events storage", func(node *cmd.NodeConfig) error {
builder.Storage.Events = bstorage.NewEvents(node.Metrics.Cache, node.DB)
return nil
}).
Component("RPC engine", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
config := builder.rpcConf
backendConfig := config.BackendConfig
Expand Down Expand Up @@ -1434,17 +1464,26 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
),
}

scriptExecMode, err := backend.ParseScriptExecutionMode(config.BackendConfig.ScriptExecutionMode)
scriptExecMode, err := backend.ParseIndexQueryMode(config.BackendConfig.ScriptExecutionMode)
if err != nil {
return nil, fmt.Errorf("could not parse script execution mode: %w", err)
}

eventQueryMode, err := backend.ParseIndexQueryMode(config.BackendConfig.EventQueryMode)
if err != nil {
return nil, fmt.Errorf("could not parse script execution mode: %w", err)
}
if eventQueryMode == backend.IndexQueryModeCompare {
return nil, fmt.Errorf("event query mode 'compare' is not supported")
}

nodeBackend, err := backend.New(backend.Params{
State: node.State,
CollectionRPC: builder.CollectionRPC,
HistoricalAccessNodes: builder.HistoricalAccessRPCs,
Blocks: node.Storage.Blocks,
Headers: node.Storage.Headers,
Events: node.Storage.Events,
Collections: node.Storage.Collections,
Transactions: node.Storage.Transactions,
ExecutionReceipts: node.Storage.Receipts,
Expand All @@ -1463,6 +1502,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
TxErrorMessagesCacheSize: builder.TxErrorMessagesCacheSize,
ScriptExecutor: builder.ScriptExecutor,
ScriptExecutionMode: scriptExecMode,
EventQueryMode: eventQueryMode,
})
if err != nil {
return nil, fmt.Errorf("could not initialize backend: %w", err)
Expand Down Expand Up @@ -1535,6 +1575,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
if err != nil {
return nil, err
}
ingestionDependable.Init(builder.IngestEng)
builder.RequestEng.WithHandle(builder.IngestEng.OnCollection)
builder.FollowerDistributor.AddOnBlockFinalizedConsumer(builder.IngestEng.OnFinalizedBlock)

Expand Down
5 changes: 2 additions & 3 deletions cmd/bootstrap/cmd/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/encodable"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/epochs"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/state/protocol/badger"
Expand Down Expand Up @@ -156,7 +155,7 @@ func finalize(cmd *cobra.Command, args []string) {
log.Info().Msg("")

// create flow.IdentityList representation of participant set
participants := model.ToIdentityList(stakingNodes).Sort(order.Canonical)
participants := model.ToIdentityList(stakingNodes).Sort(flow.Canonical)

log.Info().Msg("reading root block data")
block := readRootBlock()
Expand Down Expand Up @@ -492,7 +491,7 @@ func mergeNodeInfos(internalNodes, partnerNodes []model.NodeInfo) []model.NodeIn
}

// sort nodes using the canonical ordering
nodes = model.Sort(nodes, order.Canonical)
nodes = model.Sort(nodes, flow.Canonical)

return nodes
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/bootstrap/cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/onflow/flow-go/crypto/hash"

"github.com/onflow/flow-go/cmd/bootstrap/utils"
"github.com/onflow/flow-go/model/flow/order"

"github.com/onflow/flow-go/crypto"

Expand Down Expand Up @@ -49,7 +48,7 @@ func genNetworkAndStakingKeys() []model.NodeInfo {
internalNodes = append(internalNodes, nodeInfo)
}

return model.Sort(internalNodes, order.Canonical)
return model.Sort(internalNodes, flow.Canonical)
}

func assembleNodeInfo(nodeConfig model.NodeConfig, networkKey, stakingKey crypto.PrivateKey) model.NodeInfo {
Expand Down
3 changes: 1 addition & 2 deletions cmd/bootstrap/cmd/seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/onflow/flow-go/cmd/bootstrap/run"
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/signature"
)

Expand Down Expand Up @@ -39,7 +38,7 @@ func constructRootResultAndSeal(
DKGPhase1FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase - 1,
DKGPhase2FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*2 - 1,
DKGPhase3FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*3 - 1,
Participants: participants.Sort(order.Canonical),
Participants: participants.Sort(flow.Canonical),
Assignments: assignments,
RandomSource: GenerateRandomSeed(flow.EpochSetupRandomSourceLength),
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/bootstrap/run/cluster_qc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/cluster"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/local"
)

Expand All @@ -29,7 +28,7 @@ func GenerateClusterRootQC(signers []bootstrap.NodeInfo, allCommitteeMembers flo
}

// STEP 2: create VoteProcessor
ordered := allCommitteeMembers.Sort(order.Canonical)
ordered := allCommitteeMembers.Sort(flow.Canonical)
committee, err := committees.NewStaticCommittee(ordered, flow.Identifier{}, nil, nil)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions cmd/bootstrap/run/qc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/signature"
"github.com/onflow/flow-go/utils/unittest"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func TestGenerateRootQCWithSomeInvalidVotes(t *testing.T) {
}

func createSignerData(t *testing.T, n int) *ParticipantData {
identities := unittest.IdentityListFixture(n).Sort(order.Canonical)
identities := unittest.IdentityListFixture(n).Sort(flow.Canonical)

networkingKeys := unittest.NetworkingKeys(n)
stakingKeys := unittest.StakingKeys(n)
Expand Down
5 changes: 0 additions & 5 deletions cmd/consensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func main() {
requiredApprovalsForSealVerification uint
requiredApprovalsForSealConstruction uint
emergencySealing bool
dkgControllerConfig dkgmodule.ControllerConfig
dkgMessagingEngineConfig = dkgeng.DefaultMessagingEngineConfig()
cruiseCtlConfig = cruisectl.DefaultConfig()
cruiseCtlTargetTransitionTimeFlag = cruiseCtlConfig.TargetTransition.String()
Expand Down Expand Up @@ -161,9 +160,6 @@ func main() {
flags.BoolVar(&emergencySealing, "emergency-sealing-active", flow.DefaultEmergencySealingActive, "(de)activation of emergency sealing")
flags.BoolVar(&insecureAccessAPI, "insecure-access-api", false, "required if insecure GRPC connection should be used")
flags.StringSliceVar(&accessNodeIDS, "access-node-ids", []string{}, fmt.Sprintf("array of access node IDs sorted in priority order where the first ID in this array will get the first connection attempt and each subsequent ID after serves as a fallback. Minimum length %d. Use '*' for all IDs in protocol state.", common.DefaultAccessNodeIDSMinimum))
flags.DurationVar(&dkgControllerConfig.BaseStartDelay, "dkg-controller-base-start-delay", dkgmodule.DefaultBaseStartDelay, "used to define the range for jitter prior to DKG start (eg. 500µs) - the base value is scaled quadratically with the # of DKG participants")
flags.DurationVar(&dkgControllerConfig.BaseHandleFirstBroadcastDelay, "dkg-controller-base-handle-first-broadcast-delay", dkgmodule.DefaultBaseHandleFirstBroadcastDelay, "used to define the range for jitter prior to DKG handling the first broadcast messages (eg. 50ms) - the base value is scaled quadratically with the # of DKG participants")
flags.DurationVar(&dkgControllerConfig.HandleSubsequentBroadcastDelay, "dkg-controller-handle-subsequent-broadcast-delay", dkgmodule.DefaultHandleSubsequentBroadcastDelay, "used to define the constant delay introduced prior to DKG handling subsequent broadcast messages (eg. 2s)")
flags.DurationVar(&dkgMessagingEngineConfig.RetryBaseWait, "dkg-messaging-engine-retry-base-wait", dkgMessagingEngineConfig.RetryBaseWait, "the inter-attempt wait time for the first attempt (base of exponential retry)")
flags.Uint64Var(&dkgMessagingEngineConfig.RetryMax, "dkg-messaging-engine-retry-max", dkgMessagingEngineConfig.RetryMax, "the maximum number of retry attempts for an outbound DKG message")
flags.Uint64Var(&dkgMessagingEngineConfig.RetryJitterPercent, "dkg-messaging-engine-retry-jitter-percent", dkgMessagingEngineConfig.RetryJitterPercent, "the percentage of jitter to apply to each inter-attempt wait time")
Expand Down Expand Up @@ -915,7 +911,6 @@ func main() {
node.Me,
dkgContractClients,
dkgBrokerTunnel,
dkgControllerConfig,
),
viewsObserver,
)
Expand Down
Loading

0 comments on commit 5304857

Please sign in to comment.