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-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"
|
2019-05-22 13:22:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/logutil"
|
2019-09-27 22:48:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2019-01-10 04:19:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
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"
|
2018-07-09 02:40:34 +00:00
|
|
|
"github.com/urfave/cli"
|
2019-02-06 16:20:38 +00:00
|
|
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
2019-06-13 14:53:42 +00:00
|
|
|
_ "go.uber.org/automaxprocs"
|
2018-07-09 02:40:34 +00:00
|
|
|
)
|
|
|
|
|
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.NoCustomConfigFlag,
|
|
|
|
flags.BeaconRPCProviderFlag,
|
|
|
|
flags.CertFlag,
|
|
|
|
flags.KeystorePathFlag,
|
|
|
|
flags.PasswordFlag,
|
|
|
|
flags.DisablePenaltyRewardLogFlag,
|
|
|
|
flags.UnencryptedKeysFlag,
|
|
|
|
flags.InteropStartIndex,
|
|
|
|
flags.InteropNumValidators,
|
|
|
|
cmd.VerbosityFlag,
|
|
|
|
cmd.DataDirFlag,
|
|
|
|
cmd.EnableTracingFlag,
|
|
|
|
cmd.TracingProcessNameFlag,
|
|
|
|
cmd.TracingEndpointFlag,
|
|
|
|
cmd.TraceSampleFractionFlag,
|
|
|
|
cmd.BootstrapNode,
|
|
|
|
cmd.MonitoringPortFlag,
|
|
|
|
cmd.LogFormat,
|
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
|
|
|
cmd.LogFileName,
|
|
|
|
cmd.EnableUPnPFlag,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
appFlags = append(appFlags, featureconfig.ValidatorFlags...)
|
|
|
|
}
|
|
|
|
|
2018-07-09 02:40:34 +00:00
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
2018-10-18 17:33:38 +00:00
|
|
|
app.Name = "validator"
|
2019-03-21 02:57:25 +00:00
|
|
|
app.Usage = `launches an Ethereum Serenity validator client that interacts with a beacon chain,
|
2019-01-30 15:24:28 +00:00
|
|
|
starts proposer services, shardp2p 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
|
2019-01-30 15:24:28 +00:00
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "accounts",
|
|
|
|
Category: "accounts",
|
|
|
|
Usage: "defines useful functions for interacting with the validator client's account",
|
|
|
|
Subcommands: cli.Commands{
|
|
|
|
cli.Command{
|
|
|
|
Name: "create",
|
2019-03-21 02:57:25 +00:00
|
|
|
Description: `creates a new validator account keystore containing private keys for Ethereum Serenity -
|
|
|
|
this command outputs a deposit data string which can be used to deposit Ether into the ETH1.0 deposit
|
2019-01-30 15:24:28 +00:00
|
|
|
contract in order to activate the validator client`,
|
|
|
|
Flags: []cli.Flag{
|
2019-07-23 13:58:20 +00:00
|
|
|
flags.KeystorePathFlag,
|
|
|
|
flags.PasswordFlag,
|
2019-01-30 15:24:28 +00:00
|
|
|
},
|
2019-04-24 04:29:06 +00:00
|
|
|
Action: func(ctx *cli.Context) {
|
2019-09-27 22:48:49 +00:00
|
|
|
featureconfig.ConfigureValidatorFeatures(ctx)
|
|
|
|
// Use custom config values if the --no-custom-config flag is set.
|
|
|
|
if !ctx.GlobalBool(flags.NoCustomConfigFlag.Name) {
|
|
|
|
log.Info("Using custom parameter configuration")
|
|
|
|
if featureconfig.FeatureConfig().MinimalConfig {
|
|
|
|
log.Warn("Using Minimal Config")
|
|
|
|
params.UseMinimalConfig()
|
|
|
|
} else {
|
|
|
|
log.Warn("Using Demo Config")
|
|
|
|
params.UseDemoBeaconConfig()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 18:23:25 +00:00
|
|
|
if keystoreDir, _, err := node.CreateValidatorAccount(ctx); err != nil {
|
2019-09-11 18:38:35 +00:00
|
|
|
log.Fatalf("Could not create validator at path: %s", keystoreDir)
|
2019-04-24 04:29:06 +00:00
|
|
|
}
|
|
|
|
},
|
2019-01-30 15:24:28 +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 {
|
2019-05-14 00:43:04 +00:00
|
|
|
format := ctx.GlobalString(cmd.LogFormat.Name)
|
|
|
|
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.
|
|
|
|
formatter.DisableColors = ctx.GlobalString(cmd.LogFileName.Name) != ""
|
2019-05-14 00:43:04 +00:00
|
|
|
logrus.SetFormatter(formatter)
|
|
|
|
break
|
|
|
|
case "fluentd":
|
2019-05-24 20:54:03 +00:00
|
|
|
logrus.SetFormatter(joonix.NewFormatter())
|
2019-05-14 00:43:04 +00:00
|
|
|
break
|
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown log format %s", format)
|
|
|
|
}
|
|
|
|
|
2019-05-22 13:22:11 +00:00
|
|
|
logFileName := ctx.GlobalString(cmd.LogFileName.Name)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|