adding optimistic check to /eth/v1/validator/sync_committee_contribution rest endpoint (#15022)

This commit is contained in:
james-prysm
2025-03-06 16:29:11 -06:00
committed by GitHub
parent f89afb0fbd
commit 0b6bea43a8
3 changed files with 37 additions and 2 deletions

View File

@@ -636,6 +636,16 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
ctx, span := trace.StartSpan(r.Context(), "validator.ProduceSyncCommitteeContribution")
defer span.End()
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
if isOptimistic {
httputil.HandleError(w, "Beacon node is currently syncing and not serving request on that endpoint", http.StatusServiceUnavailable)
return
}
_, index, ok := shared.UintFromQuery(w, r, "subcommittee_index", true)
if !ok {
return

View File

@@ -1584,7 +1584,8 @@ func TestProduceSyncCommitteeContribution(t *testing.T) {
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
},
},
SyncCommitteePool: syncCommitteePool,
SyncCommitteePool: syncCommitteePool,
OptimisticModeFetcher: &mockChain.ChainService{},
}
t.Run("ok", func(t *testing.T) {
url := "http://example.com?slot=1&subcommittee_index=1&beacon_block_root=0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
@@ -1672,7 +1673,8 @@ func TestProduceSyncCommitteeContribution(t *testing.T) {
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
},
},
SyncCommitteePool: syncCommitteePool,
SyncCommitteePool: syncCommitteePool,
OptimisticModeFetcher: &mockChain.ChainService{},
}
server.ProduceSyncCommitteeContribution(writer, request)
assert.Equal(t, http.StatusNotFound, writer.Code)
@@ -1680,6 +1682,26 @@ func TestProduceSyncCommitteeContribution(t *testing.T) {
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp2))
require.ErrorContains(t, "No subcommittee messages found", errors.New(writer.Body.String()))
})
t.Run("Optimistic returns 503", func(t *testing.T) {
url := "http://example.com?slot=1&subcommittee_index=1&beacon_block_root=0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
request := httptest.NewRequest(http.MethodGet, url, nil)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
syncCommitteePool = synccommittee.NewStore()
server = Server{
CoreService: &core.Service{
HeadFetcher: &mockChain.ChainService{
SyncCommitteeIndices: []primitives.CommitteeIndex{0},
},
},
SyncCommitteePool: syncCommitteePool,
OptimisticModeFetcher: &mockChain.ChainService{
Optimistic: true,
},
}
server.ProduceSyncCommitteeContribution(writer, request)
assert.Equal(t, http.StatusServiceUnavailable, writer.Code)
})
}
func TestServer_RegisterValidator(t *testing.T) {

View File

@@ -0,0 +1,3 @@
### Fixed
- /eth/v1/validator/sync_committee_contribution should check for optimistic status and return a 503 if it's optimistic.