cmd

package
v0.26.16-access-txresu... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2022 License: AGPL-3.0 Imports: 123 Imported by: 13

Documentation

Index

Constants

View Source
const (
	NetworkComponent        = "network"
	ConduitFactoryComponent = "conduit-factory"
)
View Source
const NotSet = "not set"

Variables

This section is empty.

Functions

func DynamicStartPreInit added in v0.23.9

func DynamicStartPreInit(nodeConfig *NodeConfig) error

DynamicStartPreInit is the pre-init func that will check if a node has already bootstrapped from a root protocol snapshot. If not attempt to get a protocol snapshot where the following conditions are met. 1. Target epoch < current epoch (in the past), set root snapshot to current snapshot 2. Target epoch == "current", wait until target phase == current phase before setting root snapshot 3. Target epoch > current epoch (in future), wait until target epoch and target phase is reached before setting root snapshot

func GetSnapshot added in v0.23.9

func GetSnapshot(ctx context.Context, client *client.Client) (*inmem.Snapshot, error)

GetSnapshot will attempt to get the latest finalized protocol snapshot with the given flow configs

func GetSnapshotAtEpochAndPhase added in v0.23.9

func GetSnapshotAtEpochAndPhase(ctx context.Context, log zerolog.Logger, startupEpoch uint64, startupEpochPhase flow.EpochPhase, retryInterval time.Duration, getSnapshot GetProtocolSnapshot) (protocol.Snapshot, error)

GetSnapshotAtEpochAndPhase will get the latest finalized protocol snapshot and check the current epoch and epoch phase. If we are past the target epoch and epoch phase we exit the retry mechanism immediately. If not check the snapshot at the specified interval until we reach the target epoch and phase.

func LoadNodeMachineAccountInfoFile added in v0.20.0

func LoadNodeMachineAccountInfoFile(bootstrapDir string, nodeID flow.Identifier) (*bootstrap.NodeMachineAccountInfo, error)

LoadNodeMachineAccountInfoFile loads machine account info from the default location within the bootstrap directory - Currently being used by Collection and Consensus nodes

func LoadPrivateNodeInfo added in v0.22.8

func LoadPrivateNodeInfo(dir string, myID flow.Identifier) (*bootstrap.NodeInfoPriv, error)

Loads the private info for this node from disk (eg. private staking/network keys).

func MarkFlagRequired added in v0.22.0

func MarkFlagRequired(command *cobra.Command, flagName string)

MarkFlagRequired marks a flag added to a cobra command as required. Panics if the flag has not been added to the cobra command (indicates misconfiguration or typo).

func ValidateDynamicStartupFlags added in v0.23.9

func ValidateDynamicStartupFlags(accessPublicKey, accessAddress string, startPhase flow.EpochPhase) error

ValidateDynamicStartupFlags will validate flags necessary for dynamic node startup - assert dynamic-startup-access-publickey is valid ECDSA_P256 public key hex - assert dynamic-startup-access-address is not empty - assert dynamic-startup-startup-epoch-phase is > 0 (EpochPhaseUndefined)

Types

type BaseConfig

type BaseConfig struct {
	AdminAddr                   string
	AdminCert                   string
	AdminKey                    string
	AdminClientCAs              string
	BindAddr                    string
	NodeRole                    string
	DynamicStartupANAddress     string
	DynamicStartupANPubkey      string
	DynamicStartupEpochPhase    string
	DynamicStartupEpoch         string
	DynamicStartupSleepInterval time.Duration

	InsecureSecretsDB bool

	BootstrapDir          string
	PeerUpdateInterval    time.Duration
	UnicastMessageTimeout time.Duration
	DNSCacheTTL           time.Duration

	MetricsEnabled bool

	PreferredUnicastProtocols       []string
	NetworkReceivedMessageCacheSize uint32
	TopologyProtocolName            string
	TopologyEdgeProbability         float64
	HeroCacheMetricsEnable          bool
	SyncCoreConfig                  synchronization.Config
	CodecFactory                    func() network.Codec
	// ComplianceConfig configures either the compliance engine (consensus nodes)
	// or the follower engine (all other node roles)
	ComplianceConfig compliance.Config
	// contains filtered or unexported fields
}

