Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate span map cache flag #5551

Merged
merged 22 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c0b0327
deprecate span map cache flag
shayzluf Apr 21, 2020
69f48b2
fix tests
shayzluf Apr 21, 2020
7c0b2e4
nishant feedback
shayzluf Apr 21, 2020
6cf643f
fix startup
shayzluf Apr 21, 2020
8833be1
gaz
shayzluf Apr 21, 2020
a2ae6aa
nishant feedback
shayzluf Apr 21, 2020
2654dee
gaz
shayzluf Apr 21, 2020
666a5c6
Merge branch 'master' into deprecate_span_cache
rauljordan Apr 21, 2020
008c90e
fix img
rauljordan Apr 21, 2020
b010c64
Update slasher/usage_test.go
rauljordan Apr 21, 2020
70a7d94
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 21, 2020
083fecc
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 21, 2020
6aa6b8a
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 21, 2020
5f4d288
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 21, 2020
31e355b
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 21, 2020
2511e42
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
4525493
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
a2146cd
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
1ec26b0
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
9b2fe49
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
cebe272
Merge refs/heads/master into deprecate_span_cache
prylabs-bulldozer[bot] Apr 22, 2020
50659c2
fix up tests
rauljordan Apr 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func ConfigureBeaconChain(ctx *cli.Context) {
Init(cfg)
}

// ConfigureSlasher sets the global config based
// on what flags are enabled for the slasher client.
func ConfigureSlasher(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
}

// ConfigureValidator sets the global config based
// on what flags are enabled for the validator client.
func ConfigureValidator(ctx *cli.Context) {
Expand Down
9 changes: 9 additions & 0 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}
deprecatedUseSpanCacheFlag = &cli.BoolFlag{
Name: "span-map-cache",
Usage: deprecatedUsage,
Hidden: true,
}
)

var deprecatedFlags = []cli.Flag{
Expand Down Expand Up @@ -341,6 +346,7 @@ var deprecatedFlags = []cli.Flag{
deprecatedProtectProposerFlag,
deprecatedDiscv5Flag,
deprecatedEnableSSZCache,
deprecatedUseSpanCacheFlag,
}

// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
Expand All @@ -352,6 +358,9 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
waitForSyncedFlag,
}...)

// SlasherFlags contains a list of all the feature flags that apply to the slasher client.
var SlasherFlags = append(deprecatedFlags, []cli.Flag{}...)

