Skip to content

Commit d704c77

Browse files
Require websocket URLs for the signed giga EVM proxy (#4583)
## Summary - The signed giga EVM proxy URL must be `ws` or `wss`. `http` and `https` are rejected at config parse, autobahn validation, handshake claim decode, and on the validator's own URL. - Localnet advertises `ws://<node>:8546`. The public HTTP listener on `:8545` is unchanged. - HTTP is not used for validator-to-validator proxying because the 2026-07-30 autobahn benchmark found it too unreliable at the target throughput, where one websocket per pair was enough. Whether HTTP/2 can also serve this path can be re-evaluated later. ## Test plan - [x] Scheme, handshake, router, and node setup tests via `scripts/ramtest.sh` on `sei-tendermint` utils, config, p2p, rpc/core, and node. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e29c181 commit d704c77

15 files changed

Lines changed: 122 additions & 39 deletions

‎docker/localnode/scripts/step1_configure_init.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ else
3939
NODE_IP=$(hostname -i | awk '{print $1}')
4040
fi
4141
P2P_PORT=26656 # Must match [p2p] laddr in config.toml
42-
EVMRPC_PORT=8545 # Must match the EVM RPC HTTP port (evmrpc DefaultConfig HTTPPort).
42+
EVMWS_PORT=8546 # Must match the EVM RPC WebSocket port (evmrpc DefaultConfig WSPort).
4343
echo "$SEI_NODE_ID@$NODE_IP:$P2P_PORT" >> build/generated/persistent_peers.txt
4444

4545
# Store autobahn-compatible pubkeys and address for config generation
4646
cp ~/.sei/config/validator_pubkey.txt "$NODE_DIR/" || { echo "ERROR: failed to copy validator_pubkey.txt"; exit 1; }
4747
cp ~/.sei/config/node_pubkey.txt "$NODE_DIR/" || { echo "ERROR: failed to copy node_pubkey.txt"; exit 1; }
4848
echo "$NODE_IP:$P2P_PORT" > "$NODE_DIR/autobahn_address.txt"
49-
echo "http://$NODE_IP:$EVMRPC_PORT" > "$NODE_DIR/evmrpc_url.txt"
49+
echo "ws://$NODE_IP:$EVMWS_PORT" > "$NODE_DIR/evmrpc_url.txt"
5050

5151
# Create a new account
5252
ACCOUNT_NAME="node_admin"

‎sei-tendermint/config/autobahn.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (u *URL) UnmarshalText(text []byte) error {
2121
if err != nil {
2222
return err
2323
}
24-
if err := utils.CheckHTTPURL(*parsed); err != nil {
24+
if err := utils.CheckRPCURL(*parsed); err != nil {
2525
return err
2626
}
2727
u.URL = parsed
@@ -119,7 +119,7 @@ func (fc *AutobahnFileConfig) Validate() error {
119119
if v.EVMRPC.URL == nil {
120120
return fmt.Errorf("validator %s is missing evmrpc URL", v.ValidatorKey)
121121
}
122-
if err := utils.CheckHTTPURL(*v.EVMRPC.URL); err != nil {
122+
if err := utils.CheckRPCURL(*v.EVMRPC.URL); err != nil {
123123
return fmt.Errorf("validator %s evmrpc: %w", v.ValidatorKey, err)
124124
}
125125
}

‎sei-tendermint/config/autobahn_test.go‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
func TestURLJSONReencode(t *testing.T) {
1515
want := URL{URL: &url.URL{
16-
Scheme: "https",
17-
Host: "example.com:8545",
16+
Scheme: "wss",
17+
Host: "example.com:8546",
1818
Path: "/rpc",
1919
RawQuery: "foo=bar&baz=qux",
2020
}}
@@ -28,15 +28,26 @@ func TestURLJSONReencode(t *testing.T) {
2828
require.Equal(t, want.String(), got.String())
2929
}
3030

31-
func TestURLUnmarshalRejectsNonHTTP(t *testing.T) {
32-
var got URL
33-
require.Error(t, json.Unmarshal([]byte(`"ws://example.com:8545"`), &got))
31+
func TestURLUnmarshalAcceptsWebSocket(t *testing.T) {
32+
for _, raw := range []string{"ws://example.com:8546", "wss://example.com:8546"} {
33+
var got URL
34+
require.NoError(t, json.Unmarshal([]byte(`"`+raw+`"`), &got))
35+
require.NotNil(t, got.URL)
36+
require.Equal(t, raw, got.String())
37+
}
38+
}
39+
40+
func TestURLUnmarshalRejectsNonWebSocket(t *testing.T) {
41+
for _, raw := range []string{`"http://example.com:8545"`, `"https://example.com:8545"`, `"file://localhost/rpc"`} {
42+
var got URL
43+
require.Error(t, json.Unmarshal([]byte(raw), &got))
44+
}
3445
}
3546

3647
func validAutobahnFileConfig() AutobahnFileConfig {
3748
return AutobahnFileConfig{
3849
Validators: []AutobahnValidator{{
39-
EVMRPC: URL{URL: &url.URL{Scheme: "http", Host: "localhost:8545"}},
50+
EVMRPC: URL{URL: &url.URL{Scheme: "ws", Host: "localhost:8546"}},
4051
}},
4152
MaxTxsPerBlock: 1,
4253
BlockInterval: utils.Duration(time.Second),

‎sei-tendermint/internal/p2p/conv.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func decodeGigaClaim(p *pb.Handshake) (utils.Option[gigaHandshakeClaim], error)
192192
if err != nil {
193193
return utils.None[gigaHandshakeClaim](), fmt.Errorf("EvmRpc: %w", err)
194194
}
195-
if err := utils.CheckHTTPURL(*u); err != nil {
195+
if err := utils.CheckRPCURL(*u); err != nil {
196196
return utils.None[gigaHandshakeClaim](), fmt.Errorf("EvmRpc: %w", err)
197197
}
198198
return utils.Some(gigaHandshakeClaim{

‎sei-tendermint/internal/p2p/conv_test.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ func TestDecodeGigaClaimEVMRPC(t *testing.T) {
4545
EvmRpc: &evm,
4646
}
4747
}
48-
for _, s := range []string{"http://validator.example:8545", "https://validator.example:8545"} {
48+
for _, s := range []string{
49+
"ws://validator.example:8546",
50+
"wss://validator.example:8546",
51+
} {
4952
got, err := decodeGigaClaim(claim(s))
5053
require.NoError(t, err)
5154
require.Equal(t, s, got.OrPanic("missing claim").evmRPC)
5255
}
53-
for _, s := range []string{"file://localhost/rpc", "ws://validator.example:8545", "http://", "http://u:p@validator.example:8545"} {
56+
for _, s := range []string{
57+
"http://validator.example:8545",
58+
"https://validator.example:8545",
59+
"file://localhost/rpc",
60+
"ws://",
61+
"ws://u:p@validator.example:8546",
62+
} {
5463
_, err := decodeGigaClaim(claim(s))
5564
require.Error(t, err)
5665
}
@@ -60,7 +69,7 @@ func TestDecodeGigaClaimRequiresAllFields(t *testing.T) {
6069
rng := utils.TestRng()
6170
key := atypes.GenSecretKey(rng)
6271
sig := key.SignWithTag(gigaValidatorHandshakeTag, []byte("x"))
63-
evmRPC := "http://validator.example:8545"
72+
evmRPC := "ws://validator.example:8546"
6473
full := func() *pb.Handshake {
6574
return &pb.Handshake{
6675
ValidatorAuthKey: key.Public().Bytes(),

‎sei-tendermint/internal/p2p/giga_router_common_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func TestGigaRouterCommon_RunInboundConnLearnsMemberAndClosesOnLeave(t *testing.
353353
localKey := makeKey(rng)
354354
peerKey := makeKey(rng)
355355
selfAddr := NodeAddress{NodeID: peerKey.Public().NodeID(), Hostname: "validator.example", Port: 26656}
356-
evmRPC := *utils.OrPanic1(url.Parse("http://validator.example:8545"))
356+
evmRPC := *utils.OrPanic1(url.Parse("ws://validator.example:8546"))
357357
dummy := atypes.GenSecretKey(rng)
358358
epochs := newSettledEpochs(testEpoch(1, map[atypes.PublicKey]uint64{validatorKey.Public(): 1}))
359359
genesis := map[atypes.PublicKey]GigaNodeAddr{dummy.Public(): {Key: makeKey(rng).Public()}}

‎sei-tendermint/internal/p2p/giga_router_testhelper_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (c *testNodeCfg) GigaNodeAddr() GigaNodeAddr {
200200
return GigaNodeAddr{
201201
Key: c.nodeKey.Public(),
202202
HostPort: tcp.HostPort{Hostname: c.addr.Addr().String(), Port: c.addr.Port()},
203-
EVMRPC: *utils.OrPanic1(url.Parse(fmt.Sprintf("http://%s:8545", c.addr.Addr().String()))),
203+
EVMRPC: *utils.OrPanic1(url.Parse(fmt.Sprintf("ws://%s:8546", c.addr.Addr().String()))),
204204
}
205205
}
206206

‎sei-tendermint/internal/p2p/giga_router_validator.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewGigaValidatorRouter(cfg *GigaValidatorConfig, key NodeSecretKey, dataSta
3838
if self.Key != key.Public() {
3939
return nil, fmt.Errorf("local validator node key = %v, want %v", self.Key, key.Public())
4040
}
41-
if err := utils.CheckHTTPURL(self.EVMRPC); err != nil {
41+
if err := utils.CheckRPCURL(self.EVMRPC); err != nil {
4242
return nil, fmt.Errorf("local validator %v evmrpc: %w", validatorKey, err)
4343
}
4444
selfAddr := NodeAddress{

‎sei-tendermint/internal/p2p/giga_router_validator_test.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55
"fmt"
66
"maps"
7+
"net/http/httptest"
78
"net/url"
89
"path/filepath"
10+
"strings"
911
"testing"
1012
"time"
1113

@@ -231,12 +233,18 @@ func TestGigaRouter_EvmProxy(t *testing.T) {
231233
var nodeKeys []NodeSecretKey
232234
addrs := map[atypes.PublicKey]GigaNodeAddr{}
233235
urlByValidator := map[atypes.PublicKey]url.URL{}
236+
// DialContext opens the websocket before the first call, so the URL has
237+
// to name a listener.
238+
rpcSrv := ethrpc.NewServer()
239+
t.Cleanup(rpcSrv.Stop)
240+
httpSrv := httptest.NewServer(rpcSrv.WebsocketHandler([]string{"*"}))
241+
t.Cleanup(httpSrv.Close)
242+
rpcURL := *utils.OrPanic1(url.Parse("ws" + strings.TrimPrefix(httpSrv.URL, "http")))
234243
// NewGigaRouter requires EVMRPC on every committee member in both
235244
// validator and fullnode modes.
236-
for i, validatorKey := range validatorKeys {
245+
for _, validatorKey := range validatorKeys {
237246
nodeKey := makeKey(rng)
238247
nodeKeys = append(nodeKeys, nodeKey)
239-
rpcURL := *utils.OrPanic1(url.Parse(fmt.Sprintf("http://validator-%d.example.com:8545", i)))
240248
addrs[validatorKey.Public()] = GigaNodeAddr{
241249
Key: nodeKey.Public(),
242250
HostPort: tcp.HostPort{Hostname: "127.0.0.1", Port: 26657},

‎sei-tendermint/internal/p2p/handshake.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func handshake(
7272
return nil, errGigaClaimRequiresAddr
7373
}
7474
if offering {
75-
if err := utils.CheckHTTPURL(o.EVMRPC); err != nil {
75+
if err := utils.CheckRPCURL(o.EVMRPC); err != nil {
7676
return nil, fmt.Errorf("EvmRpc: %w", err)
7777
}
7878
}

0 commit comments

Comments
 (0)