exporter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StartExporterNodeCmd = &cobra.Command{
	Use:   "start-exporter",
	Short: "Starts exporter node",
	Run: func(cmd *cobra.Command, args []string) {
		if err := cleanenv.ReadConfig(globalArgs.ConfigPath, &cfg); err != nil {
			log.Fatal(err)
		}
		if globalArgs.ShareConfigPath != "" {
			if err := cleanenv.ReadConfig(globalArgs.ShareConfigPath, &cfg); err != nil {
				log.Fatal(err)
			}
		}

		commons.SetBuildData(cmd.Parent().Short, cmd.Parent().Version)
		log.Printf("starting %s", commons.GetBuildData())
		loggerLevel, errLogLevel := logex.GetLoggerLevelValue(cfg.LogLevel)
		Logger := logex.Build(commons.GetBuildData(), loggerLevel, &logex.EncodingConfig{
			Format:       cfg.GlobalConfig.LogFormat,
			LevelEncoder: logex.LevelEncoder([]byte(cfg.LogLevelFormat)),
		})
		if errLogLevel != nil {
			Logger.Warn(fmt.Sprintf("Default log level set to %s", loggerLevel), zap.Error(errLogLevel))
		}
		cfg.DBOptions.Logger = Logger
		cfg.DBOptions.Ctx = cmd.Context()

		db, err := storage.GetStorageFactory(cfg.DBOptions)
		if err != nil {
			Logger.Fatal("failed to create db!", zap.Error(err))
		}

		migrationOpts := migrations.Options{
			Db:     db,
			Logger: Logger,
			DbPath: cfg.DBOptions.Path,
		}
		err = migrations.Run(cmd.Context(), migrationOpts)
		if err != nil {
			Logger.Fatal("failed to run migrations", zap.Error(err))
		}

		eth2Network := core.NetworkFromString(cfg.ETH2Options.Network)
		currentEpoch := slots.EpochsSinceGenesis(time.Unix(int64(eth2Network.MinGenesisTime()), 0))
		ssvForkVersion := forksprotocol.GetCurrentForkVersion(currentEpoch)

		cfg.P2pNetworkConfig.NetworkPrivateKey, err = utils.ECDSAPrivateKey(Logger.With(zap.String("who", "p2pNetworkPrivateKey")), cfg.NetworkPrivateKey)
		if err != nil {
			log.Fatal("Failed to get p2p privateKey", zap.Error(err))
		}
		cfg.P2pNetworkConfig.ForkVersion = ssvForkVersion
		cfg.P2pNetworkConfig.Logger = Logger
		cfg.P2pNetworkConfig.UserAgent = forksv0.GenUserAgent(nil)

		network := p2p.New(cmd.Context(), &cfg.P2pNetworkConfig)
		if err := network.Setup(); err != nil {
			Logger.Fatal("failed to setup network", zap.Error(err))
		}
		if err := network.Start(); err != nil {
			Logger.Fatal("failed to start network", zap.Error(err))
		}

		Logger.Info("using registry contract address", zap.String("addr", cfg.ETH1Options.RegistryContractAddr), zap.String("abiVersion", cfg.ETH1Options.AbiVersion.String()))

		if len(cfg.ETH1Options.RegistryContractABI) > 0 {
			Logger.Info("using registry contract abi", zap.String("abi", cfg.ETH1Options.RegistryContractABI))
			if err = eth1.LoadABI(cfg.ETH1Options.RegistryContractABI); err != nil {
				Logger.Fatal("failed to load ABI JSON", zap.Error(err))
			}
		}
		eth1Client, err := goeth.NewEth1Client(goeth.ClientOptions{
			Ctx:                  cmd.Context(),
			Logger:               Logger,
			NodeAddr:             cfg.ETH1Options.ETH1Addr,
			ContractABI:          eth1.ContractABI(cfg.ETH1Options.AbiVersion),
			ConnectionTimeout:    cfg.ETH1Options.ETH1ConnectionTimeout,
			RegistryContractAddr: cfg.ETH1Options.RegistryContractAddr,
			AbiVersion:           cfg.ETH1Options.AbiVersion,
		})
		if err != nil {
			Logger.Fatal("failed to create eth1 client", zap.Error(err))
		}

		cfg.ETH2Options.Context = cmd.Context()
		cfg.ETH2Options.Logger = Logger
		cfg.ETH2Options.Graffiti = []byte("SSV.Network")
		cfg.ETH2Options.DB = db

		exporterOptions := new(exporter.Options)
		exporterOptions.Eth1Client = eth1Client

		exporterOptions.Logger = Logger

		exporterOptions.DB = db
		exporterOptions.Ctx = cmd.Context()
		exporterOptions.WS = api.NewWsServer(cmd.Context(), Logger, nil, http.NewServeMux(), cfg.WithPing)
		exporterOptions.WsAPIPort = cfg.WsAPIPort
		exporterOptions.IbftSyncEnabled = cfg.IbftSyncEnabled
		exporterOptions.CleanRegistryData = cfg.ETH1Options.CleanRegistryData
		exporterOptions.ValidatorMetaDataUpdateInterval = cfg.ValidatorMetaDataUpdateInterval

		exporterOptions.NumOfInstances = cfg.NumOfInstances
		exporterOptions.InstanceID = cfg.InstanceID

	},
}

StartExporterNodeCmd is the command to start SSV boot 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