prysm-pulse/validator/main.go
Raul Jordan e19920aec1
Miscellaneous Runtime Fixes & Improvements - Raul (#1674)
* fatal if impossible to receive chainstart

* fix tests

* fix

* custom delay

* completed custom delay

* errors

* better logs, nothing at genesis

* use demo in val

* add gazelle

* log

* starting to log stuff

* pass in ops

* avoid printing the large #s for debug, still working on tests..

* all around better logging

* fixed build error in epoch process

* fixed state transiton tests

* fixed block tests

* lint

* verify sigs in randao

* ready for inclusion falg

* only print waiting when slot is not valid

* fix build

* mod config

* fixed last justified slot issue

* fix inclusion

* fixed attestation issue

* using zero hash from params instead

* fix tests

* update balance

* removed swp

* more `- genesis_slot` for logs

* rem unused log

* fix broken tests

* account for skip slots in state root computation

* fixes done

* validator guide bug fixes - 671

* epoch boundary at the last slot of the epoch

* fix epoch issue

* more balance cal logs for debugging

* greater balance

* attestaton fixes

* fixes

* addressed testrun

* fixed ejection balance

* fix tests with far future epoch

* revert sync change

* revert initial sync change

* fix changes

* off by one att fix

* revert the att fix

* address comments

* format

* fix build

* rem file
2019-02-24 20:09:45 -06:00

141 lines
3.6 KiB
Go

package main
import (
"errors"
"fmt"
"os"
"runtime"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/validator/node"
"github.com/prysmaticlabs/prysm/validator/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
func startNode(ctx *cli.Context) error {
keystoreDirectory := ctx.String(types.KeystorePathFlag.Name)
keystorePassword := ctx.String(types.PasswordFlag.Name)
if err := accounts.VerifyAccountNotExists(keystoreDirectory, keystorePassword); err == nil {
return errors.New("no account found, use `validator accounts create` to generate a new keystore")
}
verbosity := ctx.GlobalString(cmd.VerbosityFlag.Name)
level, err := logrus.ParseLevel(verbosity)
if err != nil {
return err
}
logrus.SetLevel(level)
validatorClient, err := node.NewValidatorClient(ctx)
if err != nil {
return err
}
validatorClient.Start()
return nil
}
func createValidatorAccount(ctx *cli.Context) error {
keystoreDirectory := ctx.String(types.KeystorePathFlag.Name)
keystorePassword := ctx.String(types.PasswordFlag.Name)
if err := accounts.NewValidatorAccount(keystoreDirectory, keystorePassword); err != nil {
return fmt.Errorf("could not initialize validator account: %v", err)
}
return nil
}
func main() {
customFormatter := new(prefixed.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
log := logrus.WithField("prefix", "main")
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
VERSION:
{{.Version}}
{{end}}
`
app := cli.NewApp()
app.Name = "validator"
app.Usage = `launches an Ethereum Serenity validator client that interacts with a beacon chain,
starts proposer services, shardp2p 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.Commands{
cli.Command{
Name: "create",
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
contract in order to activate the validator client`,
Flags: []cli.Flag{
types.KeystorePathFlag,
types.PasswordFlag,
},
Action: createValidatorAccount,
},
},
},
}
app.Flags = []cli.Flag{
types.DemoConfigFlag,
types.BeaconRPCProviderFlag,
types.KeystorePathFlag,
types.PasswordFlag,
cmd.VerbosityFlag,
cmd.DataDirFlag,
cmd.EnableTracingFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.BootstrapNode,
cmd.MonitoringPortFlag,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,
debug.MemProfileRateFlag,
debug.CPUProfileFlag,
debug.TraceFlag,
}
app.Before = func(ctx *cli.Context) error {
runtime.GOMAXPROCS(runtime.NumCPU())
return debug.Setup(ctx)
}
app.After = func(ctx *cli.Context) error {
debug.Exit(ctx)
return nil
}
if err := app.Run(os.Args); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}