2021-06-26 19:00:33 +00:00
|
|
|
// Package main defines slasher server implementation for Ethereum. A slasher
|
2020-04-29 21:32:39 +00:00
|
|
|
// listens for all broadcasted messages using a running beacon node in order
|
|
|
|
// to detect malicious attestations and block proposals.
|
2019-10-31 03:26:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
joonix "github.com/joonix/log"
|
2021-03-03 18:37:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd/slasher/flags"
|
2019-10-31 03:26:55 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/cmd"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/debug"
|
2020-04-22 15:53:09 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
2020-10-14 00:10:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/journald"
|
2019-10-31 03:26:55 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/logutil"
|
2020-10-15 02:05:30 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/tos"
|
2019-10-31 03:26:55 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
2020-12-07 20:36:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/slasher/db"
|
2020-02-14 07:09:54 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/slasher/node"
|
2019-10-31 03:26:55 +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"
|
2019-10-31 03:26:55 +00:00
|
|
|
)
|
|
|
|
|
2020-04-29 23:27:01 +00:00
|
|
|
func startSlasher(cliCtx *cli.Context) error {
|
2020-10-21 15:13:46 +00:00
|
|
|
// verify if ToS accepted
|
|
|
|
if err := tos.VerifyTosAcceptedOrPrompt(cliCtx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-29 23:27:01 +00:00
|
|
|
verbosity := cliCtx.String(cmd.VerbosityFlag.Name)
|
2019-10-31 03:26:55 +00:00
|
|
|
level, err := logrus.ParseLevel(verbosity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.SetLevel(level)
|
2021-02-01 17:12:52 +00:00
|
|
|
slasher, err := node.New(cliCtx)
|
2019-10-31 03:26:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
slasher.Start()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var appFlags = []cli.Flag{
|
2020-06-23 15:41:20 +00:00
|
|
|
cmd.MinimalConfigFlag,
|
|
|
|
cmd.E2EConfigFlag,
|
2020-06-29 14:17:24 +00:00
|
|
|
cmd.RPCMaxPageSizeFlag,
|
2019-10-31 03:26:55 +00:00
|
|
|
cmd.VerbosityFlag,
|
|
|
|
cmd.DataDirFlag,
|
|
|
|
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,
|
2020-09-30 20:55:56 +00:00
|
|
|
cmd.DisableMonitoringFlag,
|
2020-12-03 22:28:57 +00:00
|
|
|
cmd.EnableBackupWebhookFlag,
|
|
|
|
cmd.BackupWebhookOutputDir,
|
2019-10-31 03:26:55 +00:00
|
|
|
cmd.LogFileName,
|
|
|
|
cmd.LogFormat,
|
2020-01-29 01:44:51 +00:00
|
|
|
cmd.ClearDB,
|
2020-02-14 07:09:54 +00:00
|
|
|
cmd.ForceClearDB,
|
2020-04-27 14:14:26 +00:00
|
|
|
cmd.ConfigFileFlag,
|
2019-10-31 03:26:55 +00:00
|
|
|
debug.PProfFlag,
|
|
|
|
debug.PProfAddrFlag,
|
|
|
|
debug.PProfPortFlag,
|
|
|
|
debug.MemProfileRateFlag,
|
|
|
|
debug.CPUProfileFlag,
|
|
|
|
debug.TraceFlag,
|
|
|
|
flags.RPCPort,
|
2020-05-20 15:23:22 +00:00
|
|
|
flags.RPCHost,
|
2020-05-26 02:08:15 +00:00
|
|
|
flags.CertFlag,
|
2019-10-31 03:26:55 +00:00
|
|
|
flags.KeyFlag,
|
2020-02-14 07:09:54 +00:00
|
|
|
flags.BeaconCertFlag,
|
2020-01-22 05:39:21 +00:00
|
|
|
flags.BeaconRPCProviderFlag,
|
2020-07-20 20:23:48 +00:00
|
|
|
flags.EnableHistoricalDetectionFlag,
|
2020-08-18 11:18:33 +00:00
|
|
|
flags.SpanCacheSize,
|
2020-10-15 02:05:30 +00:00
|
|
|
cmd.AcceptTosFlag,
|
2020-10-26 12:15:42 +00:00
|
|
|
flags.HighestAttCacheSize,
|
2019-10-31 03:26:55 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:53:09 +00:00
|
|
|
func init() {
|
|
|
|
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.SlasherFlags...))
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:26:55 +00:00
|
|
|
func main() {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2019-10-31 03:26:55 +00:00
|
|
|
app.Name = "hash slinging slasher"
|
|
|
|
app.Usage = `launches an Ethereum Serenity slasher server that interacts with a beacon chain.`
|
2021-01-25 21:27:30 +00:00
|
|
|
app.Version = version.Version()
|
2020-12-07 20:36:43 +00:00
|
|
|
app.Commands = []*cli.Command{
|
|
|
|
db.DatabaseCommands,
|
|
|
|
}
|
2019-10-31 03:26:55 +00:00
|
|
|
app.Flags = appFlags
|
2019-12-13 07:31:37 +00:00
|
|
|
app.Action = startSlasher
|
2019-10-31 03:26:55 +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-04-27 14:14:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
format := ctx.String(cmd.LogFormat.Name)
|
2019-10-31 03:26:55 +00:00
|
|
|
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.
|
2020-03-19 21:46:44 +00:00
|
|
|
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
2019-10-31 03:26:55 +00:00
|
|
|
logrus.SetFormatter(formatter)
|
|
|
|
case "fluentd":
|
|
|
|
logrus.SetFormatter(joonix.NewFormatter())
|
|
|
|
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-10-31 03:26:55 +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-10-31 03:26:55 +00:00
|
|
|
if logFileName != "" {
|
|
|
|
if err := logutil.ConfigurePersistentLogging(logFileName); err != nil {
|
|
|
|
log.WithError(err).Error("Failed to configuring logging to disk.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-10-31 03:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|