Skip to content

Commit

Permalink
core/validatorapi: propose v1 and v2 returns 404 (#3167)
Browse files Browse the repository at this point in the history
Endpoints `produce_block` and `produce_blinded_block` must return 404 explicitly to prevent processing as proxy calls. Because previously we removed these from the router.
Also, this ensures all attempts to call these endpoint will increment `core_validatorapi_request_error_total` counter. 

category: feature
ticket: #1255
  • Loading branch information
pinebit authored Jul 9, 2024
1 parent 82d6f70 commit 3b2f598
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/validatorapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ func NewRouter(ctx context.Context, h Handler, eth2Cl eth2wrap.Client, isBuilder
Handler: getValidator(h),
Methods: []string{http.MethodGet},
},
{
Name: "propose_block",
Path: "/eth/v2/validator/blocks/{slot}",
Handler: respond404(),
Methods: []string{http.MethodGet},
},
{
Name: "propose_blinded_block",
Path: "/eth/v1/validator/blinded_blocks/{slot}",
Handler: respond404(),
Methods: []string{http.MethodGet},
},
{
Name: "propose_block_v3",
Path: "/eth/v3/validator/blocks/{slot}",
Expand Down Expand Up @@ -616,6 +628,16 @@ func submitContributionAndProofs(s eth2client.SyncCommitteeContributionsSubmitte
}
}

// respond404 returns a handler function always returning http.StatusNotFound
func respond404() handlerFunc {
return func(_ context.Context, _ map[string]string, _ url.Values, _ contentType, _ []byte) (any, http.Header, error) {
return nil, nil, apiError{
StatusCode: http.StatusNotFound,
Message: "NotFound",
}
}
}

// proposeBlockV3 returns a handler function returning an unsigned BeaconBlock or BlindedBeaconBlock.
func proposeBlockV3(p eth2client.ProposalProvider, builderEnabled core.BuilderEnabled) handlerFunc {
return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) {
Expand Down
24 changes: 24 additions & 0 deletions core/validatorapi/router_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,30 @@ func TestRawRouter(t *testing.T) {

testRawRouter(t, handler, callback)
})

t.Run("propose_block returns 404", func(t *testing.T) {
handler := testHandler{}

callback := func(ctx context.Context, baseURL string) {
res, err := http.Post(baseURL+"/eth/v2/validator/blocks/123", "application/json", bytes.NewReader([]byte{}))
require.NoError(t, err)
require.Equal(t, http.StatusNotFound, res.StatusCode)
}

testRawRouter(t, handler, callback)
})

t.Run("propose_blinded_block returns 404", func(t *testing.T) {
handler := testHandler{}

callback := func(ctx context.Context, baseURL string) {
res, err := http.Post(baseURL+"/eth/v1/validator/blinded_blocks/123", "application/json", bytes.NewReader([]byte{}))
require.NoError(t, err)
require.Equal(t, http.StatusNotFound, res.StatusCode)
}

testRawRouter(t, handler, callback)
})
})

t.Run("submit bellatrix ssz proposal", func(t *testing.T) {
Expand Down

0 comments on commit 3b2f598

Please sign in to comment.