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

on evict test fix #5046

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion slasher/cache/span_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ type EpochSpansCache struct {
}

// NewEpochSpansCache initializes the map and underlying cache.
func NewEpochSpansCache(onEvicted func(key interface{}, value interface {})) (*EpochSpansCache, error) {
func NewEpochSpansCache(size int, onEvicted func(key interface{}, value interface{})) (*EpochSpansCache, error) {
if size != 0 {
epochSpansCacheSize = size
}
cache, err := lru.NewWithEvict(epochSpansCacheSize, onEvicted)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion slasher/db/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Store struct {
type Config struct {
// SpanCacheEnabled uses span cache to detect surround slashing.
SpanCacheEnabled bool
SpanCacheSize int
}

// Close closes the underlying boltdb database.
Expand Down Expand Up @@ -85,7 +86,7 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) {
return nil, err
}
kv := &Store{db: boltDB, databasePath: datafile, spanCacheEnabled: cfg.SpanCacheEnabled}
spanCache, err := cache.NewEpochSpansCache(persistSpanMapsOnEviction(kv))
spanCache, err := cache.NewEpochSpansCache(cfg.SpanCacheSize, persistSpanMapsOnEviction(kv))
if err != nil {
return nil, errors.Wrap(err, "could not create new cache")
}
Expand Down
4 changes: 2 additions & 2 deletions slasher/db/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setupDB(t testing.TB, ctx *cli.Context) *Store {
return db
}

func setupDBDiffCacheSize(t testing.TB, cacheItems int64, maxCacheSize int64) *Store {
func setupDBDiffCacheSize(t testing.TB, cacheSize int) *Store {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Could not generate random file path: %v", err)
Expand All @@ -40,7 +40,7 @@ func setupDBDiffCacheSize(t testing.TB, cacheItems int64, maxCacheSize int64) *S
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
cfg := &Config{SpanCacheEnabled: true}
cfg := &Config{SpanCacheEnabled: true, SpanCacheSize: cacheSize}
newDB, err := NewKVStore(p, cfg)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion slasher/db/kv/spanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestValidatorSpanMap_DeletesOnCacheSavesToDB(t *testing.T) {
}

func TestValidatorSpanMap_SaveOnEvict(t *testing.T) {
db := setupDBDiffCacheSize(t, 5, 5)
db := setupDBDiffCacheSize(t, 5)
defer teardownDB(t, db)
ctx := context.Background()

Expand Down
2 changes: 1 addition & 1 deletion slasher/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"sync"
"syscall"

"github.com/prysmaticlabs/prysm/shared/prometheus"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/prometheus"
"github.com/prysmaticlabs/prysm/shared/tracing"
"github.com/prysmaticlabs/prysm/slasher/beaconclient"
"github.com/prysmaticlabs/prysm/slasher/db"
Expand Down