From bb6476209c50a0e4d9ba930936a13fe9f7963609 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 7 Nov 2019 11:12:21 -0800 Subject: [PATCH] Update Committee Cache for v0.9 (#3948) * Updated committee cache * Removed shuffled indices cache * Started testing run time * Lint * Fixed test --- .../forkchoice/process_attestation.go | 1 - .../blockchain/forkchoice/process_block.go | 7 ++ beacon-chain/cache/BUILD.bazel | 2 - beacon-chain/cache/committee.go | 58 ++++------ beacon-chain/cache/committee_test.go | 74 ++---------- beacon-chain/cache/shuffled_indices.go | 106 ------------------ beacon-chain/cache/shuffled_indices_test.go | 93 --------------- .../core/blocks/block_operations_test.go | 1 - .../core/epoch/epoch_processing_test.go | 2 - beacon-chain/core/helpers/cache.go | 6 - beacon-chain/core/helpers/committee.go | 21 +--- beacon-chain/core/helpers/committee_test.go | 54 --------- beacon-chain/gateway/gateway.go | 4 +- beacon-chain/rpc/attester_server.go | 4 +- beacon-chain/rpc/attester_server_test.go | 4 +- validator/client/validator_attest.go | 1 - 16 files changed, 42 insertions(+), 396 deletions(-) delete mode 100644 beacon-chain/cache/shuffled_indices.go delete mode 100644 beacon-chain/cache/shuffled_indices_test.go diff --git a/beacon-chain/blockchain/forkchoice/process_attestation.go b/beacon-chain/blockchain/forkchoice/process_attestation.go index 36b4f170f277..f13766e0809b 100644 --- a/beacon-chain/blockchain/forkchoice/process_attestation.go +++ b/beacon-chain/blockchain/forkchoice/process_attestation.go @@ -205,7 +205,6 @@ func (s *Store) aggregateAttestation(ctx context.Context, att *ethpb.Attestation if err != nil { return err } - if a, ok := s.attsQueue[root]; ok { a, err := helpers.AggregateAttestation(a, att) if err != nil { diff --git a/beacon-chain/blockchain/forkchoice/process_block.go b/beacon-chain/blockchain/forkchoice/process_block.go index c4fda088dec7..9f8506d021b3 100644 --- a/beacon-chain/blockchain/forkchoice/process_block.go +++ b/beacon-chain/blockchain/forkchoice/process_block.go @@ -215,6 +215,13 @@ func (s *Store) OnBlockNoVerifyStateTransition(ctx context.Context, b *ethpb.Bea // Epoch boundary bookkeeping such as logging epoch summaries. if helpers.IsEpochStart(postState.Slot) { reportEpochMetrics(postState) + + // Update committee shuffled indices at the end of every epoch + if featureconfig.Get().EnableNewCache { + if err := helpers.UpdateCommitteeCache(postState); err != nil { + return err + } + } } return nil diff --git a/beacon-chain/cache/BUILD.bazel b/beacon-chain/cache/BUILD.bazel index 4c33da840c59..1ec8954ba298 100644 --- a/beacon-chain/cache/BUILD.bazel +++ b/beacon-chain/cache/BUILD.bazel @@ -10,7 +10,6 @@ go_library( "committee.go", "common.go", "eth1_data.go", - "shuffled_indices.go", ], importpath = "github.com/prysmaticlabs/prysm/beacon-chain/cache", visibility = ["//beacon-chain:__subpackages__"], @@ -41,7 +40,6 @@ go_test( "committee_test.go", "eth1_data_test.go", "feature_flag_test.go", - "shuffled_indices_test.go", ], embed = [":go_default_library"], race = "on", diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 980de4d8df6b..4339fbcc706e 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -8,6 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/prysm/shared/featureconfig" + "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/sliceutil" "k8s.io/client-go/tools/cache" ) @@ -33,15 +34,14 @@ var ( }) ) -// Committee defines the committee per epoch and shard. +// Committee defines the committee per epoch and index. type Committee struct { - CommitteeIndex uint64 CommitteeCount uint64 Epoch uint64 Committee []uint64 } -// CommitteeCache is a struct with 1 queue for looking up shuffled indices list by epoch and committee. +// CommitteeCache is a struct with 1 queue for looking up shuffled indices list by epoch and committee index. type CommitteeCache struct { CommitteeCache *cache.FIFO lock sync.RWMutex @@ -64,15 +64,17 @@ func NewCommitteeCache() *CommitteeCache { } } -// ShuffledIndices fetches the shuffled indices by epoch and committee. Every list of indices -// represent one committee. Returns true if the list exists with epoch and committee. Otherwise returns false, nil. -func (c *CommitteeCache) ShuffledIndices(epoch uint64, index uint64) ([]uint64, error) { +// ShuffledIndices fetches the shuffled indices by slot and committee index. Every list of indices +// represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil. +func (c *CommitteeCache) ShuffledIndices(slot uint64, index uint64) ([]uint64, error) { if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache { return nil, nil } c.lock.RLock() defer c.lock.RUnlock() - obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch))) + + epoch := int(slot / params.BeaconConfig().SlotsPerEpoch) + obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(epoch)) if err != nil { return nil, err } @@ -89,7 +91,13 @@ func (c *CommitteeCache) ShuffledIndices(epoch uint64, index uint64) ([]uint64, return nil, ErrNotCommittee } - start, end := startEndIndices(item, index) + committeeCountPerSlot := uint64(1) + if item.CommitteeCount/params.BeaconConfig().SlotsPerEpoch > 1 { + committeeCountPerSlot = item.CommitteeCount / params.BeaconConfig().SlotsPerEpoch + } + + indexOffSet := index + (slot%params.BeaconConfig().SlotsPerEpoch)*committeeCountPerSlot + start, end := startEndIndices(item, indexOffSet) return item.Committee[start:end], nil } @@ -147,40 +155,14 @@ func (c *CommitteeCache) EpochInCache(wantedEpoch uint64) (bool, error) { return false, nil } -// CommitteeCount returns the total number of committees in a given epoch as stored in cache. -func (c *CommitteeCache) CommitteeCount(epoch uint64) (uint64, bool, error) { - if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache { - return 0, false, nil - } - c.lock.RLock() - defer c.lock.RUnlock() - obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch))) - if err != nil { - return 0, false, err - } - - if exists { - CommitteeCacheHit.Inc() - } else { - CommitteeCacheMiss.Inc() - return 0, false, nil - } - - item, ok := obj.(*Committee) - if !ok { - return 0, false, ErrNotCommittee - } - - return item.CommitteeCount, true, nil -} - -// CommitteeIndex returns the committee index in a given epoch as stored in cache. -func (c *CommitteeCache) CommitteeIndex(epoch uint64) (uint64, bool, error) { +// CommitteeCountPerSlot returns the number of committees in a given slot as stored in cache. +func (c *CommitteeCache) CommitteeCountPerSlot(slot uint64) (uint64, bool, error) { if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache { return 0, false, nil } c.lock.RLock() defer c.lock.RUnlock() + epoch := int(slot / params.BeaconConfig().SlotsPerEpoch) obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch))) if err != nil { return 0, false, err @@ -198,7 +180,7 @@ func (c *CommitteeCache) CommitteeIndex(epoch uint64) (uint64, bool, error) { return 0, false, ErrNotCommittee } - return item.CommitteeIndex, true, nil + return item.CommitteeCount / params.BeaconConfig().SlotsPerEpoch, true, nil } // ActiveIndices returns the active indices of a given epoch stored in cache. diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index cb957b330dfe..2bdbfee69cd1 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -4,6 +4,8 @@ import ( "reflect" "strconv" "testing" + + "github.com/prysmaticlabs/prysm/shared/params" ) func TestCommitteeKeyFn_OK(t *testing.T) { @@ -36,12 +38,11 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) { Epoch: 1, Committee: []uint64{1, 2, 3, 4, 5, 6}, CommitteeCount: 3, - CommitteeIndex: 1, } - epoch := uint64(1) + slot := uint64(item.Epoch * params.BeaconConfig().SlotsPerEpoch) committeeIndex := uint64(1) - indices, err := cache.ShuffledIndices(epoch, committeeIndex) + indices, err := cache.ShuffledIndices(slot, committeeIndex) if err != nil { t.Fatal(err) } @@ -52,11 +53,12 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) { if err := cache.AddCommitteeShuffledList(item); err != nil { t.Fatal(err) } - wantedIndex := uint64(2) - indices, err = cache.ShuffledIndices(epoch, wantedIndex) + wantedIndex := uint64(0) + indices, err = cache.ShuffledIndices(slot, wantedIndex) if err != nil { t.Fatal(err) } + start, end := startEndIndices(item, wantedIndex) if !reflect.DeepEqual(indices, item.Committee[start:end]) { t.Errorf( @@ -143,68 +145,6 @@ func TestCommitteeCache_EpochInCache(t *testing.T) { } } -func TestCommitteeCache_CommitteesCount(t *testing.T) { - cache := NewCommitteeCache() - - committeeCount := uint64(3) - epoch := uint64(10) - item := &Committee{Epoch: epoch, CommitteeCount: committeeCount} - - _, exists, err := cache.CommitteeCount(1) - if err != nil { - t.Fatal(err) - } - if exists { - t.Error("Expected committee count not to exist in empty cache") - } - - if err := cache.AddCommitteeShuffledList(item); err != nil { - t.Fatal(err) - } - - count, exists, err := cache.CommitteeCount(epoch) - if err != nil { - t.Fatal(err) - } - if !exists { - t.Error("Expected committee count to be in cache") - } - if count != committeeCount { - t.Errorf("wanted: %d, got: %d", committeeCount, count) - } -} - -func TestCommitteeCache_IndexCount(t *testing.T) { - cache := NewCommitteeCache() - - committeeIndex := uint64(7) - epoch := uint64(3) - item := &Committee{Epoch: epoch, CommitteeIndex: committeeIndex} - - _, exists, err := cache.CommitteeIndex(1) - if err != nil { - t.Fatal(err) - } - if exists { - t.Error("Expected start index not to exist in empty cache") - } - - if err := cache.AddCommitteeShuffledList(item); err != nil { - t.Fatal(err) - } - - index, exists, err := cache.CommitteeIndex(epoch) - if err != nil { - t.Fatal(err) - } - if !exists { - t.Error("Expected start index to be in cache") - } - if index != committeeIndex { - t.Errorf("wanted: %d, got: %d", committeeIndex, index) - } -} - func TestCommitteeCache_ActiveIndices(t *testing.T) { cache := NewCommitteeCache() diff --git a/beacon-chain/cache/shuffled_indices.go b/beacon-chain/cache/shuffled_indices.go deleted file mode 100644 index 7fb531458ec1..000000000000 --- a/beacon-chain/cache/shuffled_indices.go +++ /dev/null @@ -1,106 +0,0 @@ -package cache - -import ( - "errors" - "strconv" - "sync" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/prysmaticlabs/prysm/shared/featureconfig" - "k8s.io/client-go/tools/cache" -) - -var ( - // ErrNotValidatorListInfo will be returned when a cache object is not a pointer to - // a ValidatorList struct. - ErrNotValidatorListInfo = errors.New("object is not a shuffled validator list") - - // maxShuffledListSize defines the max number of shuffled list can cache. - maxShuffledListSize = 1000 - - // Metrics. - shuffledIndicesCacheMiss = promauto.NewCounter(prometheus.CounterOpts{ - Name: "shuffled_validators_cache_miss", - Help: "The number of shuffled validators requests that aren't present in the cache.", - }) - shuffledIndicesCacheHit = promauto.NewCounter(prometheus.CounterOpts{ - Name: "shuffled_validators_cache_hit", - Help: "The number of shuffled validators requests that are present in the cache.", - }) -) - -// IndicesByIndexSeed defines the shuffled validator indices per randao seed. -type IndicesByIndexSeed struct { - Index uint64 - Seed []byte - ShuffledIndices []uint64 -} - -// ShuffledIndicesCache is a struct with 1 queue for looking up shuffled validators by seed. -type ShuffledIndicesCache struct { - shuffledIndicesCache *cache.FIFO - lock sync.RWMutex -} - -// slotKeyFn takes the randao seed as the key for the shuffled validators of a given epoch. -func shuffleKeyFn(obj interface{}) (string, error) { - sInfo, ok := obj.(*IndicesByIndexSeed) - if !ok { - return "", ErrNotValidatorListInfo - } - - return string(sInfo.Seed) + strconv.Itoa(int(sInfo.Index)), nil -} - -// NewShuffledIndicesCache creates a new shuffled validators cache for storing/accessing shuffled validator indices -func NewShuffledIndicesCache() *ShuffledIndicesCache { - return &ShuffledIndicesCache{ - shuffledIndicesCache: cache.NewFIFO(shuffleKeyFn), - } -} - -// IndicesByIndexSeed fetches IndicesByIndexSeed by epoch and seed. Returns true with a -// reference to the ShuffledIndicesInEpoch info, if exists. Otherwise returns false, nil. -func (c *ShuffledIndicesCache) IndicesByIndexSeed(index uint64, seed []byte) ([]uint64, error) { - if !featureconfig.Get().EnableShuffledIndexCache { - return nil, nil - } - c.lock.RLock() - defer c.lock.RUnlock() - key := string(seed) + strconv.Itoa(int(index)) - obj, exists, err := c.shuffledIndicesCache.GetByKey(key) - if err != nil { - return nil, err - } - - if exists { - shuffledIndicesCacheHit.Inc() - } else { - shuffledIndicesCacheMiss.Inc() - return nil, nil - } - - cInfo, ok := obj.(*IndicesByIndexSeed) - if !ok { - return nil, ErrNotValidatorListInfo - } - - return cInfo.ShuffledIndices, nil -} - -// AddShuffledValidatorList adds IndicesByIndexSeed object to the cache. This method also trims the least -// recently added IndicesByIndexSeed object if the cache size has ready the max cache size limit. -func (c *ShuffledIndicesCache) AddShuffledValidatorList(shuffledIndices *IndicesByIndexSeed) error { - if !featureconfig.Get().EnableShuffledIndexCache { - return nil - } - c.lock.Lock() - defer c.lock.Unlock() - if err := c.shuffledIndicesCache.AddIfNotPresent(shuffledIndices); err != nil { - return err - } - - trim(c.shuffledIndicesCache, maxShuffledListSize) - return nil -} diff --git a/beacon-chain/cache/shuffled_indices_test.go b/beacon-chain/cache/shuffled_indices_test.go deleted file mode 100644 index da2b6fe72009..000000000000 --- a/beacon-chain/cache/shuffled_indices_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package cache - -import ( - "reflect" - "strconv" - "testing" - - "github.com/prysmaticlabs/prysm/shared/featureconfig" -) - -func init() { - fc := featureconfig.Get() - fc.EnableShuffledIndexCache = true - featureconfig.Init(fc) -} - -func TestShuffleKeyFn_OK(t *testing.T) { - sInfo := &IndicesByIndexSeed{ - Index: 999, - Seed: []byte{'A'}, - ShuffledIndices: []uint64{1, 2, 3, 4, 5}, - } - - key, err := shuffleKeyFn(sInfo) - if err != nil { - t.Fatal(err) - } - if key != string(sInfo.Seed)+strconv.Itoa(int(sInfo.Index)) { - t.Errorf("Incorrect hash key: %s, expected %s", key, string(sInfo.Seed)+strconv.Itoa(int(sInfo.Index))) - } -} - -func TestShuffleKeyFn_InvalidObj(t *testing.T) { - _, err := shuffleKeyFn("bad") - if err != ErrNotValidatorListInfo { - t.Errorf("Expected error %v, got %v", ErrNotValidatorListInfo, err) - } -} - -func TestShuffledIndicesCache_ShuffledIndicesBySeed2(t *testing.T) { - cache := NewShuffledIndicesCache() - - sInfo := &IndicesByIndexSeed{ - Index: 99, - Seed: []byte{'A'}, - ShuffledIndices: []uint64{1, 2, 3, 4}, - } - - shuffledIndices, err := cache.IndicesByIndexSeed(sInfo.Index, sInfo.Seed) - if err != nil { - t.Fatal(err) - } - if shuffledIndices != nil { - t.Error("Expected shuffled indices not to exist in empty cache") - } - - if err := cache.AddShuffledValidatorList(sInfo); err != nil { - t.Fatal(err) - } - shuffledIndices, err = cache.IndicesByIndexSeed(sInfo.Index, sInfo.Seed) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(shuffledIndices, sInfo.ShuffledIndices) { - t.Errorf( - "Expected fetched info committee to be %v, got %v", - sInfo.ShuffledIndices, - shuffledIndices, - ) - } -} - -func TestShuffledIndices_MaxSize(t *testing.T) { - cache := NewShuffledIndicesCache() - - for i := uint64(0); i < 1001; i++ { - sInfo := &IndicesByIndexSeed{ - Index: i, - Seed: []byte{byte(i)}, - } - if err := cache.AddShuffledValidatorList(sInfo); err != nil { - t.Fatal(err) - } - } - - if len(cache.shuffledIndicesCache.ListKeys()) != maxShuffledListSize { - t.Errorf( - "Expected hash cache key size to be %d, got %d", - maxShuffledListSize, - len(cache.shuffledIndicesCache.ListKeys()), - ) - } -} diff --git a/beacon-chain/core/blocks/block_operations_test.go b/beacon-chain/core/blocks/block_operations_test.go index 1734c856d145..3f7b3dedc1f7 100644 --- a/beacon-chain/core/blocks/block_operations_test.go +++ b/beacon-chain/core/blocks/block_operations_test.go @@ -502,7 +502,6 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) { func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) { // We test the case when data is correct and verify the validator // registry has been updated. - helpers.ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 100) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 942b5253eea6..5c5ce0729b68 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -15,8 +15,6 @@ import ( ) func init() { - helpers.ClearShuffledValidatorCache() - // TODO(2312): remove this and use the mainnet count. c := params.BeaconConfig() c.MinGenesisActiveValidatorCount = 16384 diff --git a/beacon-chain/core/helpers/cache.go b/beacon-chain/core/helpers/cache.go index 62fd2848566a..ffa627678468 100644 --- a/beacon-chain/core/helpers/cache.go +++ b/beacon-chain/core/helpers/cache.go @@ -4,11 +4,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/cache" ) -// ClearShuffledValidatorCache clears the shuffled indices cache from scratch. -func ClearShuffledValidatorCache() { - shuffledIndicesCache = cache.NewShuffledIndicesCache() -} - // ClearActiveCountCache restarts the active validator count cache from scratch. func ClearActiveCountCache() { activeCountCache = cache.NewActiveCountCache() @@ -28,5 +23,4 @@ func ActiveIndicesKeys() []string { func ClearAllCaches() { ClearActiveIndicesCache() ClearActiveCountCache() - ClearShuffledValidatorCache() } diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index 94843c83010d..b53974a20f4d 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -16,7 +16,6 @@ import ( "google.golang.org/grpc/status" ) -var shuffledIndicesCache = cache.NewShuffledIndicesCache() var committeeCache = cache.NewCommitteeCache() // CommitteeCountAtSlot returns the number of crosslink committees of a slot. @@ -66,7 +65,7 @@ func CommitteeCountAtSlot(state *pb.BeaconState, slot uint64) (uint64, error) { func BeaconCommittee(state *pb.BeaconState, slot uint64, index uint64) ([]uint64, error) { epoch := SlotToEpoch(slot) if featureconfig.Get().EnableNewCache { - indices, err := committeeCache.ShuffledIndices(epoch, index) + indices, err := committeeCache.ShuffledIndices(slot, index) if err != nil { return nil, errors.Wrap(err, "could not interface with committee cache") } @@ -119,15 +118,6 @@ func ComputeCommittee( start := sliceutil.SplitOffset(validatorCount, count, index) end := sliceutil.SplitOffset(validatorCount, count, index+1) - // Use cached shuffled indices list if we have seen the seed before. - cachedShuffledList, err := shuffledIndicesCache.IndicesByIndexSeed(index, seed[:]) - if err != nil { - return nil, err - } - if cachedShuffledList != nil { - return cachedShuffledList, nil - } - // Save the shuffled indices in cache, this is only needed once per epoch or once per new committee index. shuffledIndices := make([]uint64, end-start) for i := start; i < end; i++ { @@ -137,13 +127,6 @@ func ComputeCommittee( } shuffledIndices[i-start] = indices[permutedIndex] } - if err := shuffledIndicesCache.AddShuffledValidatorList(&cache.IndicesByIndexSeed{ - Index: index, - Seed: seed[:], - ShuffledIndices: shuffledIndices, - }); err != nil { - return []uint64{}, errors.Wrap(err, "could not add shuffled indices list to cache") - } return shuffledIndices, nil } @@ -319,7 +302,7 @@ func UpdateCommitteeCache(state *pb.BeaconState) error { if err != nil { return err } - count, err := CommitteeCountAtSlot(state, state.Slot) + count, err := CommitteeCountAtSlot(state, epoch*params.BeaconConfig().SlotsPerEpoch) if err != nil { return err } diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index d9db33c12f2a..1b1ee7fe2396 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -75,55 +75,6 @@ func TestComputeCommittee_WithoutCache(t *testing.T) { } } -func TestComputeCommittee_WithCache(t *testing.T) { - fc := featureconfig.Get() - fc.EnableShuffledIndexCache = true - featureconfig.Init(fc) - defer featureconfig.Init(nil) - - // Create 10 committees - committeeCount := uint64(10) - validatorCount := committeeCount * params.BeaconConfig().TargetCommitteeSize - validators := make([]*ethpb.Validator, validatorCount) - for i := 0; i < len(validators); i++ { - validators[i] = ðpb.Validator{ - ExitEpoch: params.BeaconConfig().FarFutureEpoch, - } - } - - state := &pb.BeaconState{ - Validators: validators, - Slot: 200, - RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), - } - - epoch := CurrentEpoch(state) - indices, err := ActiveValidatorIndices(state, epoch) - if err != nil { - t.Fatal(err) - } - seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) - if err != nil { - t.Fatal(err) - } - - // Test shuffled indices are correct for index 3 committee - index := uint64(3) - committee3, err := ComputeCommittee(indices, seed, index, committeeCount) - if err != nil { - t.Errorf("could not compute committee: %v", err) - } - - cachedIndices, err := shuffledIndicesCache.IndicesByIndexSeed(index, seed[:]) - if err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(cachedIndices, committee3) { - t.Error("committee has different shuffled indices") - } -} - func TestAttestationParticipants_NoCommitteeCache(t *testing.T) { committeeSize := uint64(16) validators := make([]*ethpb.Validator, committeeSize*params.BeaconConfig().SlotsPerEpoch) @@ -530,7 +481,6 @@ func TestUpdateCommitteeCache_CanUpdate(t *testing.T) { } func BenchmarkComputeCommittee300000_WithPreCache(b *testing.B) { - ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 300000) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ @@ -568,7 +518,6 @@ func BenchmarkComputeCommittee300000_WithPreCache(b *testing.B) { } func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) { - ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 3000000) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ @@ -606,7 +555,6 @@ func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) { } func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) { - ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 128000) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ @@ -645,7 +593,6 @@ func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) { } func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) { - ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 1000000) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ @@ -684,7 +631,6 @@ func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) { } func BenchmarkComputeCommittee4000000_WithOutCache(b *testing.B) { - ClearShuffledValidatorCache() validators := make([]*ethpb.Validator, 4000000) for i := 0; i < len(validators); i++ { validators[i] = ðpb.Validator{ diff --git a/beacon-chain/gateway/gateway.go b/beacon-chain/gateway/gateway.go index 0b0e84d88ccb..640cc435873d 100644 --- a/beacon-chain/gateway/gateway.go +++ b/beacon-chain/gateway/gateway.go @@ -46,8 +46,8 @@ func (g *Gateway) Start() { } g.conn = conn - - gwmux := gwruntime.NewServeMux(gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.JSONPb{OrigName:false})) + + gwmux := gwruntime.NewServeMux(gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.JSONPb{OrigName: false})) for _, f := range []func(context.Context, *gwruntime.ServeMux, *grpc.ClientConn) error{ ethpb.RegisterNodeHandler, ethpb.RegisterBeaconChainHandler, diff --git a/beacon-chain/rpc/attester_server.go b/beacon-chain/rpc/attester_server.go index e5626298b2e9..c7d9b7c66e06 100644 --- a/beacon-chain/rpc/attester_server.go +++ b/beacon-chain/rpc/attester_server.go @@ -112,8 +112,8 @@ func (as *AttesterServer) RequestAttestation(ctx context.Context, req *pb.Attest } res = ðpb.AttestationData{ - Slot: req.Slot, - Index: req.CommitteeIndex, + Slot: req.Slot, + Index: req.CommitteeIndex, BeaconBlockRoot: headRoot[:], Source: headState.CurrentJustifiedCheckpoint, Target: ðpb.Checkpoint{ diff --git a/beacon-chain/rpc/attester_server_test.go b/beacon-chain/rpc/attester_server_test.go index 0ac7dc928f64..31547868b2f1 100644 --- a/beacon-chain/rpc/attester_server_test.go +++ b/beacon-chain/rpc/attester_server_test.go @@ -129,7 +129,7 @@ func TestRequestAttestation_OK(t *testing.T) { } expectedInfo := ðpb.AttestationData{ - Slot: 3*params.BeaconConfig().SlotsPerEpoch + 1, + Slot: 3*params.BeaconConfig().SlotsPerEpoch + 1, BeaconBlockRoot: blockRoot[:], Source: ðpb.Checkpoint{ Epoch: 2, @@ -211,7 +211,7 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) { } expectedInfo := ðpb.AttestationData{ - Slot: req.Slot, + Slot: req.Slot, BeaconBlockRoot: blockRoot[:], Source: ðpb.Checkpoint{ Epoch: helpers.SlotToEpoch(1500), diff --git a/validator/client/validator_attest.go b/validator/client/validator_attest.go index 412f259d2299..0d40becf4002 100644 --- a/validator/client/validator_attest.go +++ b/validator/client/validator_attest.go @@ -79,7 +79,6 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64, pubKey [ aggregationBitfield := bitfield.NewBitlist(uint64(len(assignment.Committee))) aggregationBitfield.SetBitAt(indexInCommittee, true) - log = log.WithField("bitfield", fmt.Sprintf("%08b", aggregationBitfield)) domain, err := v.validatorClient.DomainData(ctx, &pb.DomainRequest{Epoch: data.Target.Epoch, Domain: params.BeaconConfig().DomainBeaconAttester}) if err != nil {