From 7903ec0b12dcc705bac0e5eee6b457be687b6dee Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Sun, 2 Aug 2020 18:09:10 -0400 Subject: [PATCH] Fix CMD Config and modify --historical-slasher-node (#6730) * Fix CMD config overwriting * Rename and change historical slasher node * Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-cmd-config * Fix * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Add storage warning * Merge branch 'fix-cmd-config' of github.com:prysmaticlabs/prysm into fix-cmd-config * Remove period * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Add default values test * Merge branch 'fix-cmd-config' of github.com:prysmaticlabs/prysm into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Gaz * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Fix inits * Merge branch 'fix-cmd-config' of github.com:prysmaticlabs/prysm into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Fix * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config * Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-cmd-config * Fix * Merge refs/heads/master into fix-cmd-config * Merge refs/heads/master into fix-cmd-config --- beacon-chain/flags/base.go | 2 +- beacon-chain/node/node.go | 11 +++++++++-- shared/cmd/BUILD.bazel | 1 + shared/cmd/config.go | 16 ++++++---------- shared/cmd/config_test.go | 19 +++++++++++++++++-- slasher/node/node.go | 4 ++-- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/beacon-chain/flags/base.go b/beacon-chain/flags/base.go index d9f05ad64..fce2ecaf4 100644 --- a/beacon-chain/flags/base.go +++ b/beacon-chain/flags/base.go @@ -137,6 +137,6 @@ var ( // HistoricalSlasherNode is a set of beacon node flags required for performing historical detection with a slasher. HistoricalSlasherNode = &cli.BoolFlag{ Name: "historical-slasher-node", - Usage: "Enables required flags for serving historical data to a slasher client", + Usage: "Enables required flags for serving historical data to a slasher client. Results in additional storage usage", } ) diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 82ce54f84..bbb6d4099 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -100,13 +100,20 @@ func NewBeaconNode(cliCtx *cli.Context) (*BeaconNode, error) { params.LoadChainConfigFile(chainConfigFileName) } - if cliCtx.IsSet(flags.HistoricalSlasherNode.Name) { + if cliCtx.Bool(flags.HistoricalSlasherNode.Name) { c := params.BeaconConfig() - c.SlotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch + // Save a state every 4 epochs. + c.SlotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch * 4 params.OverrideBeaconConfig(c) cmdConfig := cmd.Get() + // Allow up to 4096 attestations at a time to be requested from the beacon nde. cmdConfig.MaxRPCPageSize = int(params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().MaxAttestations) cmd.Init(cmdConfig) + log.Warnf( + "Setting %d slots per archive point and %d max RPC page size for historical slasher usage. This requires additional storage", + c.SlotsPerArchivedPoint, + cmdConfig.MaxRPCPageSize, + ) } if cliCtx.IsSet(flags.SlotsPerArchivedPoint.Name) { diff --git a/shared/cmd/BUILD.bazel b/shared/cmd/BUILD.bazel index 210efbf00..667431882 100644 --- a/shared/cmd/BUILD.bazel +++ b/shared/cmd/BUILD.bazel @@ -36,6 +36,7 @@ go_test( ], embed = [":go_default_library"], deps = [ + "//shared/params:go_default_library", "//shared/testutil/assert:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/shared/cmd/config.go b/shared/cmd/config.go index 8e1dae155..70f90e492 100644 --- a/shared/cmd/config.go +++ b/shared/cmd/config.go @@ -33,7 +33,7 @@ func Init(c *Flags) { // InitWithReset sets the global config and returns function that is used to reset configuration. func InitWithReset(c *Flags) func() { resetFunc := func() { - Init(&Flags{}) + Init(nil) } Init(c) return resetFunc @@ -43,12 +43,10 @@ func InitWithReset(c *Flags) func() { // on what flags are enabled for the beacon-chain client. func ConfigureBeaconChain(ctx *cli.Context) { cfg := newConfig(ctx) - maxPageSize := params.BeaconConfig().DefaultPageSize if ctx.IsSet(RPCMaxPageSizeFlag.Name) { - maxPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) - log.Warnf("Starting beacon chain with max RPC page size of %d", maxPageSize) + cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) + log.Warnf("Starting beacon chain with max RPC page size of %d", cfg.MaxRPCPageSize) } - cfg.MaxRPCPageSize = maxPageSize Init(cfg) } @@ -56,12 +54,10 @@ func ConfigureBeaconChain(ctx *cli.Context) { // on what flags are enabled for the slasher client. func ConfigureSlasher(ctx *cli.Context) { cfg := newConfig(ctx) - maxPageSize := params.BeaconConfig().DefaultPageSize if ctx.IsSet(RPCMaxPageSizeFlag.Name) { - maxPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) - log.Warnf("Starting slasher with max RPC page size of %d", maxPageSize) + cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) + log.Warnf("Starting slasher with max RPC page size of %d", cfg.MaxRPCPageSize) } - cfg.MaxRPCPageSize = maxPageSize Init(cfg) } @@ -73,7 +69,7 @@ func ConfigureValidator(ctx *cli.Context) { } func newConfig(ctx *cli.Context) *Flags { - cfg := &Flags{} + cfg := Get() if ctx.Bool(MinimalConfigFlag.Name) { log.Warn("Using minimal config") cfg.MinimalConfig = true diff --git a/shared/cmd/config_test.go b/shared/cmd/config_test.go index 9bcfbbe12..20bf753df 100644 --- a/shared/cmd/config_test.go +++ b/shared/cmd/config_test.go @@ -4,19 +4,34 @@ import ( "flag" "testing" + "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/urfave/cli/v2" ) -func TestInitFeatureConfig(t *testing.T) { +func TestOverrideConfig(t *testing.T) { cfg := &Flags{ MinimalConfig: true, } - Init(cfg) + reset := InitWithReset(cfg) + defer reset() c := Get() assert.Equal(t, true, c.MinimalConfig) } +func TestDefaultConfig(t *testing.T) { + cfg := &Flags{ + MaxRPCPageSize: params.BeaconConfig().DefaultPageSize, + } + c := Get() + assert.DeepEqual(t, c, cfg) + + reset := InitWithReset(cfg) + defer reset() + c = Get() + assert.DeepEqual(t, c, cfg) +} + func TestConfigureBeaconConfig(t *testing.T) { app := cli.App{} set := flag.NewFlagSet("test", 0) diff --git a/slasher/node/node.go b/slasher/node/node.go index 4a9de9c05..1538055cf 100644 --- a/slasher/node/node.go +++ b/slasher/node/node.go @@ -64,7 +64,7 @@ func NewSlasherNode(cliCtx *cli.Context) (*SlasherNode, error) { return nil, err } - if cliCtx.IsSet(flags.EnableHistoricalDetectionFlag.Name) { + if cliCtx.Bool(flags.EnableHistoricalDetectionFlag.Name) { // Set the max RPC size to 4096 as configured by --historical-slasher-node for optimal historical detection. cmdConfig := cmd.Get() cmdConfig.MaxRPCPageSize = int(params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().MaxAttestations) @@ -230,7 +230,7 @@ func (s *SlasherNode) registerDetectionService() error { ChainFetcher: bs, AttesterSlashingsFeed: s.attesterSlashingsFeed, ProposerSlashingsFeed: s.proposerSlashingsFeed, - HistoricalDetection: s.cliCtx.IsSet(flags.EnableHistoricalDetectionFlag.Name), + HistoricalDetection: s.cliCtx.Bool(flags.EnableHistoricalDetectionFlag.Name), }) return s.services.RegisterService(ds) }