Skip to content

Commit 64ec665

Browse files
Fix sync committee subscription to use subnet indices instead of committee indices (#15885)
Co-authored-by: james-prysm <[email protected]>
1 parent fdb06ea commit 64ec665

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

beacon-chain/rpc/eth/validator/handlers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,18 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
597597
epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) * time.Second
598598
totalDuration := epochDuration * time.Duration(epochsToWatch)
599599

600-
cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, sub.SyncCommitteeIndices, totalDuration)
600+
subcommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount
601+
seen := make(map[uint64]bool)
602+
var subnetIndices []uint64
603+
604+
for _, idx := range sub.SyncCommitteeIndices {
605+
subnetIdx := idx / subcommitteeSize
606+
if !seen[subnetIdx] {
607+
seen[subnetIdx] = true
608+
subnetIndices = append(subnetIndices, subnetIdx)
609+
}
610+
}
611+
cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, subnetIndices, totalDuration)
601612
}
602613
}
603614

beacon-chain/rpc/eth/validator/handlers_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,8 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) {
10491049
s.SubmitSyncCommitteeSubscription(writer, request)
10501050
assert.Equal(t, http.StatusOK, writer.Code)
10511051
subnets, _, _, _ := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0)
1052-
require.Equal(t, 2, len(subnets))
1052+
require.Equal(t, 1, len(subnets))
10531053
assert.Equal(t, uint64(0), subnets[0])
1054-
assert.Equal(t, uint64(2), subnets[1])
10551054
})
10561055
t.Run("multiple", func(t *testing.T) {
10571056
cache.SyncSubnetIDs.EmptyAllCaches()
@@ -1070,7 +1069,7 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) {
10701069
assert.Equal(t, uint64(0), subnets[0])
10711070
subnets, _, _, _ = cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0)
10721071
require.Equal(t, 1, len(subnets))
1073-
assert.Equal(t, uint64(2), subnets[0])
1072+
assert.Equal(t, uint64(0), subnets[0])
10741073
})
10751074
t.Run("no body", func(t *testing.T) {
10761075
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fix sync committee subscription to use subnet indices instead of committee indices

0 commit comments

Comments
 (0)