BaseConfig is the general config for the NodeBuilder and the command line params 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.

func DefaultBaseConfig added in v0.21.0

func DefaultBaseConfig() *BaseConfig

type BuilderFunc added in v0.23.9

type BuilderFunc func(nodeConfig *NodeConfig) error

type ExecutionConfig added in v0.26.0

type ExecutionConfig struct {
	// contains filtered or unexported fields
}

type ExecutionNodeBuilder added in v0.26.0

type ExecutionNodeBuilder struct {
	*FlowNodeBuilder
	// contains filtered or unexported fields
}

func NewExecutionNodeBuilder added in v0.26.0

func NewExecutionNodeBuilder(nodeBuilder *FlowNodeBuilder) *ExecutionNodeBuilder

func (*ExecutionNodeBuilder) LoadComponentsAndModules added in v0.26.0

func (e *ExecutionNodeBuilder) LoadComponentsAndModules()

func (*ExecutionNodeBuilder) LoadFlags added in v0.26.0

func (e *ExecutionNodeBuilder) LoadFlags()

type FlowNodeBuilder

type FlowNodeBuilder struct {
	*NodeConfig
	// contains filtered or unexported fields
}

FlowNodeBuilder is the default builder struct used for all flow nodes It runs a node process with following structure, in sequential order Base inits (network, storage, state, logger)

PostInit handlers, if any

Components handlers, if any, wait sequentially Run() <- main loop Components destructors, if any The initialization can be proceeded and succeeded with PreInit and PostInit functions that allow customization of the process in case of nodes such as the unstaked access node where the NodeInfo is not part of the genesis data

func FlowNode

func FlowNode(role string, opts ...Option) *FlowNodeBuilder

FlowNode creates a new Flow node builder with the given name.

func (*FlowNodeBuilder) AdminCommand added in v0.22.0

func (fnb *FlowNodeBuilder) AdminCommand(command string, f func(config *NodeConfig) commands.AdminCommand) NodeBuilder

func (*FlowNodeBuilder) BaseFlags added in v0.20.0

func (fnb *FlowNodeBuilder) BaseFlags()

func (*FlowNodeBuilder) Build added in v0.23.9

func (fnb *FlowNodeBuilder) Build() (Node, error)

func (*FlowNodeBuilder) Component

func (fnb *FlowNodeBuilder) Component(name string, f ReadyDoneFactory) NodeBuilder

Component adds a new component to the node that conforms to the ReadyDoneAware interface.

The ReadyDoneFactory may return either a `Component` or `ReadyDoneAware` instance. In both cases, the object is started when the node is run, and the node will wait for the component to exit gracefully.

func (*FlowNodeBuilder) EnqueueAdminServerInit added in v0.22.0

func (fnb *FlowNodeBuilder) EnqueueAdminServerInit()

func (*FlowNodeBuilder) EnqueueMetricsServerInit added in v0.20.0

func (fnb *FlowNodeBuilder) EnqueueMetricsServerInit()

func (*FlowNodeBuilder) EnqueueNetworkInit added in v0.20.0

func (fnb *FlowNodeBuilder) EnqueueNetworkInit()

func (*FlowNodeBuilder) EnqueuePingService added in v0.23.9

func (fnb *FlowNodeBuilder) EnqueuePingService()

func (*FlowNodeBuilder) EnqueueResolver added in v0.23.9

func (fnb *FlowNodeBuilder) EnqueueResolver()

func (*FlowNodeBuilder) EnqueueTracer added in v0.20.0

func (fnb *FlowNodeBuilder) EnqueueTracer()

func (*FlowNodeBuilder) ExtraFlags

func (fnb *FlowNodeBuilder) ExtraFlags(f func(*pflag.FlagSet)) NodeBuilder

ExtraFlags enables binding additional flags beyond those defined in BaseConfig.

func (*FlowNodeBuilder) InitFlowNetworkWithConduitFactory added in v0.26.0

