2020-04-29 21:32:39 +00:00
|
|
|
// Package main defines a validator client, a critical actor in eth2 which manages
|
|
|
|
// 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"
|
|
|
|
"runtime"
|
2019-11-06 16:18:51 +00:00
|
|
|
runtimeDebug "runtime/debug"
|
2020-05-19 05:13:37 +00:00
|
|
|
"time"
|
2018-07-09 02:40:34 +00:00
|
|
|
|
2019-05-14 00:43:04 +00:00
|
|
|
joonix "github.com/joonix/log"
|
2018-07-20 21:31:26 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/cmd"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/debug"
|
2019-03-21 02:57:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
2020-10-14 00:10:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/journald"
|
2019-05-22 13:22:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/logutil"
|
2020-07-11 00:57:43 +00:00
|
|
|
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
|
2020-10-15 02:05:30 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/tos"
|
2019-01-10 04:19:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
2020-10-15 22:31:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts"
|
2019-07-23 13:58:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/flags"
|
2018-08-22 19:15:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/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"
|
2019-02-06 16:20:38 +00:00
|
|
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
2018-07-09 02:40:34 +00:00
|
|
|
)
|
|
|
|
|
2020-07-03 15:25:32 +00:00
|
|
|
// connTimeout defines a period after which connection to beacon node is cancelled.
|
|
|
|
const connTimeout = 10 * time.Second
|
|
|
|
|
2019-09-11 18:38:35 +00:00
|
|
|
var log = logrus.WithField("prefix", "main")
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
func startNode(ctx *cli.Context) error {
|
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,
|
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-06-10 16:04:32 +00:00
|
|
|
cmd.MonitoringHostFlag,
|
2020-05-20 18:19:30 +00:00
|
|
|
flags.MonitoringPortFlag,
|
2020-09-30 20:55:56 +00:00
|
|
|
cmd.DisableMonitoringFlag,
|
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-10-09 14:58:30 +00:00
|
|
|
flags.WebHostFlag,
|
|
|
|
flags.WebPortFlag,
|
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,
|
2019-09-11 18:38:35 +00:00
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
2020-10-15 02:05:30 +00:00
|
|
|
cmd.AcceptTosFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-03-19 21:46:44 +00:00
|
|
|
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.ValidatorFlags...))
|
2019-09-11 18:38:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
func main() {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2018-10-18 17:33:38 +00:00
|
|
|
app.Name = "validator"
|
2020-05-06 05:55:25 +00:00
|
|
|
app.Usage = `launches an Ethereum 2.0 validator client that interacts with a beacon chain,
|
|
|
|
starts proposer and attester services, p2p connections, and more`
|
2019-01-10 04:19:33 +00:00
|
|
|
app.Version = version.GetVersion()
|
2018-07-09 02:40:34 +00:00
|
|
|
app.Action = startNode
|
2020-03-19 21:46:44 +00:00
|
|
|
app.Commands = []*cli.Command{
|
2020-10-15 22:31:52 +00:00
|
|
|
accounts.WalletCommands,
|
|
|
|
accounts.AccountCommands,
|
2019-01-30 15:24:28 +00:00
|
|
|
}
|
2020-05-19 05:13:37 +00:00
|
|
|
|
2019-09-11 18:38:35 +00:00
|
|
|
app.Flags = appFlags
|
2019-03-21 02:57:25 +00:00
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
app.Before = func(ctx *cli.Context) error {
|
2020-10-11 15:26:59 +00:00
|
|
|
// Load flags from config file, if specified.
|
|
|
|
if err := cmd.LoadFlagsFromConfig(ctx, app.Flags); err != nil {
|
|
|
|
return err
|
2020-03-19 21:46:44 +00:00
|
|
|
}
|
2020-10-15 02:05:30 +00:00
|
|
|
// verify if ToS accepted
|
|
|
|
if err := tos.VerifyTosAcceptedOrPrompt(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-11 15:26:59 +00:00
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
format := ctx.String(cmd.LogFormat.Name)
|
2019-05-14 00:43:04 +00:00
|
|
|
switch format {
|
|
|
|
case "text":
|
|
|
|
formatter := new(prefixed.TextFormatter)
|
|
|
|
formatter.TimestampFormat = "2006-01-02 15:04:05"
|
|
|
|
formatter.FullTimestamp = true
|
2019-05-22 13:22:11 +00:00
|
|
|
// If persistent log files are written - we disable the log messages coloring because
|
|
|
|
// the colors are ANSI codes and seen as Gibberish in the log files.
|
2020-03-19 21:46:44 +00:00
|
|
|
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
2019-05-14 00:43:04 +00:00
|
|
|
logrus.SetFormatter(formatter)
|
|
|
|
case "fluentd":
|
2019-10-04 03:56:10 +00:00
|
|
|
f := joonix.NewFormatter()
|
|
|
|
if err := joonix.DisableTimestampFormat(f); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
logrus.SetFormatter(f)
|
2019-05-14 00:43:04 +00:00
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
2020-10-14 00:10:57 +00:00
|
|
|
case "journald":
|
|
|
|
if err := journald.Enable(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-14 00:43:04 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown log format %s", format)
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
logFileName := ctx.String(cmd.LogFileName.Name)
|
2019-05-22 13:22:11 +00:00
|
|
|
if logFileName != "" {
|
|
|
|
if err := logutil.ConfigurePersistentLogging(logFileName); err != nil {
|
|
|
|
log.WithError(err).Error("Failed to configuring logging to disk.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
2018-07-15 19:06:36 +00:00
|
|
|
return debug.Setup(ctx)
|
2018-07-09 02:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
2018-09-21 18:35:48 +00:00
|
|
|
debug.Exit(ctx)
|
2018-07-09 02:40:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|