2021-06-26 19:00:33 +00:00
|
|
|
// Package main defines a validator client, a critical actor in Ethereum which manages
|
2020-04-29 21:32:39 +00:00
|
|
|
// a keystore of private keys, connects to a beacon node to receive assignments,
|
|
|
|
// and submits blocks/attestations as needed.
|
2018-07-09 02:40:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-01-31 11:57:57 +00:00
|
|
|
"fmt"
|
2018-07-09 02:40:34 +00:00
|
|
|
"os"
|
2020-12-15 20:01:51 +00:00
|
|
|
"path/filepath"
|
2019-11-06 16:18:51 +00:00
|
|
|
runtimeDebug "runtime/debug"
|
2018-07-09 02:40:34 +00:00
|
|
|
|
2019-05-14 00:43:04 +00:00
|
|
|
joonix "github.com/joonix/log"
|
2024-01-15 14:46:54 +00:00
|
|
|
"github.com/pkg/errors"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd"
|
|
|
|
accountcommands "github.com/prysmaticlabs/prysm/v5/cmd/validator/accounts"
|
|
|
|
dbcommands "github.com/prysmaticlabs/prysm/v5/cmd/validator/db"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
|
|
|
|
slashingprotectioncommands "github.com/prysmaticlabs/prysm/v5/cmd/validator/slashing-protection"
|
|
|
|
walletcommands "github.com/prysmaticlabs/prysm/v5/cmd/validator/wallet"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd/validator/web"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/features"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/io/file"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/io/logs"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/monitoring/journald"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/debug"
|
|
|
|
prefixed "github.com/prysmaticlabs/prysm/v5/runtime/logging/logrus-prefixed-formatter"
|
|
|
|
_ "github.com/prysmaticlabs/prysm/v5/runtime/maxprocs"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/tos"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/node"
|
2018-07-21 17:51:18 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-05-31 20:08:36 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-07-09 02:40:34 +00:00
|
|
|
)
|
|
|
|
|
2024-01-15 14:46:54 +00:00
|
|
|
var log = logrus.WithField("prefix", "main")
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
func startNode(ctx *cli.Context) error {
|
2024-01-15 14:46:54 +00:00
|
|
|
// Verify if ToS is accepted.
|
2020-10-21 15:13:46 +00:00
|
|
|
if err := tos.VerifyTosAcceptedOrPrompt(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-09-26 18:23:25 +00:00
|
|
|
validatorClient, err := node.NewValidatorClient(ctx)
|
2018-08-15 01:21:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-30 15:24:28 +00:00
|
|
|
validatorClient.Start()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-11 18:38:35 +00:00
|
|
|
var appFlags = []cli.Flag{
|
|
|
|
flags.BeaconRPCProviderFlag,
|
2020-09-04 19:03:18 +00:00
|
|
|
flags.BeaconRPCGatewayProviderFlag,
|
2022-12-08 14:38:56 +00:00
|
|
|
flags.BeaconRESTApiProviderFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
flags.CertFlag,
|
2019-12-07 19:13:56 +00:00
|
|
|
flags.GraffitiFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
flags.DisablePenaltyRewardLogFlag,
|
|
|
|
flags.InteropStartIndex,
|
|
|
|
flags.InteropNumValidators,
|
2020-09-30 20:55:56 +00:00
|
|
|
flags.EnableRPCFlag,
|
2020-08-14 02:49:57 +00:00
|
|
|
flags.RPCHost,
|
|
|
|
flags.RPCPort,
|
|
|
|
flags.GRPCGatewayPort,
|
|
|
|
flags.GRPCGatewayHost,
|
2020-02-24 18:00:22 +00:00
|
|
|
flags.GrpcRetriesFlag,
|
2020-07-22 03:45:52 +00:00
|
|
|
flags.GrpcRetryDelayFlag,
|
2020-03-25 16:29:04 +00:00
|
|
|
flags.GrpcHeadersFlag,
|
2020-09-04 19:03:18 +00:00
|
|
|
flags.GPRCGatewayCorsDomain,
|
2020-05-19 13:44:54 +00:00
|
|
|
flags.DisableAccountMetricsFlag,
|
2020-05-20 18:19:30 +00:00
|
|
|
flags.MonitoringPortFlag,
|
2020-05-20 15:23:22 +00:00
|
|
|
flags.SlasherRPCProviderFlag,
|
|
|
|
flags.SlasherCertFlag,
|
2020-07-29 01:20:13 +00:00
|
|
|
flags.WalletPasswordFileFlag,
|
2020-07-08 05:01:09 +00:00
|
|
|
flags.WalletDirFlag,
|
2020-09-03 15:11:17 +00:00
|
|
|
flags.EnableWebFlag,
|
2020-12-04 23:15:12 +00:00
|
|
|
flags.GraffitiFileFlag,
|
2024-02-05 15:43:51 +00:00
|
|
|
flags.EnableDistributed,
|
2022-01-31 16:44:17 +00:00
|
|
|
// Consensys' Web3Signer flags
|
|
|
|
flags.Web3SignerURLFlag,
|
|
|
|
flags.Web3SignerPublicValidatorKeysFlag,
|
2022-03-21 18:48:02 +00:00
|
|
|
flags.SuggestedFeeRecipientFlag,
|
2022-06-06 19:32:41 +00:00
|
|
|
flags.ProposerSettingsURLFlag,
|
|
|
|
flags.ProposerSettingsFlag,
|
2022-07-19 13:38:33 +00:00
|
|
|
flags.EnableBuilderFlag,
|
2022-07-29 22:20:56 +00:00
|
|
|
flags.BuilderGasLimitFlag,
|
2024-01-02 09:52:14 +00:00
|
|
|
flags.ValidatorsRegistrationBatchSizeFlag,
|
2022-01-31 16:44:17 +00:00
|
|
|
////////////////////
|
|
|
|
cmd.DisableMonitoringFlag,
|
|
|
|
cmd.MonitoringHostFlag,
|
2020-12-03 22:28:57 +00:00
|
|
|
cmd.BackupWebhookOutputDir,
|
|
|
|
cmd.EnableBackupWebhookFlag,
|
2020-06-23 15:41:20 +00:00
|
|
|
cmd.MinimalConfigFlag,
|
|
|
|
cmd.E2EConfigFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
cmd.VerbosityFlag,
|
|
|
|
cmd.DataDirFlag,
|
2020-01-08 18:16:17 +00:00
|
|
|
cmd.ClearDB,
|
|
|
|
cmd.ForceClearDB,
|
2019-09-11 18:38:35 +00:00
|
|
|
cmd.EnableTracingFlag,
|
|
|
|
cmd.TracingProcessNameFlag,
|
|
|
|
cmd.TracingEndpointFlag,
|
|
|
|
cmd.TraceSampleFractionFlag,
|
|
|
|
cmd.LogFormat,
|
2020-05-20 18:19:30 +00:00
|
|
|
cmd.LogFileName,
|
|
|
|
cmd.ConfigFileFlag,
|
|
|
|
cmd.ChainConfigFileFlag,
|
|
|
|
cmd.GrpcMaxCallRecvMsgSizeFlag,
|
2022-02-24 18:01:37 +00:00
|
|
|
cmd.ApiTimeoutFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
2021-02-11 20:20:19 +00:00
|
|
|
debug.BlockProfileRateFlag,
|
|
|
|
debug.MutexProfileFractionFlag,
|
2020-10-15 02:05:30 +00:00
|
|
|
cmd.AcceptTosFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-09-15 01:18:39 +00:00
|
|
|
appFlags = cmd.WrapFlags(append(appFlags, features.ValidatorFlags...))
|
2019-09-11 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
func main() {
|
2024-01-02 18:02:28 +00:00
|
|
|
app := cli.App{
|
|
|
|
Name: "validator",
|
|
|
|
Usage: "Launches an Ethereum validator client that interacts with a beacon chain, starts proposer and attester services, p2p connections, and more.",
|
|
|
|
Version: version.Version(),
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
if err := startNode(ctx); err != nil {
|
2024-03-04 09:28:49 +00:00
|
|
|
log.Fatal(err.Error())
|
|
|
|
return err
|
2019-10-04 03:56:10 +00:00
|
|
|
}
|
2024-01-02 18:02:28 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
walletcommands.Commands,
|
|
|
|
accountcommands.Commands,
|
|
|
|
slashingprotectioncommands.Commands,
|
|
|
|
dbcommands.Commands,
|
|
|
|
web.Commands,
|
|
|
|
},
|
|
|
|
Flags: appFlags,
|
|
|
|
Before: func(ctx *cli.Context) error {
|
|
|
|
// Load flags from config file, if specified.
|
|
|
|
if err := cmd.LoadFlagsFromConfig(ctx, appFlags); err != nil {
|
2020-10-14 00:10:57 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-05-14 00:43:04 +00:00
|
|
|
|
2024-01-15 14:46:54 +00:00
|
|
|
logFileName := ctx.String(cmd.LogFileName.Name)
|
|
|
|
|
2024-01-02 18:02:28 +00:00
|
|
|
format := ctx.String(cmd.LogFormat.Name)
|
|
|
|
switch format {
|
|
|
|
case "text":
|
|
|
|
formatter := new(prefixed.TextFormatter)
|
|
|
|
formatter.TimestampFormat = "2006-01-02 15:04:05"
|
|
|
|
formatter.FullTimestamp = true
|
|
|
|
// If persistent log files are written - we disable the log messages coloring because
|
2024-01-15 14:46:54 +00:00
|
|
|
// the colors are ANSI codes and seen as gibberish in the log files.
|
|
|
|
formatter.DisableColors = logFileName != ""
|
2024-01-02 18:02:28 +00:00
|
|
|
logrus.SetFormatter(formatter)
|
|
|
|
case "fluentd":
|
|
|
|
f := joonix.NewFormatter()
|
|
|
|
if err := joonix.DisableTimestampFormat(f); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
logrus.SetFormatter(f)
|
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
|
|
|
case "journald":
|
|
|
|
if err := journald.Enable(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown log format %s", format)
|
2019-05-22 13:22:11 +00:00
|
|
|
}
|
|
|
|
|
2024-01-02 18:02:28 +00:00
|
|
|
if logFileName != "" {
|
|
|
|
if err := logs.ConfigurePersistentLogging(logFileName); err != nil {
|
|
|
|
log.WithError(err).Error("Failed to configuring logging to disk.")
|
|
|
|
}
|
|
|
|
}
|
2020-12-15 20:01:51 +00:00
|
|
|
|
2024-01-02 18:02:28 +00:00
|
|
|
// Fix data dir for Windows users.
|
|
|
|
outdatedDataDir := filepath.Join(file.HomeDir(), "AppData", "Roaming", "Eth2Validators")
|
|
|
|
currentDataDir := flags.DefaultValidatorDir()
|
|
|
|
if err := cmd.FixDefaultDataDir(outdatedDataDir, currentDataDir); err != nil {
|
|
|
|
log.WithError(err).Error("Cannot update data directory")
|
|
|
|
}
|
2018-07-09 02:40:34 +00:00
|
|
|
|
2024-01-02 18:02:28 +00:00
|
|
|
if err := debug.Setup(ctx); err != nil {
|
2024-01-15 14:46:54 +00:00
|
|
|
return errors.Wrap(err, "failed to setup debug")
|
2024-01-02 18:02:28 +00:00
|
|
|
}
|
2024-01-15 14:46:54 +00:00
|
|
|
|
2024-01-02 18:02:28 +00:00
|
|
|
return cmd.ValidateNoArgs(ctx)
|
|
|
|
},
|
|
|
|
After: func(ctx *cli.Context) error {
|
|
|
|
debug.Exit(ctx)
|
|
|
|
return nil
|
|
|
|
},
|
2018-07-09 02:40:34 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 16:18:51 +00:00
|
|
|
defer func() {
|
|
|
|
if x := recover(); x != nil {
|
|
|
|
log.Errorf("Runtime panic: %v\n%v", x, string(runtimeDebug.Stack()))
|
|
|
|
panic(x)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
2018-07-14 02:15:37 +00:00
|
|
|
log.Error(err.Error())
|
2018-07-09 02:40:34 +00:00
|
|
|
}
|
|
|
|
}
|