func (fnb *FlowNodeBuilder) InitFlowNetworkWithConduitFactory(node *NodeConfig, cf network.ConduitFactory) (network.Network, error)

func (*FlowNodeBuilder) InitIDProviders added in v0.21.1

func (fnb *FlowNodeBuilder) InitIDProviders()

func (*FlowNodeBuilder) Initialize added in v0.20.0

func (fnb *FlowNodeBuilder) Initialize() error

func (*FlowNodeBuilder) Module

func (fnb *FlowNodeBuilder) Module(name string, f BuilderFunc) NodeBuilder

Module enables setting up dependencies of the engine with the builder context.

func (*FlowNodeBuilder) MustNot

func (fnb *FlowNodeBuilder) MustNot(err error) *zerolog.Event

MustNot asserts that the given error must not occur.

If the error is nil, returns a nil log event (which acts as a no-op). If the error is not nil, returns a fatal log event containing the error.

func (*FlowNodeBuilder) OverrideComponent added in v0.26.0

func (fnb *FlowNodeBuilder) OverrideComponent(name string, f ReadyDoneFactory) NodeBuilder

OverrideComponent adds given builder function to the components set of the node builder. If a builder function with that name already exists, it will be overridden.

func (*FlowNodeBuilder) ParseAndPrintFlags added in v0.20.0

func (fnb *FlowNodeBuilder) ParseAndPrintFlags() error

func (*FlowNodeBuilder) PostInit

func (fnb *FlowNodeBuilder) PostInit(f BuilderFunc) NodeBuilder

func (*FlowNodeBuilder) PreInit added in v0.20.0

func (fnb *FlowNodeBuilder) PreInit(f BuilderFunc) NodeBuilder

func (*FlowNodeBuilder) PrintBuildVersionDetails added in v0.20.0

func (fnb *FlowNodeBuilder) PrintBuildVersionDetails()

func (*FlowNodeBuilder) RegisterBadgerMetrics added in v0.20.0

func (fnb *FlowNodeBuilder) RegisterBadgerMetrics() error

func (*FlowNodeBuilder) RegisterDefaultAdminCommands added in v0.23.0

func (fnb *FlowNodeBuilder) RegisterDefaultAdminCommands()

func (*FlowNodeBuilder) RestartableComponent added in v0.26.2

func (fnb *FlowNodeBuilder) RestartableComponent(name string, f ReadyDoneFactory, errorHandler component.OnError) NodeBuilder

RestartableComponent adds a new component to the node that conforms to the ReadyDoneAware interface, and calls the provided error handler when an irrecoverable error is encountered. Use RestartableComponent if the component is not critical to the node's safe operation and can/should be independently restarted when an irrecoverable error is encountered.

IMPORTANT: Since a RestartableComponent can be restarted independently of the node, the node and other components must not rely on it for safe operation, and failures must be handled gracefully. As such, RestartableComponents do not block the node from becoming ready, and do not block subsequent components from starting serially. They do start in serial order.

Note: The ReadyDoneFactory method may be called multiple times if the component is restarted.

Any irrecoverable errors thrown by the component will be passed to the provided error handler.

func (*FlowNodeBuilder) ShutdownFunc added in v0.23.9

func (fnb *FlowNodeBuilder) ShutdownFunc(fn func() error) NodeBuilder

ShutdownFunc adds a callback function that is called after all components have exited.

func (*FlowNodeBuilder) ValidateFlags added in v0.20.6

func (fnb *FlowNodeBuilder) ValidateFlags(f func() error) NodeBuilder

type FlowNodeImp added in v0.23.9

type FlowNodeImp struct {
	component.Component
	*NodeConfig
	// contains filtered or unexported fields
}

FlowNodeImp is created by the FlowNodeBuilder with all components ready to be started. The Run function starts all the components, and is blocked until either a termination signal is received or a irrecoverable error is encountered.

func (*FlowNodeImp) Run added in v0.23.9

func (node *FlowNodeImp) Run()

Run starts all the node's components, then blocks until a SIGINT or SIGTERM is received, at which point it gracefully shuts down. Any unhandled irrecoverable errors thrown in child components will propagate up to here and result in a fatal error.

