2019-05-14 00:43:04 +00:00
|
|
|
// Package beacon-chain defines all the utilities needed for a beacon chain node.
|
2018-07-14 02:15:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-05-14 00:43:04 +00:00
|
|
|
"fmt"
|
2018-07-14 02:15:37 +00:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
2019-05-14 00:43:04 +00:00
|
|
|
joonix "github.com/joonix/log"
|
2019-06-02 15:33:44 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
"github.com/x-cray/logrus-prefixed-formatter"
|
|
|
|
|
2018-07-20 21:31:26 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/node"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/utils"
|
|
|
|
"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-01-10 04:19:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
2018-07-14 02:15:37 +00:00
|
|
|
)
|
|
|
|
|
2019-06-02 15:33:44 +00:00
|
|
|
var appFlags = []cli.Flag{
|
|
|
|
utils.NoCustomConfigFlag,
|
|
|
|
utils.DepositContractFlag,
|
|
|
|
utils.Web3ProviderFlag,
|
|
|
|
utils.HTTPWeb3ProviderFlag,
|
|
|
|
utils.RPCPort,
|
|
|
|
utils.CertFlag,
|
|
|
|
utils.KeyFlag,
|
|
|
|
utils.EnableDBCleanup,
|
|
|
|
utils.GRPCGatewayPort,
|
|
|
|
cmd.BootstrapNode,
|
|
|
|
cmd.NoDiscovery,
|
|
|
|
cmd.StaticPeers,
|
|
|
|
cmd.RelayNode,
|
|
|
|
cmd.P2PPort,
|
|
|
|
cmd.P2PHost,
|
|
|
|
cmd.P2PMaxPeers,
|
|
|
|
cmd.P2PPrivKey,
|
|
|
|
cmd.P2PWhitelist,
|
|
|
|
cmd.DataDirFlag,
|
|
|
|
cmd.VerbosityFlag,
|
|
|
|
cmd.EnableTracingFlag,
|
|
|
|
cmd.TracingProcessNameFlag,
|
|
|
|
cmd.TracingEndpointFlag,
|
|
|
|
cmd.TraceSampleFractionFlag,
|
|
|
|
cmd.MonitoringPortFlag,
|
|
|
|
cmd.DisableMonitoringFlag,
|
|
|
|
cmd.ClearDB,
|
|
|
|
cmd.LogFormat,
|
|
|
|
cmd.MaxGoroutines,
|
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
|
|
|
cmd.LogFileName,
|
|
|
|
}
|
2018-07-21 17:51:18 +00:00
|
|
|
|
2019-06-02 15:33:44 +00:00
|
|
|
func init() {
|
|
|
|
appFlags = append(appFlags, featureconfig.BeaconChainFlags...)
|
2018-07-14 02:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2018-07-21 17:51:18 +00:00
|
|
|
log := logrus.WithField("prefix", "main")
|
2018-07-14 02:15:37 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "beacon-chain"
|
|
|
|
app.Usage = "this is a beacon chain implementation for Ethereum 2.0"
|
|
|
|
app.Action = startNode
|
2019-01-10 04:19:33 +00:00
|
|
|
app.Version = version.GetVersion()
|
2018-07-14 02:15:37 +00:00
|
|
|
|
2019-06-02 15:33:44 +00:00
|
|
|
app.Flags = appFlags
|
2019-03-21 02:57:25 +00:00
|
|
|
|
2018-07-14 02:15:37 +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-14 02:15:37 +00:00
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
2018-07-15 19:06:36 +00:00
|
|
|
return debug.Setup(ctx)
|
2018-07-14 02:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 15:33:44 +00:00
|
|
|
|
|
|
|
func startNode(ctx *cli.Context) error {
|
|
|
|
verbosity := ctx.GlobalString(cmd.VerbosityFlag.Name)
|
|
|
|
level, err := logrus.ParseLevel(verbosity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.SetLevel(level)
|
|
|
|
|
|
|
|
beacon, err := node.NewBeaconNode(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
beacon.Start()
|
|
|
|
return nil
|
|
|
|
}
|