mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
9ac950f480
* Added the 'enable-upnp' flag to the list of supported command line arguments. If the user specifies this feature flag (adds --enable-upnp as an argument) - the Beacon-chain and Validator services, when started, will initialize libp2p with the UPNP options. * Added the new arg to usage.go due to test failure * Update shared/p2p/service.go Changed the logging according to Preston's recommendation. Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Code review changes: 1. File formatting. 2. Command line arg more detailed description.
131 lines
3.2 KiB
Go
131 lines
3.2 KiB
Go
// Package beacon-chain defines all the utilities needed for a beacon chain node.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
|
|
joonix "github.com/joonix/log"
|
|
"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"
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
"github.com/prysmaticlabs/prysm/shared/logutil"
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
|
_ "go.uber.org/automaxprocs"
|
|
)
|
|
|
|
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,
|
|
cmd.EnableUPnPFlag,
|
|
}
|
|
|
|
func init() {
|
|
appFlags = append(appFlags, featureconfig.BeaconChainFlags...)
|
|
}
|
|
|
|
func main() {
|
|
log := logrus.WithField("prefix", "main")
|
|
app := cli.NewApp()
|
|
app.Name = "beacon-chain"
|
|
app.Usage = "this is a beacon chain implementation for Ethereum 2.0"
|
|
app.Action = startNode
|
|
app.Version = version.GetVersion()
|
|
|
|
app.Flags = appFlags
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
|
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
|
|
// 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) != ""
|
|
logrus.SetFormatter(formatter)
|
|
break
|
|
case "fluentd":
|
|
logrus.SetFormatter(joonix.NewFormatter())
|
|
break
|
|
case "json":
|
|
logrus.SetFormatter(&logrus.JSONFormatter{})
|
|
break
|
|
default:
|
|
return fmt.Errorf("unknown log format %s", format)
|
|
}
|
|
|
|
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.")
|
|
}
|
|
}
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
return debug.Setup(ctx)
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
log.Error(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|