2020-04-29 17:40:33 +00:00
|
|
|
// Package beacon-chain defines the entire runtime of an eth2 beacon 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-11-06 16:18:51 +00:00
|
|
|
runtimeDebug "runtime/debug"
|
2018-07-14 02:15:37 +00:00
|
|
|
|
2020-04-18 06:23:45 +00:00
|
|
|
gethlog "github.com/ethereum/go-ethereum/log"
|
2020-05-31 06:44:34 +00:00
|
|
|
golog "github.com/ipfs/go-log/v2"
|
2019-05-14 00:43:04 +00:00
|
|
|
joonix "github.com/joonix/log"
|
2019-07-23 13:58:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
2018-07-20 21:31:26 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/node"
|
|
|
|
"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"
|
2020-10-14 00:10:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/journald"
|
2019-05-22 13:22:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/logutil"
|
2020-07-11 00:57:43 +00:00
|
|
|
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
|
2020-10-15 02:05:30 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/tos"
|
2019-01-10 04:19:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
2019-06-13 14:53:42 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-05-31 20:08:36 +00:00
|
|
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
2018-07-14 02:15:37 +00:00
|
|
|
)
|
|
|
|
|
2019-06-02 15:33:44 +00:00
|
|
|
var appFlags = []cli.Flag{
|
2019-07-23 13:58:20 +00:00
|
|
|
flags.DepositContractFlag,
|
|
|
|
flags.HTTPWeb3ProviderFlag,
|
2020-01-17 02:18:26 +00:00
|
|
|
flags.RPCHost,
|
2019-07-23 13:58:20 +00:00
|
|
|
flags.RPCPort,
|
|
|
|
flags.CertFlag,
|
|
|
|
flags.KeyFlag,
|
2020-06-03 18:11:43 +00:00
|
|
|
flags.DisableGRPCGateway,
|
2020-06-10 16:04:32 +00:00
|
|
|
flags.GRPCGatewayHost,
|
2019-07-23 13:58:20 +00:00
|
|
|
flags.GRPCGatewayPort,
|
2020-09-03 23:25:56 +00:00
|
|
|
flags.GPRCGatewayCorsDomain,
|
2019-12-13 15:12:49 +00:00
|
|
|
flags.MinSyncPeers,
|
2020-01-16 01:46:15 +00:00
|
|
|
flags.ContractDeploymentBlock,
|
2020-02-18 00:37:37 +00:00
|
|
|
flags.SetGCPercent,
|
2020-10-19 20:03:31 +00:00
|
|
|
flags.HeadSync,
|
2020-09-17 06:11:21 +00:00
|
|
|
flags.DisableSync,
|
2020-04-14 20:27:03 +00:00
|
|
|
flags.DisableDiscv5,
|
2020-04-27 14:35:40 +00:00
|
|
|
flags.BlockBatchLimit,
|
2020-05-12 11:31:10 +00:00
|
|
|
flags.BlockBatchLimitBurstFactor,
|
2019-09-09 21:13:50 +00:00
|
|
|
flags.InteropMockEth1DataVotesFlag,
|
|
|
|
flags.InteropGenesisStateFlag,
|
2019-09-11 18:38:35 +00:00
|
|
|
flags.InteropNumValidatorsFlag,
|
|
|
|
flags.InteropGenesisTimeFlag,
|
2020-03-06 23:06:01 +00:00
|
|
|
flags.SlotsPerArchivedPoint,
|
2020-05-01 01:47:10 +00:00
|
|
|
flags.EnableDebugRPCEndpoints,
|
2020-10-26 18:20:54 +00:00
|
|
|
flags.EnableBackupWebhookFlag,
|
|
|
|
flags.BackupWebhookOutputDir,
|
2020-07-20 20:23:48 +00:00
|
|
|
flags.HistoricalSlasherNode,
|
2020-08-05 22:03:25 +00:00
|
|
|
flags.ChainID,
|
|
|
|
flags.NetworkID,
|
2020-09-26 08:04:07 +00:00
|
|
|
flags.WeakSubjectivityCheckpt,
|
2020-06-23 15:41:20 +00:00
|
|
|
cmd.MinimalConfigFlag,
|
|
|
|
cmd.E2EConfigFlag,
|
2020-06-29 14:17:24 +00:00
|
|
|
cmd.RPCMaxPageSizeFlag,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.BootstrapNode,
|
|
|
|
cmd.NoDiscovery,
|
|
|
|
cmd.StaticPeers,
|
|
|
|
cmd.RelayNode,
|
2019-09-12 04:52:27 +00:00
|
|
|
cmd.P2PUDPPort,
|
|
|
|
cmd.P2PTCPPort,
|
2020-01-23 03:25:10 +00:00
|
|
|
cmd.P2PIP,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.P2PHost,
|
2020-01-22 22:07:22 +00:00
|
|
|
cmd.P2PHostDNS,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.P2PMaxPeers,
|
|
|
|
cmd.P2PPrivKey,
|
2020-04-14 20:27:03 +00:00
|
|
|
cmd.P2PMetadata,
|
2020-06-08 04:35:15 +00:00
|
|
|
cmd.P2PAllowList,
|
|
|
|
cmd.P2PDenyList,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.DataDirFlag,
|
|
|
|
cmd.VerbosityFlag,
|
|
|
|
cmd.EnableTracingFlag,
|
|
|
|
cmd.TracingProcessNameFlag,
|
|
|
|
cmd.TracingEndpointFlag,
|
|
|
|
cmd.TraceSampleFractionFlag,
|
2020-06-10 16:04:32 +00:00
|
|
|
cmd.MonitoringHostFlag,
|
2020-04-19 08:36:19 +00:00
|
|
|
flags.MonitoringPortFlag,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.DisableMonitoringFlag,
|
|
|
|
cmd.ClearDB,
|
2019-10-31 09:55:32 +00:00
|
|
|
cmd.ForceClearDB,
|
2019-06-02 15:33:44 +00:00
|
|
|
cmd.LogFormat,
|
|
|
|
cmd.MaxGoroutines,
|
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
|
|
|
cmd.LogFileName,
|
2019-06-26 19:59:37 +00:00
|
|
|
cmd.EnableUPnPFlag,
|
2020-03-19 21:46:44 +00:00
|
|
|
cmd.ConfigFileFlag,
|
2020-05-05 17:58:07 +00:00
|
|
|
cmd.ChainConfigFileFlag,
|
2020-05-06 21:01:23 +00:00
|
|
|
cmd.GrpcMaxCallRecvMsgSizeFlag,
|
2020-10-15 02:05:30 +00:00
|
|
|
cmd.AcceptTosFlag,
|
2019-06-02 15:33:44 +00:00
|
|
|
}
|
2018-07-21 17:51:18 +00:00
|
|
|
|
2019-06-02 15:33:44 +00:00
|
|
|
func init() {
|
2020-03-19 21:46:44 +00:00
|
|
|
appFlags = cmd.WrapFlags(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")
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2018-07-14 02:15:37 +00:00
|
|
|
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 {
|
2020-10-11 15:26:59 +00:00
|
|
|
// Load flags from config file, if specified.
|
|
|
|
if err := cmd.LoadFlagsFromConfig(ctx, app.Flags); err != nil {
|
|
|
|
return err
|
2020-03-19 21:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
format := ctx.String(cmd.LogFormat.Name)
|
2019-05-14 00:43:04 +00:00
|
|
|
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.
|
2020-03-19 21:46:44 +00:00
|
|
|
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
2019-05-14 00:43:04 +00:00
|
|
|
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)
|
2019-05-14 00:43:04 +00:00
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
2020-10-14 00:10:57 +00:00
|
|
|
case "journald":
|
|
|
|
if err := journald.Enable(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-14 00:43:04 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown log format %s", format)
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
logFileName := ctx.String(cmd.LogFileName.Name)
|
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.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 05:53:03 +00:00
|
|
|
if err := cmd.ExpandWeb3EndpointIfFile(ctx, flags.HTTPWeb3ProviderFlag); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-18 01:37:35 +00:00
|
|
|
if ctx.IsSet(flags.SetGCPercent.Name) {
|
2020-03-19 21:46:44 +00:00
|
|
|
runtimeDebug.SetGCPercent(ctx.Int(flags.SetGCPercent.Name))
|
2020-02-18 01:37:35 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-11-06 16:18:51 +00:00
|
|
|
defer func() {
|
|
|
|
if x := recover(); x != nil {
|
|
|
|
log.Errorf("Runtime panic: %v\n%v", x, string(runtimeDebug.Stack()))
|
|
|
|
panic(x)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-07-14 02:15:37 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 15:33:44 +00:00
|
|
|
|
|
|
|
func startNode(ctx *cli.Context) error {
|
2020-10-21 15:13:46 +00:00
|
|
|
// verify if ToS accepted
|
|
|
|
if err := tos.VerifyTosAcceptedOrPrompt(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
verbosity := ctx.String(cmd.VerbosityFlag.Name)
|
2019-06-02 15:33:44 +00:00
|
|
|
level, err := logrus.ParseLevel(verbosity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.SetLevel(level)
|
2019-10-01 15:38:21 +00:00
|
|
|
if level == logrus.TraceLevel {
|
2020-04-18 06:23:45 +00:00
|
|
|
// libp2p specific logging.
|
2020-05-31 06:44:34 +00:00
|
|
|
golog.SetAllLoggers(golog.LevelDebug)
|
2020-04-18 06:23:45 +00:00
|
|
|
// Geth specific logging.
|
|
|
|
glogger := gethlog.NewGlogHandler(gethlog.StreamHandler(os.Stderr, gethlog.TerminalFormat(true)))
|
|
|
|
glogger.Verbosity(gethlog.LvlTrace)
|
|
|
|
gethlog.Root().SetHandler(glogger)
|
2019-09-11 18:38:35 +00:00
|
|
|
}
|
2019-06-02 15:33:44 +00:00
|
|
|
|
|
|
|
beacon, err := node.NewBeaconNode(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
beacon.Start()
|
|
|
|
return nil
|
|
|
|
}
|