From e9eb7e3228a941f11e56355c3f5f20786da47d48 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 16 Oct 2025 19:34:01 -0700 Subject: [PATCH] Fix sync committee subscription to use subnet indices instead of committee indices --- beacon-chain/rpc/eth/validator/handlers.go | 13 ++++++++++++- beacon-chain/rpc/eth/validator/handlers_test.go | 5 ++--- .../ttsao_fix-sync-committee-subnet-indices.md | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changelog/ttsao_fix-sync-committee-subnet-indices.md diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index 043ad17bb851..16df7d5448ce 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -597,7 +597,18 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http. epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) * time.Second totalDuration := epochDuration * time.Duration(epochsToWatch) - cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, sub.SyncCommitteeIndices, totalDuration) + subcommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount + seen := make(map[uint64]bool) + var subnetIndices []uint64 + + for _, idx := range sub.SyncCommitteeIndices { + subnetIdx := idx / subcommitteeSize + if !seen[subnetIdx] { + seen[subnetIdx] = true + subnetIndices = append(subnetIndices, subnetIdx) + } + } + cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, subnetIndices, totalDuration) } } diff --git a/beacon-chain/rpc/eth/validator/handlers_test.go b/beacon-chain/rpc/eth/validator/handlers_test.go index 3baba284b840..d0f0d90747fd 100644 --- a/beacon-chain/rpc/eth/validator/handlers_test.go +++ b/beacon-chain/rpc/eth/validator/handlers_test.go @@ -1049,9 +1049,8 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) { s.SubmitSyncCommitteeSubscription(writer, request) assert.Equal(t, http.StatusOK, writer.Code) subnets, _, _, _ := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0) - require.Equal(t, 2, len(subnets)) + require.Equal(t, 1, len(subnets)) assert.Equal(t, uint64(0), subnets[0]) - assert.Equal(t, uint64(2), subnets[1]) }) t.Run("multiple", func(t *testing.T) { cache.SyncSubnetIDs.EmptyAllCaches() @@ -1070,7 +1069,7 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) { assert.Equal(t, uint64(0), subnets[0]) subnets, _, _, _ = cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0) require.Equal(t, 1, len(subnets)) - assert.Equal(t, uint64(2), subnets[0]) + assert.Equal(t, uint64(0), subnets[0]) }) t.Run("no body", func(t *testing.T) { request := httptest.NewRequest(http.MethodPost, "http://example.com", nil) diff --git a/changelog/ttsao_fix-sync-committee-subnet-indices.md b/changelog/ttsao_fix-sync-committee-subnet-indices.md new file mode 100644 index 000000000000..e2793410b236 --- /dev/null +++ b/changelog/ttsao_fix-sync-committee-subnet-indices.md @@ -0,0 +1,3 @@ +### Fixed + +- Fix sync committee subscription to use subnet indices instead of committee indices