2021-06-26 19:00:33 +00:00
|
|
|
// Package beacon-chain defines the entire runtime of an Ethereum 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"
|
2020-12-15 20:01:51 +00:00
|
|
|
"path/filepath"
|
2018-07-14 02:15:37 +00:00
|
|
|
"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"
|
2018-07-20 21:31:26 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/node"
|
2021-09-21 18:11:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
2021-10-18 17:48:05 +00:00
|
|
|
blockchaincmd "github.com/prysmaticlabs/prysm/cmd/beacon-chain/blockchain"
|
2021-03-03 17:05:37 +00:00
|
|
|
dbcommands "github.com/prysmaticlabs/prysm/cmd/beacon-chain/db"
|
2021-03-02 19:36:03 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
2021-11-04 18:19:44 +00:00
|
|
|
powchaincmd "github.com/prysmaticlabs/prysm/cmd/beacon-chain/powchain"
|
2022-03-28 21:01:55 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/sync/checkpoint"
|
2021-09-15 01:18:39 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/features"
|
2021-09-17 21:55:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/io/file"
|
|
|
|
"github.com/prysmaticlabs/prysm/io/logs"
|
2021-09-14 20:59:51 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/monitoring/journald"
|
2021-09-16 09:46:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/runtime/debug"
|
|
|
|
_ "github.com/prysmaticlabs/prysm/runtime/maxprocs"
|
|
|
|
"github.com/prysmaticlabs/prysm/runtime/tos"
|
|
|
|
"github.com/prysmaticlabs/prysm/runtime/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-12-03 20:38:00 +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,
|
2022-02-25 19:08:43 +00:00
|
|
|
flags.ExecutionJWTSecretFlag,
|
2020-12-11 11:15:04 +00:00
|
|
|
flags.FallbackWeb3ProviderFlag,
|
2020-01-17 02:18:26 +00:00
|
|
|
flags.RPCHost,
|
2019-07-23 13:58:20 +00:00
|
|
|
flags.RPCPort,
|
|
|
|
flags.CertFlag,
|
|
|
|
flags.KeyFlag,
|
2021-09-24 09:25:42 +00:00
|
|
|
flags.HTTPModules,
|
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-11-17 05:25:35 +00:00
|
|
|
flags.SubscribeToAllSubnets,
|
2020-07-20 20:23:48 +00:00
|
|
|
flags.HistoricalSlasherNode,
|
2020-08-05 22:03:25 +00:00
|
|
|
flags.ChainID,
|
|
|
|
flags.NetworkID,
|
2022-03-28 21:01:55 +00:00
|
|
|
flags.WeakSubjectivityCheckpoint,
|
2020-11-26 18:38:52 +00:00
|
|
|
flags.Eth1HeaderReqLimit,
|
2021-03-18 21:00:00 +00:00
|
|
|
flags.GenesisStatePath,
|
2021-09-21 07:55:52 +00:00
|
|
|
flags.MinPeersPerSubnet,
|
2022-03-21 21:25:33 +00:00
|
|
|
flags.SuggestedFeeRecipient,
|
2020-12-03 22:28:57 +00:00
|
|
|
cmd.EnableBackupWebhookFlag,
|
|
|
|
cmd.BackupWebhookOutputDir,
|
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,
|
2021-02-11 20:20:19 +00:00
|
|
|
debug.BlockProfileRateFlag,
|
|
|
|
debug.MutexProfileFractionFlag,
|
2019-06-02 15:33:44 +00:00
|
|
|
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,
|
2020-12-07 20:36:43 +00:00
|
|
|
cmd.RestoreSourceFileFlag,
|
|
|
|
cmd.RestoreTargetDirFlag,
|
2021-02-15 20:29:47 +00:00
|
|
|
cmd.BoltMMapInitialSizeFlag,
|
2021-11-30 22:27:03 +00:00
|
|
|
cmd.ValidatorMonitorIndicesFlag,
|
2022-02-24 18:01:37 +00:00
|
|
|
cmd.ApiTimeoutFlag,
|
2022-03-28 21:01:55 +00:00
|
|
|
checkpoint.BlockPath,
|
|
|
|
checkpoint.StatePath,
|
|
|
|
checkpoint.RemoteURL,
|
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() {
|
2021-09-15 01:18:39 +00:00
|
|
|
appFlags = cmd.WrapFlags(append(appFlags, features.BeaconChainFlags...))
|
2018-07-14 02:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2018-07-14 02:15:37 +00:00
|
|
|
app.Name = "beacon-chain"
|
2021-06-26 19:00:33 +00:00
|
|
|
app.Usage = "this is a beacon chain implementation for Ethereum"
|
2018-07-14 02:15:37 +00:00
|
|
|
app.Action = startNode
|
2021-01-25 21:27:30 +00:00
|
|
|
app.Version = version.Version()
|
2020-12-07 20:36:43 +00:00
|
|
|
app.Commands = []*cli.Command{
|
2021-03-03 17:05:37 +00:00
|
|
|
dbcommands.Commands,
|
2020-12-07 20:36:43 +00:00
|
|
|
}
|
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":
|
2020-12-03 20:38:00 +00:00
|
|
|
formatter := new(prefixed.TextFormatter)
|
2019-05-14 00:43:04 +00:00
|
|
|
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 != "" {
|
2021-09-17 21:55:24 +00:00
|
|
|
if err := logs.ConfigurePersistentLogging(logFileName); err != nil {
|
2019-05-22 13:22:11 +00:00
|
|
|
log.WithError(err).Error("Failed to configuring logging to disk.")
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 11:15:04 +00:00
|
|
|
if err := cmd.ExpandSingleEndpointIfFile(ctx, flags.HTTPWeb3ProviderFlag); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := cmd.ExpandWeb3EndpointsIfFile(ctx, flags.FallbackWeb3ProviderFlag); err != nil {
|
2020-10-22 05:53:03 +00:00
|
|
|
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())
|
2021-06-30 16:24:04 +00:00
|
|
|
if err := debug.Setup(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return cmd.ValidateNoArgs(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-12-15 20:01:51 +00:00
|
|
|
// Fix data dir for Windows users.
|
2021-09-17 21:55:24 +00:00
|
|
|
outdatedDataDir := filepath.Join(file.HomeDir(), "AppData", "Roaming", "Eth2")
|
2020-12-15 20:01:51 +00:00
|
|
|
currentDataDir := ctx.String(cmd.DataDirFlag.Name)
|
|
|
|
if err := cmd.FixDefaultDataDir(outdatedDataDir, currentDataDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-10-18 17:48:05 +00:00
|
|
|
blockchainFlagOpts, err := blockchaincmd.FlagOptions(ctx)
|
|
|
|
if err != nil {
|
2022-02-25 19:08:43 +00:00
|
|
|
return err
|
2021-10-18 17:48:05 +00:00
|
|
|
}
|
2021-11-04 18:19:44 +00:00
|
|
|
powchainFlagOpts, err := powchaincmd.FlagOptions(ctx)
|
|
|
|
if err != nil {
|
2022-02-25 19:08:43 +00:00
|
|
|
return err
|
2021-11-04 18:19:44 +00:00
|
|
|
}
|
2021-10-18 17:48:05 +00:00
|
|
|
opts := []node.Option{
|
|
|
|
node.WithBlockchainFlagOptions(blockchainFlagOpts),
|
2021-11-04 18:19:44 +00:00
|
|
|
node.WithPowchainFlagOptions(powchainFlagOpts),
|
2021-10-18 17:48:05 +00:00
|
|
|
}
|
2022-03-28 21:01:55 +00:00
|
|
|
cptOpts, err := checkpoint.BeaconNodeOptions(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if cptOpts != nil {
|
|
|
|
opts = append(opts, cptOpts)
|
|
|
|
}
|
2021-10-18 17:48:05 +00:00
|
|
|
beacon, err := node.New(ctx, opts...)
|
2019-06-02 15:33:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
beacon.Start()
|
|
|
|
return nil
|
|
|
|
}
|