operator

package
v0.5.5-jatov2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StartNodeCmd = &cobra.Command{
	Use:   "start-node",
	Short: "Starts an instance of SSV node",
	Run: func(cmd *cobra.Command, args []string) {
		logger, err := setupGlobal(cmd)
		if err != nil {
			log.Fatal("could not create logger", err)
		}

		defer logging.CapturePanic(logger)

		networkConfig, forkVersion, err := setupSSVNetwork(logger)
		if err != nil {
			log.Fatal("could not setup network", err)
		}

		cfg.DBOptions.Ctx = cmd.Context()
		db, err := setupDb(logger, networkConfig.Beacon)
		if err != nil {
			logger.Fatal("could not setup db", zap.Error(err))
		}
		nodeStorage, operatorData := setupOperatorStorage(logger, db)

		keyManager, err := ekm.NewETHKeyManagerSigner(logger, db, networkConfig, cfg.SSVOptions.ValidatorOptions.BuilderProposals)
		if err != nil {
			logger.Fatal("could not create new eth-key-manager signer", zap.Error(err))
		}

		cfg.P2pNetworkConfig.Ctx = cmd.Context()

		permissioned := func() bool {
			currentEpoch := uint64(networkConfig.Beacon.EstimatedCurrentEpoch())
			return currentEpoch >= cfg.P2pNetworkConfig.PermissionedActivateEpoch && currentEpoch < cfg.P2pNetworkConfig.PermissionedDeactivateEpoch
		}

		cfg.P2pNetworkConfig.Permissioned = permissioned
		cfg.P2pNetworkConfig.WhitelistedOperatorKeys = append(cfg.P2pNetworkConfig.WhitelistedOperatorKeys, networkConfig.WhitelistedOperatorKeys...)

		p2pNetwork := setupP2P(forkVersion, operatorData, db, logger, networkConfig)

		ctx := cmd.Context()
		slotTicker := slot_ticker.NewTicker(ctx, networkConfig)

		cfg.ETH2Options.Context = cmd.Context()
		eth2Client, eth1Client := setupNodes(logger, operatorData.ID, networkConfig, slotTicker)

		nodeChecker := nodeprobe.NewProber(
			logger,
			eth1Client,

			eth2Client.(nodeprobe.StatusChecker),
		)

		nodeChecker.Start(ctx)

		cfg.SSVOptions.ForkVersion = forkVersion
		cfg.SSVOptions.Context = ctx
		cfg.SSVOptions.DB = db
		cfg.SSVOptions.BeaconNode = eth2Client
		cfg.SSVOptions.Eth1Client = eth1Client
		cfg.SSVOptions.Network = networkConfig
		cfg.SSVOptions.P2PNetwork = p2pNetwork
		cfg.SSVOptions.ValidatorOptions.ForkVersion = forkVersion
		cfg.SSVOptions.ValidatorOptions.BeaconNetwork = networkConfig.Beacon
		cfg.SSVOptions.ValidatorOptions.Context = ctx
		cfg.SSVOptions.ValidatorOptions.DB = db
		cfg.SSVOptions.ValidatorOptions.Network = p2pNetwork
		cfg.SSVOptions.ValidatorOptions.KeyManager = keyManager
		cfg.SSVOptions.ValidatorOptions.Beacon = eth2Client

		cfg.SSVOptions.ValidatorOptions.ShareEncryptionKeyProvider = nodeStorage.GetPrivateKey
		cfg.SSVOptions.ValidatorOptions.OperatorData = operatorData
		cfg.SSVOptions.ValidatorOptions.RegistryStorage = nodeStorage
		cfg.SSVOptions.ValidatorOptions.GasLimit = cfg.ETH2Options.GasLimit

		if cfg.WsAPIPort != 0 {
			ws := exporterapi.NewWsServer(cmd.Context(), nil, http.NewServeMux(), cfg.WithPing)
			cfg.SSVOptions.WS = ws
			cfg.SSVOptions.WsAPIPort = cfg.WsAPIPort
			cfg.SSVOptions.ValidatorOptions.NewDecidedHandler = decided.NewStreamPublisher(logger, ws)
		}

		cfg.SSVOptions.ValidatorOptions.DutyRoles = []spectypes.BeaconRole{spectypes.BNRoleAttester}
		validatorCtrl := validator.NewController(logger, cfg.SSVOptions.ValidatorOptions)
		cfg.SSVOptions.ValidatorController = validatorCtrl

		operatorNode = operator.New(logger, cfg.SSVOptions, slotTicker)

		if cfg.MetricsAPIPort > 0 {
			go startMetricsHandler(cmd.Context(), logger, db, cfg.MetricsAPIPort, cfg.EnableProfile)
		}

		nodeChecker.Wait()

		nodeUnreadyHandler := func() {
			logger.Fatal("Ethereum node(s) are either out of sync or down. Ensure the nodes are ready to resume.")
		}
		nodeChecker.SetUnreadyHandler(nodeUnreadyHandler)

		metrics.ReportSSVNodeHealthiness(true)

		if len(cfg.LocalEventsPath) > 0 {
			if err := validator.LoadLocalEvents(
				logger,
				validatorCtrl.Eth1EventHandler(logger, false),
				cfg.LocalEventsPath,
			); err != nil {
				logger.Fatal("failed to load local events", zap.Error(err))
			}
		} else {
			if err := operatorNode.StartEth1(logger, networkConfig.ETH1SyncOffset); err != nil {
				logger.Fatal("failed to start eth1", zap.Error(err))
			}
		}

		cfg.P2pNetworkConfig.GetValidatorStats = func() (uint64, uint64, uint64, error) {
			return validatorCtrl.GetValidatorStats()
		}
		if err := p2pNetwork.Setup(logger); err != nil {
			logger.Fatal("failed to setup network", zap.Error(err))
		}
		if err := p2pNetwork.Start(logger); err != nil {
			logger.Fatal("failed to start network", zap.Error(err))
		}

		if cfg.SSVAPIPort > 0 {
			apiServer := apiserver.New(
				logger,
				fmt.Sprintf(":%d", cfg.SSVAPIPort),
				&handlers.Node{

					PeersIndex: p2pNetwork.(p2pv1.PeersIndexProvider).PeersIndex(),
					Network:    p2pNetwork.(p2pv1.HostProvider).Host().Network(),
					TopicIndex: p2pNetwork.(handlers.TopicIndex),
				},
				&handlers.Validators{
					Shares: nodeStorage.Shares(),
				},
			)
			go func() {
				err := apiServer.Run()
				if err != nil {
					logger.Fatal("failed to start API server", zap.Error(err))
				}
			}()
		}

		if err := operatorNode.Start(logger); err != nil {
			logger.Fatal("failed to start SSV node", zap.Error(err))
		}
	},
}

StartNodeCmd is the command to start SSV node

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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