Commit graph

13118 commits

Author SHA1 Message Date
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
57c40154be core: use atomic type #27011 2025-04-28 16:57:56 +08:00
Daniel Liu
9a06e129b8 core: simplify atomic store after writeBlockWithState #20798 2025-04-28 16:57:56 +08:00
Daniel Liu
1d3e5cb455 core: prefetch next block state concurrently #19328 2025-04-28 16:57:56 +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
b899363d17 node: set JWT expiry to 60 seconds #25416 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
e9b0bc7d74
node: ensure resp.body closed #26969 (#987) 2025-04-28 09:12:42 +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
Daniel Liu
c02ab17b17
core: use headers only where blocks are unnecessary #19261 (#984) 2025-04-28 06:46:40 +08:00
JukLee0ira
80547a50d9
cmd/geth: make authrpc listening address settable from cli #24522 (#994) 2025-04-27 19:55:03 +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
JukLee0ira
b4308ba733
internal/ethapi: disable sending of non eip155 replay protected tx #22339 (#971)
* internal/ethapi: disable sending of non eip155 replay protected tx #22339

* eth: optimize the initialization logic of EthAPIBackend

* fix
2025-04-25 11:55:52 +08:00
Daniel Liu
08dbbe705d core: fix error in block iterator #18986 2025-04-25 08:03:58 +08:00
Daniel Liu
ff435e081f core: rework blockchain import #17973 2025-04-25 08:03:58 +08:00
Daniel Liu
58e9b8c8f6
node, rpc: improve HTTP write timeout handling #25457 (#982)
Here we add special handling for sending an error response when the write timeout of the
HTTP server is just about to expire. This is surprisingly difficult to get right, since is
must be ensured that all output is fully flushed in time, which needs support from
multiple levels of the RPC handler stack:

The timeout response can't use chunked transfer-encoding because there is no way to write
the final terminating chunk. net/http writes it when the topmost handler returns, but the
timeout will already be over by the time that happens. We decided to disable chunked
encoding by setting content-length explicitly.

Gzip compression must also be disabled for timeout responses because we don't know the
true content-length before compressing all output, i.e. compression would reintroduce
chunked transfer-encoding.

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-04-25 08:01:44 +08:00
JukLee0ira
ef02abcf8f
rpc, internal/guide: speed up tests a bit #26193 (#981) 2025-04-24 22:08:58 +08:00
Daniel Liu
149beccd14
rpc: decrease websocket ping interval #26253 (#979)
This is to cater for more node providers.

Co-authored-by: Wihan de Beer <debeerwihan@gmail.com>
2025-04-24 19:09:42 +08:00
Daniel Liu
eb4240992e
rpc, internal/guide: speed up tests a bit #26193 (#978)
This removes an RPC test which takes > 90s to execute, and updates the
internal/guide tests to use lighter scrypt parameters.

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 19:08:57 +08:00
Daniel Liu
a35bc8de19
rpc: support injecting HTTP headers through context #26023 (#977)
This adds a way to specify HTTP headers per request.

Co-authored-by: storyicon <storyicon@foxmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 19:08:16 +08:00
Daniel Liu
f8eb869b08
rpc: fix connection tracking set in Server #26180 (#976)
rpc: fix connection tracking in Server

When upgrading to mapset/v2 with generics, the set element type used in
rpc.Server had to be changed to *ServerCodec because ServerCodec is not
'comparable'. While the distinction is technically correct, we know all
possible ServerCodec types, and all of them are comparable. So just use
a map instead.

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 19:07:30 +08:00
Daniel Liu
18c9efa71d
rpc: handle wrong HTTP batch response length #26064 (#975)
Co-authored-by: Jordan Krage <jmank88@gmail.com>
2025-04-24 19:06:19 +08:00
Daniel Liu
02eb1d5375
rpc: improve error codes for internal server errors #25678 (#974)
This changes the error code returned by the RPC server in certain situations:

- handler panic: code -32603
- result marshaling error: code -32603
- attempt to subscribe via HTTP: code -32001

In all of the above cases, the server previously returned the default error
code -32000.

Co-authored-by: Nicholas <nicholas.zhaoyu@gmail.com>
Co-authored-by: Nicholas Zhao <nicholas.zhao@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 19:03:29 +08:00
Daniel Liu
1d6b09394b
rpc: check that version is 2.0 in request objects #25570 (#973)
The JSON-RPC spec requires the "version" field to be exactly "2.0",
so we should verify that. This change is not backwards-compatible with
sloppy client implementations, but I decided to go ahead with it anyway
because the failure will be caught via the returned error.

Co-authored-by: Seungbae Yu <dbadoy4874@gmail.com>
2025-04-24 19:02:33 +08:00
Daniel Liu
2ce0a220a2
cmd, node, rpc: add ReadHeaderTimeout config option #25338 (#972) 2025-04-24 19:01:11 +08:00
Daniel Liu
94b3ca1eeb
all: remove version field #25096 (#970) 2025-04-24 18:55:15 +08:00
Daniel Liu
4fb622bfd0
all: remove public field from rpc.API #25059 (#969) 2025-04-24 18:53:59 +08:00
Daniel Liu
175ef934ed
rpc: remove mention of shh RPC API #25137 (#968) 2025-04-24 18:41:11 +08:00
Daniel Liu
cfd7e241c6
rpc: fix defer in test #24490 (#967) 2025-04-24 18:40:19 +08:00
Daniel Liu
716e58388f
rpc: fix godoc #24488 (#966)
Co-authored-by: s7v7nislands <s7v7nislands@gmail.com>
Co-authored-by: seven <seven@nodereal.io>
2025-04-24 18:38:38 +08:00
Daniel Liu
007314980f
rpc: set Request.GetBody for client requests #24292 (#965)
When talking to an HTTP2 server, there are situations where it needs to
"rewind" the Request.Body. To allow this, we have to set up the Request.GetBody
function to return a brand new instance of the body.

If not set, we can end up with the following error:

    http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error

See this commit for more information: cffdcf672a

Co-authored-by: Valentin Trinqué <ValentinTrinque@users.noreply.github.com>
2025-04-24 18:37:08 +08:00
Daniel Liu
d751e88fa5
internal/jsre, node, rpc: fix goroutine leaks in tests #24211 (#964) 2025-04-24 18:36:10 +08:00
Daniel Liu
e7ca47c280
rpc: fix time key collision for logger with json output #24112 (#963)
The "t" key overrides the log message time in JSON output.

Co-authored-by: Roman Mazalov <83914728+gopherxyz@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 18:35:18 +08:00
Daniel Liu
3a618f0fd2
rpc: linear time batch response matching #23856 (#962)
This avoids quadratic time complexity in the lookup of the batch element
corresponding to an RPC response. Unfortunately, the new approach
requires additional memory for the mapping from ID to index.

Fixes #22805

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 18:34:12 +08:00
Daniel Liu
de88f30b58
rpc/client: fix typo #23834 (#961)
Co-authored-by: chuwt <weitaochu@gmail.com>
2025-04-24 18:32:44 +08:00