type GetProtocolSnapshot added in v0.23.9

type GetProtocolSnapshot func(ctx context.Context) (protocol.Snapshot, error)

GetProtocolSnapshot callback that will get latest finalized protocol snapshot

type Metrics

type Metrics struct {
	Network        module.NetworkMetrics
	Engine         module.EngineMetrics
	Compliance     module.ComplianceMetrics
	Cache          module.CacheMetrics
	Mempool        module.MempoolMetrics
	CleanCollector module.CleanerMetrics
}

type Node added in v0.23.9

type Node interface {
	component.Component

	// Run initiates all common components (logger, database, protocol state etc.)
	// then starts each component. It also sets up a channel to gracefully shut
	// down each component if a SIGINT is received.
	Run()
}

func NewNode added in v0.23.9

func NewNode(component component.Component, cfg *NodeConfig, logger zerolog.Logger, cleanup func() error, handleFatal func(error)) Node

NewNode returns a new node instance

type NodeBuilder added in v0.20.0

type NodeBuilder interface {
	// BaseFlags reads the command line arguments common to all nodes
	BaseFlags()

	// ExtraFlags reads the node specific command line arguments and adds it to the FlagSet
	ExtraFlags(f func(*pflag.FlagSet)) NodeBuilder

	// ParseAndPrintFlags parses and validates all the command line arguments
	ParseAndPrintFlags() error

	// Initialize performs all the initialization needed at the very start of a node
	Initialize() error

	// PrintBuildVersionDetails prints the node software build version
	PrintBuildVersionDetails()

	// InitIDProviders initializes the ID providers needed by various components
	InitIDProviders()

	// EnqueueNetworkInit enqueues the default networking layer.
	EnqueueNetworkInit()

	// EnqueueMetricsServerInit enqueues the metrics component.
	EnqueueMetricsServerInit()

	// EnqueueTracer enqueues the Tracer component.
	EnqueueTracer()

	// Module enables setting up dependencies of the engine with the builder context
	Module(name string, f BuilderFunc) NodeBuilder

	// Component adds a new component to the node that conforms to the ReadyDoneAware
	// interface, and throws a Fatal() when an irrecoverable error is encountered.
	//
	// The ReadyDoneFactory may return either a `Component` or `ReadyDoneAware` instance.
	// In both cases, the object is started according to its interface when the node is run,
	// and the node will wait for the component to exit gracefully.
	Component(name string, f ReadyDoneFactory) NodeBuilder

	// RestartableComponent adds a new component to the node that conforms to the ReadyDoneAware
	// interface, and calls the provided error handler when an irrecoverable error is encountered.
	// Use RestartableComponent if the component is not critical to the node's safe operation and
	// can/should be independently restarted when an irrecoverable error is encountered.
	//
	// Any irrecoverable errors thrown by the component will be passed to the provided error handler.
	RestartableComponent(name string, f ReadyDoneFactory, errorHandler component.OnError) NodeBuilder

	// ShutdownFunc adds a callback function that is called after all components have exited.
	// All shutdown functions are called regardless of errors returned by previous callbacks. Any
	// errors returned are captured and passed to the caller.
	ShutdownFunc(fn func() error) NodeBuilder

	// AdminCommand registers a new admin command with the admin server
	AdminCommand(command string, f func(config *NodeConfig) commands.AdminCommand) NodeBuilder

	// MustNot asserts that the given error must not occur.
	// If the error is nil, returns a nil log event (which acts as a no-op).
	// If the error is not nil, returns a fatal log event containing the error.
	MustNot(err error) *zerolog.Event

	// Build finalizes the node configuration in preparation for start and returns a Node
	// object that can be run
	Build() (Node, error)

	// PreInit registers a new PreInit function.
	// PreInit functions run before the protocol state is initialized or any other modules or components are initialized
	PreInit(f BuilderFunc) NodeBuilder

	// PostInit registers a new PreInit function.
	// PostInit functions run after the protocol state has been initialized but before any other modules or components
	// are initialized
	PostInit(f BuilderFunc) NodeBuilder

	// RegisterBadgerMetrics registers all badger related metrics
	RegisterBadgerMetrics() error

	// ValidateFlags sets any custom validation rules for the command line flags,
	// for example where certain combinations aren't allowed
	ValidateFlags(func() error) NodeBuilder
}

