Skip to content

Commit 0b6bea4

Browse files
authored
adding optimistic check to /eth/v1/validator/sync_committee_contribution rest endpoint (#15022)
1 parent f89afb0 commit 0b6bea4

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,16 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
636636
ctx, span := trace.StartSpan(r.Context(), "validator.ProduceSyncCommitteeContribution")
637637
defer span.End()
638638

639+
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
640+
if err != nil {
641+
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
642+
return
643+
}
644+
if isOptimistic {
645+
httputil.HandleError(w, "Beacon node is currently syncing and not serving request on that endpoint", http.StatusServiceUnavailable)
646+
return
647+
}
648+
639649
_, index, ok := shared.UintFromQuery(w, r, "subcommittee_index", true)
640650
if !ok {
641651
return

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,8 @@ func TestProduceSyncCommitteeContribution(t *testing.T) {
15841584
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
15851585
},
15861586
},
1587-
SyncCommitteePool: syncCommitteePool,
1587+
SyncCommitteePool: syncCommitteePool,
1588+
OptimisticModeFetcher: &mockChain.ChainService{},
15881589
}
15891590
t.Run("ok", func(t *testing.T) {
15901591
url := "http://example.com?slot=1&subcommittee_index=1&beacon_block_root=0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
@@ -1672,14 +1673,35 @@ func TestProduceSyncCommitteeContribution(t *testing.T) {
16721673
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
16731674
},
16741675
},
1675-
SyncCommitteePool: syncCommitteePool,
1676+
SyncCommitteePool: syncCommitteePool,
1677+
OptimisticModeFetcher: &mockChain.ChainService{},
16761678
}
16771679
server.ProduceSyncCommitteeContribution(writer, request)
16781680
assert.Equal(t, http.StatusNotFound, writer.Code)
16791681
resp2 := &structs.ProduceSyncCommitteeContributionResponse{}
16801682
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp2))
16811683
require.ErrorContains(t, "No subcommittee messages found", errors.New(writer.Body.String()))
16821684
})
1685+
t.Run("Optimistic returns 503", func(t *testing.T) {
1686+
url := "http://example.com?slot=1&subcommittee_index=1&beacon_block_root=0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
1687+
request := httptest.NewRequest(http.MethodGet, url, nil)
1688+
writer := httptest.NewRecorder()
1689+
writer.Body = &bytes.Buffer{}
1690+
syncCommitteePool = synccommittee.NewStore()
1691+
server = Server{
1692+
CoreService: &core.Service{
1693+
HeadFetcher: &mockChain.ChainService{
1694+
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
1695+
},
1696+
},
1697+
SyncCommitteePool: syncCommitteePool,
1698+
OptimisticModeFetcher: &mockChain.ChainService{
1699+
Optimistic: true,
1700+
},
1701+
}
1702+
server.ProduceSyncCommitteeContribution(writer, request)
1703+
assert.Equal(t, http.StatusServiceUnavailable, writer.Code)
1704+
})
16831705
}
16841706

16851707
func TestServer_RegisterValidator(t *testing.T) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- /eth/v1/validator/sync_committee_contribution should check for optimistic status and return a 503 if it's optimistic.

0 commit comments

Comments
 (0)