Skip to content

Commit 1811aa0

Browse files
authored
node, cmd: remove dead geth-forked httpServer (erigontech#21724)
`node/rpcstack.go` carried a geth-forked `httpServer` (plus `httpConfig`/`wsConfig`/`rpcHandler`, `checkPath`, and a package-local `isWebsocket`) that is never constructed outside tests — `newHTTPServer` has no non-test callers. Erigon's actual HTTP/WS serving lives in `cmd/rpcdaemon/cli` (`createHandler` + `node.StartHTTPEndpoint`). This removes the dead closure and its never-wired configuration: - `node/rpcstack.go`: drop `httpServer` and friends (−331 lines). The live exports (`NewHTTPHandlerStack`, `NewWSConnectionLimiter`, `RegisterApisFromWhitelist`, and the CORS/vhost/gzip/admission middleware) are untouched. - `cmd/utils/flags.go`: drop `--http.rpcprefix` / `--ws.rpcprefix` flag definitions — never registered with any command. - `node/nodecfg/config.go`: drop the corresponding `HTTPPathPrefix` / `WSPathPrefix` fields — never read. Tests previously used the dead `httpServer` as a harness around live middleware; they are rewritten to target the live constructors directly: - CORS/vhosts/allowlist tests now run `httptest.Server` around `NewHTTPHandlerStack`. - WebSocket origin and connection-limit tests use `rpc.Server.WebsocketHandler` + `NewWSConnectionLimiter`. - `TestHTTP2H2C` now exercises the production `StartHTTPEndpoint` h2c path (x/net h2c) instead of the dead server's `http.Protocols` wiring, so h2c support is finally asserted on a server erigon actually runs. - `TestIsWebsocket` moves to `cmd/rpcdaemon/cli`, which has the live (previously untested) `isWebsocket` copy. - `Test_checkPath` is deleted along with `checkPath`. Supersedes erigontech#21714: the WS status-code bug fixed there lives in the removed, unreachable `httpServer.ServeHTTP`. The corresponding upstream fix is ethereum/go-ethereum#35111, which remains correct in geth where this code is live. Pure dead-code removal, no behavior change — per the repo TDD guidance the rewritten existing tests are the safety net. Verified locally: `make lint` (twice) clean, `go test ./node/ ./cmd/rpcdaemon/cli/` green, `make erigon integration` builds. Possible follow-up (out of scope here): most of the geth-inherited HTTP/WS block in `nodecfg.Config` (`HTTPHost`, `HTTPPort`, `HTTPCors`, `HTTPModules`, `WSHost`, `WSPort`, `WSOrigins`, `WSModules`, `WSExposeAll`) also has no non-test readers.
1 parent 5a7c7ad commit 1811aa0

5 files changed

Lines changed: 71 additions & 479 deletions

File tree

cmd/rpcdaemon/cli/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,28 @@
1717
package cli
1818

1919
import (
20+
"net/http"
2021
"net/url"
2122
"testing"
2223

2324
"github.com/stretchr/testify/require"
2425
)
2526

27+
// TestIsWebsocket tests if an incoming websocket upgrade request is detected properly.
28+
func TestIsWebsocket(t *testing.T) {
29+
r, _ := http.NewRequest("GET", "/", nil)
30+
31+
require.False(t, isWebsocket(r))
32+
r.Header.Set("upgrade", "websocket")
33+
require.False(t, isWebsocket(r))
34+
r.Header.Set("connection", "upgrade")
35+
require.True(t, isWebsocket(r))
36+
r.Header.Set("connection", "upgrade,keep-alive")
37+
require.True(t, isWebsocket(r))
38+
r.Header.Set("connection", " UPGRADE,keep-alive")
39+
require.True(t, isWebsocket(r))
40+
}
41+
2642
func TestParseSocketUrl(t *testing.T) {
2743
t.Run("sock", func(t *testing.T) {
2844
socketUrl, err := url.Parse("unix:///some/file/path.sock")

cmd/utils/flags.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,6 @@ var (
470470
Value: 200,
471471
}
472472

473-
HTTPPathPrefixFlag = cli.StringFlag{
474-
Name: "http.rpcprefix",
475-
Usage: "HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths.",
476-
Value: "",
477-
}
478473
TLSFlag = cli.BoolFlag{
479474
Name: "tls",
480475
Usage: "Enable TLS handshake",
@@ -518,11 +513,6 @@ var (
518513
Usage: "Origins from which to accept websockets requests",
519514
Value: "",
520515
}
521-
WSPathPrefixFlag = cli.StringFlag{
522-
Name: "ws.rpcprefix",
523-
Usage: "HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths.",
524-
Value: "",
525-
}
526516
WSSubscribeLogsChannelSize = cli.IntFlag{
527517
Name: "ws.api.subscribelogs.channelsize",
528518
Usage: "Size of the channel used for websocket logs subscriptions",

node/nodecfg/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ type Config struct {
113113
// interface.
114114
HTTPTimeouts rpccfg.HTTPTimeouts
115115

116-
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
117-
HTTPPathPrefix string `toml:",omitempty"`
118-
119116
// WSHost is the host interface on which to start the websocket RPC server. If
120117
// this field is empty, no websocket API endpoint will be started.
121118
WSHost string
@@ -125,9 +122,6 @@ type Config struct {
125122
// ephemeral nodes).
126123
WSPort int `toml:",omitempty"`
127124

128-
// WSPathPrefix specifies a path prefix on which ws-rpc is to be served.
129-
WSPathPrefix string `toml:",omitempty"`
130-
131125
// WSOrigins is the list of domain to accept websocket requests from. Please be
132126
// aware that the server can only act upon the HTTP request the client sends and
133127
// cannot verify the validity of the request header.

0 commit comments

Comments
 (0)