Commit graph

901 commits

Author SHA1 Message Date
wit liu
0d6807d15b
rpc: fix flaky test TestServerWebsocketReadLimit #32889 (#1752) 2025-11-14 20:04:09 +05:30
wit liu
d9ae317a38
all: format golang files (#1548)
Co-authored-by: wit <wit765765346@gmail>
2025-09-21 19:41:54 +08:00
Daniel Liu
ce26c34c7b
rpc: refactor read limit test #32494 (#1412)
closes #32240 #32232

The main cause for the time out is the slow json encoding of large data.
In #32240 they tried to resolve the issue by reducing the size of the
test. However as Felix pointed out, the test is still kind of confusing.

I've refactored the test so it is more understandable and have reduced
the amount of data needed to be json encoded. I think it is still
important to ensure that the default read limit is not active, so I have
retained one large (~32 MB) test case, but it's at least smaller than
the existing ~64 MB test case.

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
2025-09-03 15:44:04 +08:00
Daniel Liu
a6762110b5
rpc: add SetWebsocketReadLimit in Server #32279 (#1411)
Exposing the public method to setReadLimits for Websocket RPC to
prevent OOM.

Current, Geth Server is using a default 32MB max read limit (message
size) for websocket, which is prune to being attacked for OOM. Any one
can easily launch a client to send a bunch of concurrent large request
to cause the node to crash for OOM. One example of such script that can
easily crash a Geth node running websocket server is like this:

ec830979ac/poc.go

---------

Co-authored-by: Yiming Zang <50607998+yzang2019@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-03 15:43:14 +08:00
Daniel Liu
33b40aef2c
rpc: use reflect.TypeFor #32316 (#1410)
Co-authored-by: cui <cuiweixie@gmail.com>
2025-09-03 15:42:31 +08:00
Daniel Liu
2d36f159c7
all: update dead wiki links #32215 (#1409)
---

**Description:**
- Replaced outdated GitHub wiki links with current, official
documentation URLs.
- Removed links that redirect or are no longer relevant.
- Ensured all references point to up-to-date and reliable sources.

---

Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com>
2025-09-03 15:41:48 +08:00
Daniel Liu
eb770486f2
internal: remove unused shh and swarm modules from console #32073 (#1407)
Similar to https://github.com/ethereum/go-ethereum/pull/31856, remove
the not availabe shh, swarm modules in the console.

---------

Co-authored-by: Zhou <DanialZhouMAX@gmail.com>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-09-03 15:40:28 +08:00
Daniel Liu
5081beee0e
rpc: add method name length limit #31711 (#1406)
This change adds a limit for RPC method names to prevent potential abuse
where large method names could lead to large response sizes.

The limit is enforced in:
- handleCall for regular RPC method calls
- handleSubscribe for subscription method calls

Added tests in websocket_test.go to verify the length limit
functionality for both regular method calls and subscriptions.

---------

Co-authored-by: Matus Kysel <MatusKysel@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-03 15:39:40 +08:00
Tarun Sharma
c14f2e17aa test: Updated test cases to include MaxInt64, MinInt64 and MaxUint64, also rename testcase to TestHas0xPrefix to cover Has0xPrefix public method in hexutil package 2025-05-16 12:55:45 +04:00
Tarun Sharma
631be3cc04 refactor: Removed IsValidHexString and make has0xPrefix as public as per review comment 2025-05-16 12:33:25 +04:00
Tarun Sharma
46a301a528 test: added more table test data for TestBlockNumberJSONUnmarshal 2025-05-16 10:36:36 +04:00
Tarun Sharma
cccfefa669 test: adding test condition to mustFail=false in TestBlockNumberJSONUnmarshal for valid number input 2025-05-12 17:34:01 +04:00
Tarun Sharma
78e82ac8a9 test: updated test cases to cover hex and number support for XDPoS_getV2BlockByNumber 2025-05-09 14:32:01 +04:00
Tarun Sharma
8d0e24b2e2 api: accept both hex and decimal for block number 2025-05-08 17:57:46 +04:00
Daniel Liu
266cf85510
rpc: remove deprecated method Notifier.Closed #29162 (#1022)
Co-authored-by: Undefinedor <wanghao@imwh.net>
2025-05-06 09:44:20 +08:00
Daniel Liu
f19813e3ee
rpc: run tests in parallel #30384 (#1021)
Continuation of https://github.com/ethereum/go-ethereum/pull/30381

Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
2025-05-06 09:41:42 +08:00
Daniel Liu
d25c6f02a7
all: not copy loop var for golang v1.22 (#1020) 2025-04-29 17:27:36 +08:00
Daniel Liu
d955e17cd6
rpc: add timeout to rpc client Unsubscribe #30318 (#1019)
Fixes #30156

This adds a repro of the linked issue. I fixed it by adding a timeout
when issuing the call to unsubscribe.

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
2025-04-29 17:26:34 +08:00
Daniel Liu
4c805e5968
rpc: show more error detail for invalidMessageError #30191 (#1018)
Here we add distinct error messages for network timeouts and JSON parsing errors.
Note this specifically applies to HTTP connections serving a single RPC request.

Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-29 17:25:43 +08:00
Daniel Liu
445d9b37d3
rpc: truncate call error data logs #30028 (#1017)
Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-29 17:14:14 +08:00
Daniel Liu
84b731fc23
rpc: close Clients in tests #29512 (#1016)
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
2025-04-29 17:13:29 +08:00
Daniel Liu
fd42d8b292
rpc: implement Unwrap() for wsHandshakeError #29522 (#1015)
Co-authored-by: Marcus Baldassarre <baldassarremarcus@gmail.com>
2025-04-29 17:12:33 +08:00
Daniel Liu
c0747977e2
rpc: fix ipc max path size #29385 (#1014)
Co-authored-by: Miles Chen <fearlesschenc@gmail.com>
2025-04-29 17:11:33 +08:00
Daniel Liu
fa39dac391
rpc: fix leak by close http body #29223 (#1013) 2025-04-29 17:10:12 +08:00
Daniel Liu
656419ba14
rpc: add more test cases for arg types #29006 (#1012)
* rpc: add more test cases for arg types #29006

* rpc: add more test cases for arg types #29006

---------

Co-authored-by: Andrei Kostakov <bps@dzen.ws>
2025-04-29 17:08:05 +08:00
Daniel Liu
a4aebd5d88
rpc: fix typos (#1011) 2025-04-29 17:07:10 +08:00
Daniel Liu
35a202675d
node, rpc: add configurable HTTP request limit #28948 (#1010)
Adds a configurable HTTP request limit, and bumps the engine default

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-29 17:06:06 +08:00
lightclient
9373c71211 rpc: use stable object in notifier test #30193
This makes the test resilient to changes of types.Header -- otherwise the test needs to be
updated each time the header structure is modified.
2025-04-29 17:04:50 +08:00
Delweng
7bf5517cda rpc: improve performance of subscription notification encoding #28328
It turns out that encoding json.RawMessage is slow because
package json basically parses the message again to ensure it is valid.
We can avoid the slowdown by encoding the entire RPC notification once,
which yields a 30% speedup.
2025-04-29 17:04:50 +08:00
Daniel Liu
26a9ea539f
core, rpc: speed up tests #28461 (#1008) 2025-04-29 16:57:58 +08:00
Daniel Liu
80abc58f25
all: replace some cases of strings.SplitN with strings.Cut #28446 (#1007)
Co-authored-by: Håvard Anda Estensen <haavard.ae@gmail.com>
2025-04-28 18:07:59 +08:00
Daniel Liu
7422a13f24
rpc: use correct stringer-method for serializing BlockNumberOrHash #28358 (#1006)
The String() version of BlockNumberOrHash uses decimal for all block numbers, including negative ones used to indicate labels. Switch to using BlockNumber.String() which encodes it correctly for use in the JSON-RPC API.

Co-authored-by: Adrian Sutton <adrian@oplabs.co>
2025-04-28 18:06:35 +08:00
Daniel Liu
aa75ed2f6b
rpc: increase timeout in TestClientWebsocketPing #28371 (#1005)
Co-authored-by: Brandon Liu <lzqcn2000@126.com>
2025-04-28 18:05:48 +08:00
Daniel Liu
1dd15812f3
rpc: fix erroneous error-message in test #28227 (#1004)
Co-authored-by: hyunchel <3271191+hyunchel@users.noreply.github.com>
2025-04-28 18:04:49 +08:00
Daniel Liu
c16b1b5217
eth, rpc: add configurable option for wsMessageSizeLimit #27801 (#1003)
This change adds a configurable limit to websocket message.
---------

Co-authored-by: tylerni7 <tylerni7@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-04-28 18:02:12 +08:00
Daniel Liu
f6a5d42285
rpc: use go-winio for named pipes #27972 (#1002)
We're trying a new named pipe library, which should hopefully fix some occasional failures in CI.

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-28 17:50:26 +08:00
Daniel Liu
027b69a372
rpc: attempt to fix ping/pong logic race #27733 (#1001)
This should fix #27726. With enough load, it might happen that the SetPongHandler
callback gets invoked before the call to SetReadDeadline is made in pingLoop. When
this occurs, the socket will end up with a 30s read deadline even though it got the pong,
which will lead to a timeout.

The fix here is processing the pong on pingLoop, synchronizing with the code that
sends the ping.

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-28 17:49:37 +08:00
Daniel Liu
9d4a26d552
rpc: avoid use of cgo by hard-coding maxPathSize #27447 (#1000)
Package rpc uses cgo to find the maximum UNIX domain socket path
length. If exceeded, a warning is printed. This is the only use of cgo in this
package. It seems excessive to depend on cgo just for this warning, so
we now hard-code the usual limit for Linux instead.

---------

Co-authored-by: Koichi Shiraishi <zchee.io@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-28 17:48:07 +08:00
Daniel Liu
5e4c2cb821
rpc: add method to test for subscription support #25942 (#999)
This adds two ways to check for subscription support. First, one can now check
whether the transport method (HTTP/WS/etc.) is capable of subscriptions using
the new Client.SupportsSubscriptions method.

Second, the error returned by Subscribe can now reliably be tested using this
pattern:

    sub, err := client.Subscribe(...)
    if errors.Is(err, rpc.ErrNotificationsUnsupported) {
        // no subscription support
    }

---------

Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-28 17:46:24 +08:00
Daniel Liu
c75623ace7
rpc: add limit for batch request and response size #26681 (#998) 2025-04-28 17:00:30 +08:00
Daniel Liu
b628212d8e
rpc: change BlockNumber constant values to match ethclient #27219 (#992) 2025-04-28 10:59:34 +08:00
Daniel Liu
3ae8b8a99d
rpc, internal/cmdtest: increase timeout in tests #27083 (#991)
This change gives the cmd-tests have a bit more time to finish before getting forcibly torn down.

Co-authored-by: Delweng <delweng@gmail.com>
2025-04-28 10:47:39 +08:00
Daniel Liu
5af41b62a7
rpc: more accurate checking of handler method signatures #27287 (#990)
This changes the RPC server to ignore methods using *context.Context as parameter
and *error as return value type. Methods with such types would crash the server when
called.

Co-authored-by: Stephen Guo <stephen.fire@gmail.com>
2025-04-28 10:45:50 +08:00
Daniel Liu
e6b7ae906b
rpc: websocket should respect the HTTP_PROXY by default #27264 (#989) 2025-04-28 10:44:31 +08:00
JukLee0ira
16969b1569 rpc: fix setting client in DialHTTPWithClient #26470 2025-04-28 10:25:07 +08:00
JukLee0ira
0e84001c0b node, rpc: add JWT auth support in client #24911 2025-04-28 10:25:07 +08:00
Daniel Liu
2ad5333196
rpc: use atomic types #27214 (#988)
rpc: use atomic type

Co-authored-by: s7v7nislands <s7v7nislands@gmail.com>
2025-04-28 09:19:07 +08:00
Daniel Liu
051938ba7e
rpc: increase websocket frame size #26883 (#986)
This increases the maximum allowed message size to 32MB.

Originally submitted at https://github.com/ledgerwatch/erigon/pull/2739

example block failure: https://etherscan.io/tx/0x1317d973a55cedf9b0f2df6ea48e8077dd176f5444a3423368a46d6e4db89982#internal

Co-authored-by: Jonathan Otto <jonathan.otto@gmail.com>
2025-04-28 09:11:52 +08:00
Daniel Liu
9c5712a79c
rpc: fix off-by-one in ipc endpoint length check #26614 (#985)
This change fixes a minor flaw in the check for ipc endpoint length. The max_path_size is the max path that an ipc endpoint can have, which is 208. However, that size concerns the null-terminated pathname, so we need to account for an extra null-character too.

Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-04-28 09:10:46 +08:00
JukLee0ira
230a2f09ba
cmd/geth, node, rpc: implement jwt tokens #24364 (#993)
* cmd/geth, node, rpc: implement jwt tokens #24364

* fix
2025-04-27 18:17:09 +08:00