Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ linters:
- prealloc
- reassign
- govet
- makezero
- errchkjson
- noctx
disable:
- testifylint
- errchkjson #TODO: enable me
- makezero #TODO: enable me
- noctx #TODO: enable me
- errorlint #TODO: enable me
- unused #TODO: enable me
- contextcheck
Expand Down
12 changes: 6 additions & 6 deletions cl/beacon/beaconhttp/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestHandleEndpoint_SetsEthConsensusVersionHeaderFromBodyVersion(t *testing.
return NewBeaconResponse(map[string]any{"ok": true}).WithVersion(clparams.DenebVersion), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
rr := httptest.NewRecorder()
h(rr, req)

Expand All @@ -47,7 +47,7 @@ func TestHandleEndpoint_UsesSSZForPreferredWeightedAccept(t *testing.T) {
return NewBeaconResponse(testSSZResponse{}), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
req.Header.Set("Accept", "application/octet-stream;q=1,application/json;q=0.9")
rr := httptest.NewRecorder()
h(rr, req)
Expand All @@ -65,7 +65,7 @@ func TestHandleEndpoint_UsesJSONForPreferredSSZAcceptWhenResponseDoesNotSupportS
return NewBeaconResponse(map[string]any{"ok": true}), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
req.Header.Set("Accept", "application/octet-stream;q=1,application/json;q=0.9")
rr := httptest.NewRecorder()
h(rr, req)
Expand All @@ -91,7 +91,7 @@ func TestHandleEndpoint_RejectsSSZOnlyAcceptWhenResponseDoesNotSupportSSZ(t *tes
return NewBeaconResponse(map[string]any{"ok": true}), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
req.Header.Set("Accept", "application/octet-stream")
rr := httptest.NewRecorder()
h(rr, req)
Expand All @@ -114,7 +114,7 @@ func TestHandleEndpoint_UsesSSZWhenExactTypeBeatsWildcard(t *testing.T) {
return NewBeaconResponse(testSSZResponse{}), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
req.Header.Set("Accept", "application/octet-stream, */*")
rr := httptest.NewRecorder()
h(rr, req)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestHandleEndpoint_DoesNotOverrideEthConsensusVersionHeader(t *testing.T) {
WithVersion(clparams.DenebVersion), nil
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequestWithContext(t.Context(), "GET", "/test", http.NoBody)
rr := httptest.NewRecorder()
h(rr, req)

Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/beacontest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (s *Source) executeRemote(ctx context.Context) (json.RawMessage, int, error
}
purl.RawQuery = q.Encode()

request, err := http.NewRequest(method, strings.ReplaceAll(purl.String(), "%3F", "?"), body)
request, err := http.NewRequestWithContext(context.Background(), method, strings.ReplaceAll(purl.String(), "%3F", "?"), body)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx variable exists here

if err != nil {
return nil, 0, err
}
Expand Down
6 changes: 4 additions & 2 deletions cl/beacon/handler/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (a *ApiHandler) GetEthV1BeaconBlobs(w http.ResponseWriter, r *http.Request)
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, errors.New("block not found"))
}

indicies := []uint64{}
var indicies []uint64
commitments := block.Block.Body.GetBlobKzgCommitments()
if commitments == nil {
commitments = solid.NewStaticListSSZ[*cltypes.KZGCommitment](0, 48)
Expand All @@ -263,6 +263,7 @@ func (a *ApiHandler) GetEthV1BeaconBlobs(w http.ResponseWriter, r *http.Request)
}
} else {
// take the blobs by the versioned hashes
filtered := make([]uint64, 0, len(versionedHashes))
versionedHashesToIndex := make(map[common.Hash]uint64)
commitments.Range(func(index int, value *cltypes.KZGCommitment, length int) bool {
hash, err := utils.KzgCommitmentToVersionedHash(common.Bytes48(*value))
Expand All @@ -275,9 +276,10 @@ func (a *ApiHandler) GetEthV1BeaconBlobs(w http.ResponseWriter, r *http.Request)
for _, hash := range versionedHashes {
index, ok := versionedHashesToIndex[common.HexToHash(hash)]
if ok {
indicies = append(indicies, index)
filtered = append(filtered, index)
}
}
indicies = filtered
}

// collect the blobs
Expand Down
12 changes: 9 additions & 3 deletions cl/beacon/handler/blobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func getBeaconBlobsStatus(t *testing.T, f blobsTestFixture) int {
func requestBeaconBlobs(t *testing.T, baseURL string, f blobsTestFixture) *http.Response {
t.Helper()

resp, err := http.Get(baseURL + "/eth/v1/beacon/blobs/" + strconv.FormatUint(f.slot, 10) + "?versioned_hashes=" + f.versionedHash.Hex())
req, err := http.NewRequestWithContext(t.Context(), "GET", baseURL+"/eth/v1/beacon/blobs/"+strconv.FormatUint(f.slot, 10)+"?versioned_hashes="+f.versionedHash.Hex(), nil)
require.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
return resp
}
Expand Down Expand Up @@ -195,7 +197,9 @@ func TestBlobSidecarsResponseEnvelope(t *testing.T) {
server := httptest.NewServer(f.handler.mux)
defer server.Close()

resp, err := http.Get(server.URL + "/eth/v1/beacon/blob_sidecars/" + strconv.FormatUint(f.slot, 10))
req, err := http.NewRequestWithContext(t.Context(), "GET", server.URL+"/eth/v1/beacon/blob_sidecars/"+strconv.FormatUint(f.slot, 10), nil)
require.NoError(t, err)
resp, err := server.Client().Do(req)
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode)
Expand Down Expand Up @@ -230,7 +234,9 @@ func TestBlobSidecarsEmptyResponseEnvelope(t *testing.T) {
server := httptest.NewServer(f.handler.mux)
defer server.Close()

resp, err := http.Get(server.URL + "/eth/v1/beacon/blob_sidecars/" + strconv.FormatUint(f.slot, 10))
req, err := http.NewRequestWithContext(t.Context(), "GET", server.URL+"/eth/v1/beacon/blob_sidecars/"+strconv.FormatUint(f.slot, 10), nil)
require.NoError(t, err)
resp, err := server.Client().Do(req)
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode)
Expand Down
12 changes: 6 additions & 6 deletions cl/beacon/handler/block_production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestBlockBuilderWindowGloas(t *testing.T) {

func TestPublishBlindedBlocksRejectsGloas(t *testing.T) {
_, _, _, _, _, h, _, _, _, _ := setupTestingHandler(t, clparams.ElectraVersion, log.Root(), true)
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(nil))
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(nil))
req.Header.Set("Eth-Consensus-Version", clparams.GloasVersion.String())

_, err := h.publishBlindedBlocks(httptest.NewRecorder(), req, 2)
Expand All @@ -102,7 +102,7 @@ func TestPublishBlindedBlocksRejectsPreBellatrix(t *testing.T) {
block := cltypes.NewSignedBlindedBeaconBlock(&clparams.MainnetBeaconConfig, version)
body, err := json.Marshal(block)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Eth-Consensus-Version", version.String())

Expand All @@ -119,7 +119,7 @@ func TestPublishBlindedBlocksRejectsPreBellatrix(t *testing.T) {

func TestPublishBlindedBlocksRejectsUnsupportedContentType(t *testing.T) {
h := &ApiHandler{beaconChainCfg: &clparams.MainnetBeaconConfig}
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", nil)
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", nil)
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Eth-Consensus-Version", clparams.FuluVersion.String())

Expand All @@ -146,7 +146,7 @@ func TestPublishBlindedBlocksAcceptsEmptyFuluBuilderResponse(t *testing.T) {
block := cltypes.NewSignedBlindedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.FuluVersion)
body, err := json.Marshal(block)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("Eth-Consensus-Version", clparams.FuluVersion.String())

Expand All @@ -166,7 +166,7 @@ func TestPublishBlindedBlocksRejectsMissingPreFuluPayload(t *testing.T) {
block := cltypes.NewSignedBlindedBeaconBlock(&clparams.MainnetBeaconConfig, clparams.ElectraVersion)
body, err := json.Marshal(block)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Eth-Consensus-Version", clparams.ElectraVersion.String())

Expand Down Expand Up @@ -234,7 +234,7 @@ func TestPublishBlindedBlocksRejectsMalformedRequest(t *testing.T) {
if tc.mutateJSON != nil {
body = tc.mutateJSON(t, body)
}
req := httptest.NewRequest(http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v2/beacon/blinded_blocks", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Eth-Consensus-Version", clparams.FuluVersion.String())

Expand Down
12 changes: 6 additions & 6 deletions cl/beacon/handler/duties_proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestGetHistoricalProposerDependentRootEpochZeroReturnsGenesisRoot(t *testin
func TestGetDutiesProposerEpochZeroReturnsGenesisRootAndDuties(t *testing.T) {
db, _, _, _, _, handler, _, _, fcu, _ := setupTestingHandler(t, clparams.Phase0Version, log.Root(), true)

genesisState, err := initial_state.GetGenesisState(chainspec.MainnetChainID)
genesisState, err := initial_state.GetGenesisState(context.Background(), chainspec.MainnetChainID)
require.NoError(t, err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Context()

handler.stateReader = historical_states_reader.NewHistoricalStatesReader(handler.beaconChainCfg, nil, state_accessors.NewStaticValidatorTable(), genesisState, nil, handler.syncedData)

Expand Down Expand Up @@ -301,7 +301,7 @@ func TestGetDutiesProposerFutureEpochTooFarReturnsBadRequest(t *testing.T) {

headEpoch := postState.Slot() / handler.beaconChainCfg.SlotsPerEpoch
epoch := headEpoch + maxEpochsLookaheadForDuties + 1
request := httptest.NewRequest(http.MethodGet, "/eth/v1/validator/duties/proposer/"+strconv.FormatUint(epoch, 10), http.NoBody)
request := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/eth/v1/validator/duties/proposer/"+strconv.FormatUint(epoch, 10), http.NoBody)
recorder := httptest.NewRecorder()
handler.mux.ServeHTTP(recorder, request)
require.Equal(t, http.StatusBadRequest, recorder.Code, recorder.Body.String())
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestGetDutiesProposerEpochOverflowReturnsBadRequest(t *testing.T) {
_, _, _, _, _, handler, _, _, _, _ := setupTestingHandler(t, clparams.BellatrixVersion, log.Root(), true)

epoch := uint64(math.MaxUint64)
request := httptest.NewRequest(http.MethodGet, "/eth/v1/validator/duties/proposer/"+strconv.FormatUint(epoch, 10), http.NoBody)
request := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/eth/v1/validator/duties/proposer/"+strconv.FormatUint(epoch, 10), http.NoBody)
recorder := httptest.NewRecorder()
handler.mux.ServeHTTP(recorder, request)
require.Equal(t, http.StatusBadRequest, recorder.Code, recorder.Body.String())
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestGetAttesterDutiesEpochOverflowReturnsBadRequest(t *testing.T) {

epoch := uint64(math.MaxUint64)
body := strings.NewReader(`["0"]`)
request := httptest.NewRequest(http.MethodPost, "/eth/v1/validator/duties/attester/"+strconv.FormatUint(epoch, 10), body)
request := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v1/validator/duties/attester/"+strconv.FormatUint(epoch, 10), body)
recorder := httptest.NewRecorder()
handler.mux.ServeHTTP(recorder, request)
require.Equal(t, http.StatusBadRequest, recorder.Code, recorder.Body.String())
Expand All @@ -430,7 +430,7 @@ func TestPostPtcDutiesEpochOverflowReturnsBadRequest(t *testing.T) {

epoch := uint64(math.MaxUint64)
body := strings.NewReader(`["0"]`)
request := httptest.NewRequest(http.MethodPost, "/eth/v1/validator/duties/ptc/"+strconv.FormatUint(epoch, 10), body)
request := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/eth/v1/validator/duties/ptc/"+strconv.FormatUint(epoch, 10), body)
recorder := httptest.NewRecorder()
handler.mux.ServeHTTP(recorder, request)
require.Equal(t, http.StatusBadRequest, recorder.Code, recorder.Body.String())
Expand All @@ -446,7 +446,7 @@ func getProposerDutiesForEpoch(t *testing.T, handler *ApiHandler, epoch uint64)
func getProposerDutiesForPath(t *testing.T, handler *ApiHandler, path string) proposerDutiesResponse {
t.Helper()

request := httptest.NewRequest(http.MethodGet, path, http.NoBody)
request := httptest.NewRequestWithContext(t.Context(), http.MethodGet, path, http.NoBody)
recorder := httptest.NewRecorder()
handler.mux.ServeHTTP(recorder, request)
require.Equal(t, http.StatusOK, recorder.Code, recorder.Body.String())
Expand Down
Loading
Loading