// E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E.
var E2EValidatorFlags = []string{
"--enable-domain-data-cache",
Expand Down
7 changes: 6 additions & 1 deletion slasher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
deps = [
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/logutil:go_default_library",
"//shared/version:go_default_library",
"//slasher/flags:go_default_library",
Expand All @@ -30,7 +31,10 @@ go_test(
size = "small",
srcs = ["usage_test.go"],
embed = [":go_default_library"],
deps = ["@in_gopkg_urfave_cli_v2//:go_default_library"],
deps = [
"//shared/featureconfig:go_default_library",
"@in_gopkg_urfave_cli_v2//:go_default_library",
],
)

go_image(
Expand All @@ -50,6 +54,7 @@ go_image(
deps = [
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/logutil:go_default_library",
"//shared/version:go_default_library",
"//slasher/flags:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion slasher/db/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ go_test(
"//slasher/db/iface:go_default_library",
"//slasher/db/types:go_default_library",
"//slasher/detection/attestations/types:go_default_library",
"//slasher/flags:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions slasher/db/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ type Store struct {

// Config options for the slasher db.
type Config struct {
// SpanCacheEnabled uses span cache to detect surround slashing.
SpanCacheEnabled bool
SpanCacheSize int
// SpanCacheSize determines the span map cache size.
SpanCacheSize int
}

// Close closes the underlying boltdb database.
Expand Down Expand Up @@ -85,7 +84,8 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) {
}
return nil, err
}
kv := &Store{db: boltDB, databasePath: datafile, spanCacheEnabled: cfg.SpanCacheEnabled}
kv := &Store{db: boltDB, databasePath: datafile}
kv.enableSpanCache(true)
spanCache, err := cache.NewEpochSpansCache(cfg.SpanCacheSize, persistSpanMapsOnEviction(kv))
if err != nil {
return nil, errors.Wrap(err, "could not create new cache")
Expand Down
5 changes: 2 additions & 3 deletions slasher/db/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/slasher/db/iface"
"github.com/prysmaticlabs/prysm/slasher/flags"
"gopkg.in/urfave/cli.v2"
)

Expand All @@ -23,7 +22,7 @@ func setupDB(t testing.TB, ctx *cli.Context) *Store {
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
cfg := &Config{SpanCacheEnabled: ctx.Bool(flags.UseSpanCacheFlag.Name)}
cfg := &Config{}
db, err := NewKVStore(p, cfg)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
Expand All @@ -40,7 +39,7 @@ func setupDBDiffCacheSize(t testing.TB, cacheSize int) *Store {
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
cfg := &Config{SpanCacheEnabled: true, SpanCacheSize: cacheSize}
cfg := &Config{SpanCacheSize: cacheSize}
newDB, err := NewKVStore(p, cfg)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
Expand Down
7 changes: 2 additions & 5 deletions slasher/db/kv/spanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
"github.com/prysmaticlabs/prysm/slasher/flags"
"gopkg.in/urfave/cli.v2"
)

Expand Down Expand Up @@ -98,7 +97,6 @@ func TestStore_SaveSpans(t *testing.T) {
func TestStore_SaveCachedSpans(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
db := setupDB(t, cli.NewContext(&app, set, nil))
defer teardownDB(t, db)
ctx := context.Background()
Expand Down Expand Up @@ -134,7 +132,7 @@ func TestStore_DeleteEpochSpans(t *testing.T) {
db := setupDB(t, cli.NewContext(&app, set, nil))
defer teardownDB(t, db)
ctx := context.Background()

db.spanCacheEnabled = false
for _, tt := range spanTests {
err := db.SaveEpochSpansMap(ctx, tt.epoch, tt.spanMap)
if err != nil {
Expand Down Expand Up @@ -167,7 +165,6 @@ func TestStore_DeleteEpochSpans(t *testing.T) {
func TestValidatorSpanMap_DeletesOnCacheSavesToDB(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
db := setupDB(t, cli.NewContext(&app, set, nil))
defer teardownDB(t, db)
ctx := context.Background()
Expand Down Expand Up @@ -242,7 +239,6 @@ func TestValidatorSpanMap_SaveOnEvict(t *testing.T) {
func TestValidatorSpanMap_SaveCachedSpansMaps(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
db := setupDB(t, cli.NewContext(&app, set, nil))
defer teardownDB(t, db)
ctx := context.Background()
Expand Down Expand Up @@ -276,6 +272,7 @@ func TestStore_ReadWriteEpochsSpanByValidatorsIndices(t *testing.T) {
db := setupDB(t, cli.NewContext(&app, set, nil))
defer teardownDB(t, db)
ctx := context.Background()
db.spanCacheEnabled = false

for _, tt := range spanTests {
err := db.SaveEpochSpansMap(ctx, tt.epoch, tt.spanMap)
Expand Down
4 changes: 2 additions & 2 deletions slasher/db/testing/setup_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
cfg := &kv.Config{SpanCacheEnabled: spanCacheEnabled}
cfg := &kv.Config{}
db, err := slasherDB.NewDB(p, cfg)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
Expand All @@ -41,7 +41,7 @@ func SetupSlasherDBDiffCacheSize(t testing.TB, cacheItems int64, maxCacheSize in
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
cfg := &kv.Config{SpanCacheEnabled: true}
cfg := &kv.Config{}
newDB, err := slasherDB.NewDB(p, cfg)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
Expand Down
5 changes: 0 additions & 5 deletions slasher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ var (
Name: "rebuild-span-maps",
Usage: "Rebuild span maps from indexed attestations in db",
}
// UseSpanCacheFlag enables the slasher to use span cache.
UseSpanCacheFlag = &cli.BoolFlag{
Name: "span-map-cache",
Usage: "Enable span map cache",
}
)
8 changes: 6 additions & 2 deletions slasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
joonix "github.com/joonix/log"
"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/prysmaticlabs/prysm/slasher/flags"
Expand All @@ -20,6 +21,7 @@ import (
var log = logrus.WithField("prefix", "main")

func startSlasher(ctx *cli.Context) error {
featureconfig.ConfigureSlasher(ctx)
verbosity := ctx.String(cmd.VerbosityFlag.Name)
level, err := logrus.ParseLevel(verbosity)
if err != nil {
Expand All @@ -41,7 +43,6 @@ var appFlags = []cli.Flag{
cmd.TracingProcessNameFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.BootstrapNode,
flags.MonitoringPortFlag,
cmd.LogFileName,
cmd.LogFormat,
Expand All @@ -55,12 +56,15 @@ var appFlags = []cli.Flag{
debug.TraceFlag,
flags.RPCPort,
flags.KeyFlag,
flags.UseSpanCacheFlag,
flags.RebuildSpanMapsFlag,
flags.BeaconCertFlag,
flags.BeaconRPCProviderFlag,
}

func init() {
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.SlasherFlags...))
}

func main() {
app := cli.App{}
app.Name = "hash slinging slasher"
Expand Down
3 changes: 2 additions & 1 deletion slasher/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func NewSlasherNode(ctx *cli.Context) (*SlasherNode, error) {
); err != nil {
return nil, err
}

registry := shared.NewServiceRegistry()

slasher := &SlasherNode{
Expand Down Expand Up @@ -142,7 +143,7 @@ func (s *SlasherNode) startDB(ctx *cli.Context) error {
clearDB := ctx.Bool(cmd.ClearDB.Name)
forceClearDB := ctx.Bool(cmd.ForceClearDB.Name)
dbPath := path.Join(baseDir, slasherDBName)
cfg := &kv.Config{SpanCacheEnabled: ctx.Bool(flags.UseSpanCacheFlag.Name)}
cfg := &kv.Config{}
d, err := db.NewDB(dbPath, cfg)
if err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions slasher/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var appHelpFlagGroups = []flagGroup{
cmd.TracingProcessNameFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.BootstrapNode,
flags.MonitoringPortFlag,
cmd.LogFormat,
cmd.LogFileName,
Expand All @@ -74,7 +73,6 @@ var appHelpFlagGroups = []flagGroup{
flags.BeaconCertFlag,
flags.KeyFlag,
flags.RPCPort,
flags.UseSpanCacheFlag,
flags.RebuildSpanMapsFlag,
flags.BeaconRPCProviderFlag,
},
Expand Down
6 changes: 4 additions & 2 deletions slasher/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
"gopkg.in/urfave/cli.v2"
)

Expand All @@ -15,6 +16,8 @@ func TestAllFlagsExistInHelp(t *testing.T) {
for _, group := range appHelpFlagGroups {
helpFlags = append(helpFlags, group.Flags...)
}
helpFlags = featureconfig.ActiveFlags(helpFlags)
appFlags = featureconfig.ActiveFlags(appFlags)

for _, flag := range appFlags {
if !doesFlagExist(flag, helpFlags) {
Expand All @@ -32,10 +35,9 @@ func TestAllFlagsExistInHelp(t *testing.T) {

func doesFlagExist(flag cli.Flag, flags []cli.Flag) bool {
for _, f := range flags {
if f == flag {
if f.String() == flag.String() {
return true
}
}

return false
}
1 change: 0 additions & 1 deletion validator/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ func doesFlagExist(flag cli.Flag, flags []cli.Flag) bool {
return true
}
}

return false
}