NodeBuilder declares the initialization methods needed to bootstrap up a Flow node

type NodeConfig added in v0.20.0

type NodeConfig struct {
	Cancel context.CancelFunc // cancel function for the context that is passed to the networking layer
	BaseConfig
	Logger            zerolog.Logger
	NodeID            flow.Identifier
	Me                module.Local
	Tracer            module.Tracer
	MetricsRegisterer prometheus.Registerer
	Metrics           Metrics
	DB                *badger.DB
	SecretsDB         *badger.DB
	Storage           Storage
	ProtocolEvents    *events.Distributor
	State             protocol.State
	Resolver          madns.BasicResolver
	Middleware        network.Middleware
	Network           network.Network
	ConduitFactory    network.ConduitFactory
	PingService       network.PingService
	MsgValidators     []network.MessageValidator
	FvmOptions        []fvm.Option
	StakingKey        crypto.PrivateKey
	NetworkKey        crypto.PrivateKey

	// ID providers
	IdentityProvider             id.IdentityProvider
	IDTranslator                 p2p.IDTranslator
	SyncEngineIdentifierProvider id.IdentifierProvider

	// root state information
	RootSnapshot protocol.Snapshot
	// cached properties of RootSnapshot for convenience
	RootBlock   *flow.Block
	RootQC      *flow.QuorumCertificate
	RootResult  *flow.ExecutionResult
	RootSeal    *flow.Seal
	RootChainID flow.ChainID
	SporkID     flow.Identifier

	// bootstrapping options
	SkipNwAddressBasedValidations bool
}

NodeConfig contains all the derived parameters such the NodeID, private keys etc. and initialized instances of structs such as DB, Network etc. The NodeConfig is composed of the BaseConfig and is updated in the NodeBuilder functions as a node is bootstrapped.

type Option added in v0.21.0

type Option func(*BaseConfig)

func WithBindAddress added in v0.21.1

func WithBindAddress(bindAddress string) Option

func WithBootstrapDir added in v0.21.0

func WithBootstrapDir(bootstrapDir string) Option

func WithComplianceConfig added in v0.26.16

func WithComplianceConfig(complianceConfig compliance.Config) Option

func WithDB added in v0.21.1

func WithDB(db *badger.DB) Option

WithDB takes precedence over WithDataDir and datadir will be set to empty if DB is set using this option

func WithDataDir added in v0.21.0

func WithDataDir(dataDir string) Option

func WithLogLevel added in v0.21.1

func WithLogLevel(level string) Option

func WithMetricsEnabled added in v0.21.0

func WithMetricsEnabled(enabled bool) Option

func WithSecretsDBEnabled added in v0.22.4

func WithSecretsDBEnabled(enabled bool) Option

func WithSyncCoreConfig added in v0.26.0

func WithSyncCoreConfig(syncConfig synchronization.Config) Option

type ReadyDoneFactory added in v0.23.9

type ReadyDoneFactory func(node *NodeConfig) (module.ReadyDoneAware, error)

type Storage

type Storage = storage.All

type VerificationConfig added in v0.26.0

type VerificationConfig struct {
	// contains filtered or unexported fields
}

type VerificationNodeBuilder added in v0.26.0

type VerificationNodeBuilder struct {
	*FlowNodeBuilder
	// contains filtered or unexported fields
}

func NewVerificationNodeBuilder added in v0.26.0

func NewVerificationNodeBuilder(nodeBuilder *FlowNodeBuilder) *VerificationNodeBuilder

func (*VerificationNodeBuilder) LoadComponentsAndModules added in v0.26.0

func (v *VerificationNodeBuilder) LoadComponentsAndModules()

func (*VerificationNodeBuilder) LoadFlags added in v0.26.0

func (v *VerificationNodeBuilder) LoadFlags()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL