From 19b2788ce8bacf9c800ffca3bffff9a2c11f81fa Mon Sep 17 00:00:00 2001 From: Tyler <122291810+0xTylerHolmes@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:23:12 -0500 Subject: [PATCH 1/4] Update linters and fix issues (#707) --- .github/workflows/lint.yml | 4 ++-- .golangci.yml | 20 +++++++++----------- server/service.go | 2 +- server/service_test.go | 22 +++++++++++----------- server/utils_test.go | 6 +++--- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 69e7b301..9ea31d4c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,10 +30,10 @@ jobs: run: go install mvdan.cc/gofumpt@v0.6.0 - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.7 + run: go install honnef.co/go/tools/cmd/staticcheck@v0.5.1 - name: Install golangci-lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1 + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 - name: Lint run: make lint diff --git a/.golangci.yml b/.golangci.yml index 64a2d5c5..548eb4d9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,11 +9,10 @@ linters: - gocritic - godot - godox - - gomnd - lll + - mnd - nlreturn - nonamedreturns - - nosnakecase - paralleltest - testpackage - varnamelen @@ -40,20 +39,19 @@ linters: - contextcheck - rowserrcheck - sqlclosecheck - - structcheck - wastedassign # # Disabled because deprecated: # - - deadcode - - exhaustivestruct - - golint - - ifshort - - interfacer - - maligned - - scopelint - - varcheck + - copyloopvar + + # + # Disabled due to versioning: + # + - intrange + - exportloopref + linters-settings: gofumpt: diff --git a/server/service.go b/server/service.go index bdfc929e..aa0c3903 100644 --- a/server/service.go +++ b/server/service.go @@ -230,7 +230,7 @@ func (m *BoostService) handleRoot(w http.ResponseWriter, _ *http.Request) { // handleStatus sends calls to the status endpoint of every relay. // It returns OK if at least one returned OK, and returns error otherwise. func (m *BoostService) handleStatus(w http.ResponseWriter, _ *http.Request) { - w.Header().Set(HeaderKeyVersion, config.Version) + w.Header().Set(HeaderKeyVersion, config.Version) //nolint:canonicalheader // we use a non-canonical header if !m.relayCheck || m.CheckRelays() > 0 { m.respondOK(w, nilResponse) } else { diff --git a/server/service_test.go b/server/service_test.go index 65a20324..7c0cfb7a 100644 --- a/server/service_test.go +++ b/server/service_test.go @@ -206,7 +206,7 @@ func TestStatus(t *testing.T) { rr := backend.request(t, http.MethodGet, path, nil) require.Equal(t, http.StatusOK, rr.Code) - require.Greater(t, len(rr.Header().Get("X-MEVBoost-Version")), 0) //nolint:testifylint + require.NotEmpty(t, rr.Header().Get("X-MEVBoost-Version")) //nolint:canonicalheader // we use a non-canonical header require.Equal(t, 1, backend.relays[0].GetRequestCount(path)) }) @@ -218,7 +218,7 @@ func TestStatus(t *testing.T) { rr := backend.request(t, http.MethodGet, path, nil) require.Equal(t, http.StatusServiceUnavailable, rr.Code) - require.Greater(t, len(rr.Header().Get("X-MEVBoost-Version")), 0) //nolint:testifylint + require.NotEmpty(t, rr.Header().Get("X-MEVBoost-Version")) //nolint:canonicalheader // we use a non-canonical header require.Equal(t, 0, backend.relays[0].GetRequestCount(path)) }) } @@ -269,7 +269,7 @@ func TestRegisterValidator(t *testing.T) { w.WriteHeader(http.StatusBadRequest) }) rr = backend.request(t, http.MethodPost, path, payload) - require.Equal(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadGateway, rr.Code) require.Equal(t, 3, backend.relays[0].GetRequestCount(path)) require.Equal(t, 3, backend.relays[1].GetRequestCount(path)) @@ -283,7 +283,7 @@ func TestRegisterValidator(t *testing.T) { // Now make the relay return slowly, mev-boost should return an error backend.relays[0].ResponseDelay = 180 * time.Millisecond rr = backend.request(t, http.MethodPost, path, payload) - require.Equal(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadGateway, rr.Code) require.Equal(t, 2, backend.relays[0].GetRequestCount(path)) }) @@ -398,7 +398,7 @@ func TestGetHeader(t *testing.T) { backend := newTestBackend(t, 1, time.Second) rr := backend.request(t, http.MethodGet, invalidSlotPath, nil) - require.Equal(t, `{"code":400,"message":"invalid slot"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":400,"message":"invalid slot"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadRequest, rr.Code, rr.Body.String()) require.Equal(t, 0, backend.relays[0].GetRequestCount(path)) }) @@ -408,7 +408,7 @@ func TestGetHeader(t *testing.T) { backend := newTestBackend(t, 1, time.Second) rr := backend.request(t, http.MethodGet, invalidPubkeyPath, nil) - require.Equal(t, `{"code":400,"message":"invalid pubkey"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":400,"message":"invalid pubkey"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadRequest, rr.Code, rr.Body.String()) require.Equal(t, 0, backend.relays[0].GetRequestCount(path)) }) @@ -418,7 +418,7 @@ func TestGetHeader(t *testing.T) { backend := newTestBackend(t, 1, time.Second) rr := backend.request(t, http.MethodGet, invalidSlotPath, nil) - require.Equal(t, `{"code":400,"message":"invalid hash"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":400,"message":"invalid hash"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadRequest, rr.Code, rr.Body.String()) require.Equal(t, 0, backend.relays[0].GetRequestCount(path)) }) @@ -667,7 +667,7 @@ func TestGetPayload(t *testing.T) { rr = backend.request(t, http.MethodPost, path, payload) require.Equal(t, 1, backend.relays[0].GetRequestCount(path)) require.Equal(t, 1, backend.relays[1].GetRequestCount(path)) - require.Equal(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadGateway, rr.Code, rr.Body.String()) }) @@ -682,7 +682,7 @@ func TestGetPayload(t *testing.T) { } else { w.WriteHeader(http.StatusInternalServerError) _, err := w.Write([]byte(`{"code":500,"message":"internal server error"}`)) - require.NoError(t, err) + require.NoError(t, err, "failed to write error response") //nolint:testifylint // if we fail here the test is compromised } count++ }) @@ -704,12 +704,12 @@ func TestGetPayload(t *testing.T) { } else { w.WriteHeader(http.StatusInternalServerError) _, err := w.Write([]byte(`{"code":500,"message":"internal server error"}`)) - require.NoError(t, err) + require.NoError(t, err, "failed to write error response") //nolint:testifylint // if we fail here the test is compromised } }) rr := backend.request(t, http.MethodPost, path, payload) require.Equal(t, 5, backend.relays[0].GetRequestCount(path)) - require.Equal(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) + require.JSONEq(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String()) require.Equal(t, http.StatusBadGateway, rr.Code, rr.Body.String()) }) } diff --git a/server/utils_test.go b/server/utils_test.go index cfb89abb..e59ffc42 100644 --- a/server/utils_test.go +++ b/server/utils_test.go @@ -46,7 +46,7 @@ func TestSendHTTPRequestUserAgent(t *testing.T) { customUA := "test-user-agent" expectedUA := fmt.Sprintf("mev-boost/%s %s", config.Version, customUA) ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { - require.Equal(t, expectedUA, r.Header.Get("User-Agent")) + require.Equal(t, expectedUA, r.Header.Get("User-Agent")) //nolint:testifylint // if we fail here the test has failed done <- true })) code, err := SendHTTPRequest(context.Background(), *http.DefaultClient, http.MethodGet, ts.URL, UserAgent(customUA), nil, nil, nil) @@ -58,7 +58,7 @@ func TestSendHTTPRequestUserAgent(t *testing.T) { // Test without custom UA expectedUA = fmt.Sprintf("mev-boost/%s", config.Version) ts = httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { - require.Equal(t, expectedUA, r.Header.Get("User-Agent")) + require.Equal(t, expectedUA, r.Header.Get("User-Agent")) //nolint:testifylint // if we fail here the test has failed done <- true })) code, err = SendHTTPRequest(context.Background(), *http.DefaultClient, http.MethodGet, ts.URL, "", nil, nil, nil) @@ -77,7 +77,7 @@ func TestSendHTTPRequestGzip(t *testing.T) { require.NoError(t, zw.Close()) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, "gzip", r.Header.Get("Accept-Encoding")) + require.Equal(t, "gzip", r.Header.Get("Accept-Encoding")) //nolint:testifylint // if this fails the test is invalid w.Header().Set("Content-Encoding", "gzip") _, _ = w.Write(buf.Bytes()) })) From a953c9d3f0286ee5166aaa14a06893267b075864 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 11 Dec 2024 03:30:53 +0800 Subject: [PATCH 2/4] Update main.go (#706) --- cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index eaaa5b29..b02b5677 100644 --- a/cli/main.go +++ b/cli/main.go @@ -158,7 +158,7 @@ func setupGenesis(cmd *cli.Command) (string, uint64) { ) switch { - case cmd.Bool(customGenesisForkFlag.Name): + case cmd.IsSet(customGenesisForkFlag.Name): genesisForkVersion = cmd.String(customGenesisForkFlag.Name) case cmd.Bool(sepoliaFlag.Name): genesisForkVersion = genesisForkVersionSepolia From 6d98bd48dd995a39d5e0265c5e0d96caef7eccbc Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Wed, 11 Dec 2024 11:49:15 +0100 Subject: [PATCH 3/4] chore: add `.env.example` (#696) * chore(git): add *.env, !.env.example to .gitignore * chore: .env.example --- .env.example | 30 ++++++++++++++++++++++++++++++ .gitignore | 7 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..864bba07 --- /dev/null +++ b/.env.example @@ -0,0 +1,30 @@ +# General settings +BOOST_LISTEN_ADDR=localhost:18550 # Listen address for mev-boost server + +# Logging and debugging settings +LOG_JSON=false # Set to true to log in JSON format instead of text +DEBUG=false # Set to true to enable debug mode (shorthand for '--loglevel debug') +LOG_LEVEL=info # Log level: trace, debug, info, warn/warning, error, fatal, panic +LOG_SERVICE_TAG= # Optional: add a 'service=...' tag to all log messages +DISABLE_LOG_VERSION=false # Set to true to disable logging the version + +# Genesis settings +GENESIS_FORK_VERSION= # Custom genesis fork version (optional) +GENESIS_TIMESTAMP=-1 # Custom genesis timestamp (in unix seconds) +MAINNET=true # Set to true to use Mainnet +SEPOLIA=false # Set to true to use Sepolia network +HOLESKY=false # Set to true to use Holesky network + +# Relay settings +RELAYS= # Relay URLs: single entry or comma-separated list (scheme://pubkey@host) +RELAY_MONITORS= # Relay monitor URLs: single entry or comma-separated list (scheme://host) +MIN_BID_ETH=0 # Minimum bid to accept from a relay (in ETH) +RELAY_STARTUP_CHECK=false # Set to true to check relay status on startup and on status API call + +# Relay timeout settings (in ms) +RELAY_TIMEOUT_MS_GETHEADER=950 # Timeout for getHeader requests to the relay (in ms) +RELAY_TIMEOUT_MS_GETPAYLOAD=4000 # Timeout for getPayload requests to the relay (in ms) +RELAY_TIMEOUT_MS_REGVAL=3000 # Timeout for registerValidator requests (in ms) + +# Retry settings +REQUEST_MAX_RETRIES=5 # Maximum number of retries for a relay get payload request diff --git a/.gitignore b/.gitignore index 5a0fe029..733ea559 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,9 @@ .vscode/ /README.internal.md /validator_data.json -/build/ \ No newline at end of file +/build/ + +# Environemnt variable files +.env* +!.env.example + From c574ad25265ce00e5b483ad7a69bffb57e38e0d3 Mon Sep 17 00:00:00 2001 From: guckool Date: Wed, 11 Dec 2024 11:49:45 +0100 Subject: [PATCH 4/4] docs: fix invalid link in the document (#690) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f0b9073d..c8f5b9fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ test-cli is a utility to run through all the proposer requests against mev-boost Mergemock is fully integrated: https://github.com/protolambda/mergemock -Make sure you've setup and built mergemock first, refer to its [README](https://github.com/flashbots/mergemock#quick-start) but here's a quick setup guide: +Make sure you've setup and built mergemock first, refer to its [README](https://github.com/protolambda/mergemock/blob/master/README.md) but here's a quick setup guide: ```bash git clone https://github.com/protolambda/mergemock.git