From a2f781522f792addfa7a70f11ef2434970d96446 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 16 Aug 2020 20:17:46 -0700 Subject: [PATCH] Update committee cache size to 32 (#7018) * Update committee cache size to 32 * Merge branch 'master' into update-committee-cache-size * Cache: fixed rotating test * Merge branch 'update-committee-cache-size' of github.com:prysmaticlabs/prysm into update-committee-cache-size * Merge refs/heads/master into update-committee-cache-size * Merge refs/heads/master into update-committee-cache-size * Merge refs/heads/master into update-committee-cache-size --- beacon-chain/cache/committee.go | 5 ++--- beacon-chain/cache/committee_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 68468ca8d4ca..0ebb0de65e9e 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -17,9 +17,8 @@ var ( ErrNotCommittee = errors.New("object is not a committee struct") // maxCommitteesCacheSize defines the max number of shuffled committees on per randao basis can cache. - // Due to reorgs, it's good to keep the old cache around for quickly switch over. 10 is a generous - // cache size as it considers 3 concurrent branches over 3 epochs. - maxCommitteesCacheSize = uint64(10) + // Due to reorgs and long finality, it's good to keep the old cache around for quickly switch over. + maxCommitteesCacheSize = uint64(32) // CommitteeCacheMiss tracks the number of committee requests that aren't present in the cache. CommitteeCacheMiss = promauto.NewCounter(prometheus.CounterOpts{ diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index 6e5b40d32ae5..3a503412141c 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -122,7 +122,9 @@ func TestCommitteeCache_CanRotate(t *testing.T) { cache := NewCommitteesCache() // Should rotate out all the epochs except 190 through 199. - for i := 100; i < 200; i++ { + start := 100 + end := 200 + for i := start; i < end; i++ { s := []byte(strconv.Itoa(i)) item := &Committees{Seed: bytesutil.ToBytes32(s)} require.NoError(t, cache.AddCommitteeShuffledList(item)) @@ -134,7 +136,8 @@ func TestCommitteeCache_CanRotate(t *testing.T) { sort.Slice(k, func(i, j int) bool { return k[i] < k[j] }) - s := bytesutil.ToBytes32([]byte(strconv.Itoa(190))) + wanted := end - int(maxCommitteesCacheSize) + s := bytesutil.ToBytes32([]byte(strconv.Itoa(wanted))) assert.Equal(t, key(s), k[0], "incorrect key received for slot 190") s = bytesutil.ToBytes32([]byte(strconv.Itoa(199)))