prysm-pulse/validator/main.go
Ivan Martinez 4d9da25d02
Add confirm password to validator accounts create (#5762)
* Add confirm password to accounts create

* Fix build

* Update shared/cmd/helpers.go

* Update shared/cmd/helpers.go

Co-authored-by: Shay Zluf <thezluf@gmail.com>

* Change to return empty ""

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: Shay Zluf <thezluf@gmail.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-05-06 19:50:19 -04:00

203 lines
5.8 KiB
Go

// 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"
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/logutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/validator/flags"
"github.com/prysmaticlabs/prysm/validator/node"
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
_ "go.uber.org/automaxprocs"
"gopkg.in/urfave/cli.v2"
"gopkg.in/urfave/cli.v2/altsrc"
)
var log = logrus.WithField("prefix", "main")
func startNode(ctx *cli.Context) error {
validatorClient, err := node.NewValidatorClient(ctx)
if err != nil {
return err
}
validatorClient.Start()
return nil
}
var appFlags = []cli.Flag{
flags.BeaconRPCProviderFlag,
flags.CertFlag,
flags.GraffitiFlag,
flags.KeystorePathFlag,
flags.PasswordFlag,
flags.DisablePenaltyRewardLogFlag,
flags.UnencryptedKeysFlag,
flags.InteropStartIndex,
flags.InteropNumValidators,
flags.GrpcRetriesFlag,
flags.GrpcHeadersFlag,
flags.KeyManager,
flags.KeyManagerOpts,
flags.AccountMetricsFlag,
cmd.VerbosityFlag,
cmd.DataDirFlag,
cmd.ClearDB,
cmd.ForceClearDB,
cmd.EnableTracingFlag,
cmd.TracingProcessNameFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
flags.MonitoringPortFlag,
cmd.LogFormat,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,
debug.MemProfileRateFlag,
debug.CPUProfileFlag,
debug.TraceFlag,
cmd.LogFileName,
cmd.ConfigFileFlag,
cmd.ChainConfigFileFlag,
cmd.GrpcMaxCallRecvMsgSizeFlag,
}
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{
{
Name: "accounts",
Category: "accounts",
Usage: "defines useful functions for interacting with the validator client's account",
Subcommands: []*cli.Command{
{
Name: "create",
Description: `creates a new validator account keystore containing private keys for Ethereum 2.0 -
this command outputs a deposit data string which can be used to deposit Ether into the ETH1.0 deposit
contract in order to activate the validator client`,
Flags: []cli.Flag{
flags.KeystorePathFlag,
flags.PasswordFlag,
},
Action: func(cliCtx *cli.Context) error {
featureconfig.ConfigureValidator(cliCtx)
if featureconfig.Get().MinimalConfig {
log.Warn("Using Minimal Config")
params.UseMinimalConfig()
}
keystorePath, passphrase, err := accounts.HandleEmptyFlags(cliCtx, true /*confirmPassword*/)
if err != nil {
log.WithError(err).Error("Could not list keys")
}
if _, _, err := accounts.CreateValidatorAccount(keystorePath, passphrase); err != nil {
log.WithError(err).Fatalf("Could not create validator at path: %s", keystorePath)
}
return nil
},
},
{
Name: "keys",
Description: `lists the private keys for 'keystore' keymanager keys`,
Flags: []cli.Flag{
flags.KeystorePathFlag,
flags.PasswordFlag,
},
Action: func(cliCtx *cli.Context) error {
keystorePath, passphrase, err := accounts.HandleEmptyFlags(cliCtx, false /*confirmPassword*/)
if err != nil {
log.WithError(err).Error("Could not list keys")
}
if err := accounts.PrintPublicAndPrivateKeys(keystorePath, passphrase); err != nil {
log.WithError(err).Errorf("Could not list private and public keys in path %s", keystorePath)
}
return nil
},
},
},
},
}
app.Flags = appFlags
app.Before = func(ctx *cli.Context) error {
if ctx.IsSet(cmd.ConfigFileFlag.Name) {
if err := altsrc.InitInputSourceWithContext(appFlags, altsrc.NewYamlSourceFromFlagFunc(cmd.ConfigFileFlag.Name))(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
// 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)
break
case "fluentd":
f := joonix.NewFormatter()
if err := joonix.DisableTimestampFormat(f); err != nil {
panic(err)
}
logrus.SetFormatter(f)
break
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
break
default:
return fmt.Errorf("unknown log format %s", format)
}
logFileName := ctx.String(cmd.LogFileName.Name)
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 {
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)
}
}