prysm-pulse/validator/main.go

178 lines
4.6 KiB
Go
Raw Normal View History

// 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.
package main
import (
"fmt"
"os"
"runtime"
runtimeDebug "runtime/debug"
Command to fetch validator statuses + MultipleValidatorStatus (#5784) * Add method to fetch account statuses * Add status command * gofmt * Add comment about sorting * Close conneciton when finished * Fix error * Refactor FetchAccountStatuses * Add status_test.go * Move sorting out of FetchAccountStatuses * Remove unnecessary casting * Expect ValidatorStatus to be called * Wrap long comment * Comment out sorting * Add all necessary dial options * Close connection before evaluating error from fetch * Small changes * Fix lint issues * Merge branch 'master' into validator-client-account-statuses * Update dependencies for docker images * Rename multipleValidatorStatus to activationStatus * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Update commit hash for ethereumapis * Implement MultipleValidatorStatus * Tests for MultipleValidatorStatus * Fix bugs * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Add export comment for MultipleValidatorStatus * Run `go fmt` in prysm (#5815) * go fmt * Add fix for nil state in InitializeFromProto (#5817) * Add nil check and tests * Add unsafe test * Update tools/genesis-state-gen/main.go * Undo genesis state gen changes * Merge branch 'proto-fuzz-fix' of github.com:prysmaticlabs/prysm into proto-fuzz-fix * gaz * Fix * Add export comment for MultipleValidatorStatus * Clean up comments * Update mock files for beacon_node_validator_service * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Run gazelle * Fix mock issues * Fetch statuses in batches * Simplify public key generation for status_test * Sort validator statuses by status type * Format validator statuses and print to console * Fix lint issues * Delimit with commas * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Rename otheropts to extraopts * Merge branch 'master' into validator-client-account-statuses * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Clean up MultipleValidatorStatus tests * Add sync checker to MultipleValidatorStatus * Update formatting * Prepend 0x to validator keys * Check number of status blocks recieved in status_test * Move sorting to goroutine * Capitalize constants * Fix typo * Use mock reponses in sort test * Remove byteutils * Fix ugly format * Add comment on MultipleValidatorStatus test * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Create entrypoint to run status command, and make unexported functions internal * Move merge step into FetchAccountStatuses * Revert service.go * Remove responseToSortedMetadata * Simplify mergeTwo * Replace fmt output with logrus * Fix typo * Merge branch 'master' into validator-client-account-statuses * Update comment * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Return error on bad credentials * Merge branch 'master' into validator-client-account-statuses * Merge branch 'master' into validator-client-account-statuses * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Skip merge step on error * Fix conflicts * Fix mock paths * Add comments * Convert some sprintfs to wrapfs * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Rename ExtractPublicKeys to ExtractPublicKeysFromKeyStore and move to account.go * Add support for keymanager * Add supported flags to flags list * Log warning on intermediary errors * Update output * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Merge branch 'master' into validator-client-account-statuses * Fix conflicts * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Set context timeout for FetchAccountStatuses * Remove deprecated grpc.WithTimeout * gofmt * Remove getters * Remove parallel stuff * Move grpc dialing out of status.go * Update logging based on feedback * Update validator/accounts/status.go
2020-05-19 05:13:37 +00:00
"time"
joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/journald"
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
"github.com/prysmaticlabs/prysm/shared/logutil"
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
"github.com/prysmaticlabs/prysm/shared/tos"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/validator/flags"
2018-08-22 19:15:21 +00:00
"github.com/prysmaticlabs/prysm/validator/node"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
// connTimeout defines a period after which connection to beacon node is cancelled.
const connTimeout = 10 * time.Second
var log = logrus.WithField("prefix", "main")
func startNode(ctx *cli.Context) error {
validatorClient, err := node.NewValidatorClient(ctx)
if err != nil {
return err
}
2019-01-30 15:24:28 +00:00
validatorClient.Start()
return nil
}
var appFlags = []cli.Flag{
flags.BeaconRPCProviderFlag,
flags.BeaconRPCGatewayProviderFlag,
flags.CertFlag,
flags.GraffitiFlag,
flags.DisablePenaltyRewardLogFlag,
flags.InteropStartIndex,
flags.InteropNumValidators,
flags.EnableRPCFlag,
flags.RPCHost,
flags.RPCPort,
flags.GRPCGatewayPort,
flags.GRPCGatewayHost,
flags.GrpcRetriesFlag,
flags.GrpcRetryDelayFlag,
flags.GrpcHeadersFlag,
flags.GPRCGatewayCorsDomain,
flags.DisableAccountMetricsFlag,
cmd.MonitoringHostFlag,
flags.MonitoringPortFlag,
cmd.DisableMonitoringFlag,
flags.SlasherRPCProviderFlag,
flags.SlasherCertFlag,
flags.WalletPasswordFileFlag,
flags.WalletDirFlag,
flags.EnableWebFlag,
flags.WebHostFlag,
flags.WebPortFlag,
cmd.MinimalConfigFlag,
cmd.E2EConfigFlag,
cmd.VerbosityFlag,
cmd.DataDirFlag,
cmd.ClearDB,
cmd.ForceClearDB,
cmd.EnableTracingFlag,
cmd.TracingProcessNameFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.LogFormat,
cmd.LogFileName,
cmd.ConfigFileFlag,
cmd.ChainConfigFileFlag,
cmd.GrpcMaxCallRecvMsgSizeFlag,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,
debug.MemProfileRateFlag,
debug.CPUProfileFlag,
debug.TraceFlag,
cmd.AcceptTosFlag,
}
func init() {
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.ValidatorFlags...))
}
func main() {
app := cli.App{}
app.Name = "validator"
app.Usage = `launches an Ethereum 2.0 validator client that interacts with a beacon chain,
starts proposer and attester services, p2p connections, and more`
app.Version = version.GetVersion()
app.Action = startNode
app.Commands = []*cli.Command{
accounts.WalletCommands,
accounts.AccountCommands,
2019-01-30 15:24:28 +00:00
}
Command to fetch validator statuses + MultipleValidatorStatus (#5784) * Add method to fetch account statuses * Add status command * gofmt * Add comment about sorting * Close conneciton when finished * Fix error * Refactor FetchAccountStatuses * Add status_test.go * Move sorting out of FetchAccountStatuses * Remove unnecessary casting * Expect ValidatorStatus to be called * Wrap long comment * Comment out sorting * Add all necessary dial options * Close connection before evaluating error from fetch * Small changes * Fix lint issues * Merge branch 'master' into validator-client-account-statuses * Update dependencies for docker images * Rename multipleValidatorStatus to activationStatus * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Update commit hash for ethereumapis * Implement MultipleValidatorStatus * Tests for MultipleValidatorStatus * Fix bugs * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Add export comment for MultipleValidatorStatus * Run `go fmt` in prysm (#5815) * go fmt * Add fix for nil state in InitializeFromProto (#5817) * Add nil check and tests * Add unsafe test * Update tools/genesis-state-gen/main.go * Undo genesis state gen changes * Merge branch 'proto-fuzz-fix' of github.com:prysmaticlabs/prysm into proto-fuzz-fix * gaz * Fix * Add export comment for MultipleValidatorStatus * Clean up comments * Update mock files for beacon_node_validator_service * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Run gazelle * Fix mock issues * Fetch statuses in batches * Simplify public key generation for status_test * Sort validator statuses by status type * Format validator statuses and print to console * Fix lint issues * Delimit with commas * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Rename otheropts to extraopts * Merge branch 'master' into validator-client-account-statuses * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Clean up MultipleValidatorStatus tests * Add sync checker to MultipleValidatorStatus * Update formatting * Prepend 0x to validator keys * Check number of status blocks recieved in status_test * Move sorting to goroutine * Capitalize constants * Fix typo * Use mock reponses in sort test * Remove byteutils * Fix ugly format * Add comment on MultipleValidatorStatus test * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Create entrypoint to run status command, and make unexported functions internal * Move merge step into FetchAccountStatuses * Revert service.go * Remove responseToSortedMetadata * Simplify mergeTwo * Replace fmt output with logrus * Fix typo * Merge branch 'master' into validator-client-account-statuses * Update comment * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Return error on bad credentials * Merge branch 'master' into validator-client-account-statuses * Merge branch 'master' into validator-client-account-statuses * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Skip merge step on error * Fix conflicts * Fix mock paths * Add comments * Convert some sprintfs to wrapfs * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Rename ExtractPublicKeys to ExtractPublicKeysFromKeyStore and move to account.go * Add support for keymanager * Add supported flags to flags list * Log warning on intermediary errors * Update output * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Merge branch 'master' into validator-client-account-statuses * Fix conflicts * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into validator-client-account-statuses * Merge branch 'validator-client-account-statuses' of https://github.com/michaelhly/prysm into validator-client-account-statuses * Set context timeout for FetchAccountStatuses * Remove deprecated grpc.WithTimeout * gofmt * Remove getters * Remove parallel stuff * Move grpc dialing out of status.go * Update logging based on feedback * Update validator/accounts/status.go
2020-05-19 05:13:37 +00:00
app.Flags = appFlags
app.Before = func(ctx *cli.Context) error {
// Load flags from config file, if specified.
if err := cmd.LoadFlagsFromConfig(ctx, app.Flags); err != nil {
return err
}
// verify if ToS accepted
if err := tos.VerifyTosAcceptedOrPrompt(ctx); err != nil {
return err
}
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
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
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.
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
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)
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)
}
logFileName := ctx.String(cmd.LogFileName.Name)
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
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.")
}
}
runtime.GOMAXPROCS(runtime.NumCPU())
return debug.Setup(ctx)
}
app.After = func(ctx *cli.Context) error {
2018-09-21 18:35:48 +00:00
debug.Exit(ctx)
return nil
}
defer func() {
if x := recover(); x != nil {
log.Errorf("Runtime panic: %v\n%v", x, string(runtimeDebug.Stack()))
panic(x)
}
}()
if err := app.Run(os.Args); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}