Commit graph

905 commits

Author SHA1 Message Date
Chen Kai
ccc771f576
Merge branch 'ethereum:master' into gethintegration 2025-02-28 12:03:43 +08:00
Martin HS
767c202e47
all: drop x/exp direct dependency (#30558)
This is a not-particularly-important "cleanliness" PR. It removes the
last remnants of the `x/exp` package, where we used the `maps.Keys`
function.

The original returned the keys in a slice, but when it became 'native'
the signature changed to return an iterator, so the new idiom is
`slices.Collect(maps.Keys(theMap))`, unless of course the raw iterator
can be used instead.

In some cases, where we previously collect into slice and then sort, we
can now instead do `slices.SortXX` on the iterator instead, making the
code a bit more concise.

This PR might be _slighly_ less optimal, because the original `x/exp`
implementation allocated the slice at the correct size off the bat,
which I suppose the new code won't.

Putting it up for discussion.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-02-27 15:53:52 +01:00
Chen Kai
df157f902d
Merge branch 'ethereum:master' into gethintegration 2025-02-25 16:50:59 +08:00
Felix Lange
9e6f924671
eth: report error from setupDiscovery at startup (#31233)
I ran into this while trying to debug a discv5 thing. I tried to disable
DNS discovery using `--discovery.dns=false`, which doesn't work.
Annoyingly, geth started anyway and discarded the error silently. I
eventually found my mistake, but it took way longer than it should have.

Also including a small change to the error message for invalid DNS URLs
here. The user actually needs to see the URL to make sense of the error.
2025-02-23 17:38:32 +01:00
Felix Lange
2a81bbaa4f
p2p/nat: remove test with default servers (#31225)
The test occasionally fails when network connectivity is bad or if it
hits the wrong server. We usually don't add tests with external network
dependency so I'm removing them.

Fixes #31220
2025-02-21 10:42:54 +08:00
Chen Kai
dba7fd79b4
Merge branch 'ethereum:master' into gethintegration 2025-02-19 15:32:24 +08:00
Felix Lange
c113e3b5b1
p2p: fix marshaling of NAT in TOML (#31192)
This fixes an issue where a nat.Interface unmarshaled from the TOML
config file could not be re-marshaled to TOML correctly.

Fixes #31183
2025-02-17 09:47:12 +01:00
Chen Kai
fb3a790d14 Merge branch 'gethmaster' into gethintegration 2025-02-17 16:12:07 +08:00
Chen Kai
22b9354494
p2p/discover: make discv5 response timeout configurable (#31119) 2025-02-11 13:52:43 +01:00
Harry Ngo
d2ca7cf9f1
p2p/discover: remove unused parameter in revalidationList.get (#31155) 2025-02-11 13:45:44 +01:00
Chen Kai
3f13894d21
Merge branch 'ethereum:master' into gethintegration 2025-02-09 22:47:52 +08:00
Felix Lange
5d97db8d03
all: update license comments and AUTHORS (#31133) 2025-02-05 23:01:17 +01:00
thinkAfCod
b1fa06e1a2 only cache talk request 2025-02-03 09:29:26 +08:00
Chen Kai
618559ee75 revert seq num to time
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2025-02-02 22:31:49 +08:00
Chen Kai
76f806d4fc Merge branch 'gethmaster' into gethinte1 2025-01-31 18:18:13 +08:00
zhen peng
75526bb8e0
p2p/nat: add stun protocol (#31064)
This implements a basic mechanism to query the node's external IP using
a STUN server. There is a built-in list of public STUN servers for convenience.
The new detection mechanism must be selected explicitly using `--nat=stun` 
and is not enabled by default in Geth.

Fixes #30881

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-01-24 16:16:02 +01:00
Chen Kai
d2edccaa5b Merge branch 'gethmaster' into gethintegration
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2025-01-22 20:03:33 +08:00
Felix Lange
218b697f05
p2p: support configuring NAT in TOML file (#31041)
This is an alternative for #27407 with a solution based on gencodec.
With the PR, one can now configure like this:

```
# config.toml
[Node.P2P]
NAT = "extip:33.33.33.33"
```

```shell
$ geth --config config.toml
...
INFO [01-17|16:37:31.436] Started P2P networking      self=enode://2290...ab@33.33.33.33:30303
```
2025-01-22 09:29:34 +01:00
Chen Kai
7c7bfe0bad
Merge branch 'ethereum:master' into gethintegration 2025-01-16 12:15:35 +08:00
georgehao
1843f27766
all: fix some typos in comments and names (#31023) 2025-01-14 14:16:15 +01:00
Chen Kai
b8283a0ae6
Merge branch 'ethereum:master' into gethintegration 2025-01-06 13:05:52 +08:00
gitglorythegreat
85ffbde427
all: use cmp.Compare (#30958) 2025-01-02 14:06:47 +01:00
Chen Kai
5650b3efb2
Merge branch 'ethereum:master' into gethintegration 2024-12-17 16:57:18 +08:00
Lucas
804d45cc2e
p2p: DNS resolution for static nodes (#30822)
Closes #23210 

# Context 
When deploying Geth in Kubernetes with ReplicaSets, we encountered two
DNS-related issues affecting node connectivity. First, during startup,
Geth tries to resolve DNS names for static nodes too early in the config
unmarshaling phase. If peer nodes aren't ready yet (which is common in
Kubernetes rolling deployments), this causes an immediate failure:


```
INFO [11-26|10:03:42.816] Starting Geth on Ethereum mainnet...
INFO [11-26|10:03:42.817] Bumping default cache on mainnet         provided=1024 updated=4096
Fatal: config.toml, line 81: (p2p.Config.StaticNodes) lookup idontexist.geth.node: no such host
``` 

The second issue comes up when pods get rescheduled to different nodes -
their IPs change but peers keep using the initially resolved IP, never
updating the DNS mapping.

This PR adds proper DNS support for enode:// URLs by deferring resolution
to connection time. It also handles DNS failures gracefully instead of failing
fatally during startup, making it work better in container environments where
IPs are dynamic and peers come and go during rollouts.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-13 12:46:12 +01:00
Chen Kai
63d9a45739
Merge branch 'ethereum:master' into gethintegration 2024-12-13 11:36:51 +08:00
lorenzo
c1c2507148
p2p: fix DiscReason encoding/decoding (#30855)
This fixes an issue where the disconnect message was not wrapped in a list.
The specification requires it to be a list like any other message.

In order to remain compatible with legacy geth versions, we now accept both
encodings when parsing a disconnect message.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-12 12:33:42 +01:00
Chen Kai
13a227a9ca Merge branch 'gethmaster' into gethintegration 2024-12-11 22:34:49 +08:00
Martin HS
9045b79bc2
metrics, cmd/geth: change init-process of metrics (#30814)
This PR modifies how the metrics library handles `Enabled`: previously,
the package `init` decided whether to serve real metrics or just
dummy-types.

This has several drawbacks: 
- During pkg init, we need to determine whether metrics are enabled or
not. So we first hacked in a check if certain geth-specific
commandline-flags were enabled. Then we added a similar check for
geth-env-vars. Then we almost added a very elaborate check for
toml-config-file, plus toml parsing.

- Using "real" types and dummy types interchangeably means that
everything is hidden behind interfaces. This has a performance penalty,
and also it just adds a lot of code.

This PR removes the interface stuff, uses concrete types, and allows for
the setting of Enabled to happen later. It is still assumed that
`metrics.Enable()` is invoked early on.

The somewhat 'heavy' operations, such as ticking meters and exp-decay,
now checks the enable-flag to prevent resource leak.

The change may be large, but it's mostly pretty trivial, and from the
last time I gutted the metrics, I ensured that we have fairly good test
coverage.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-10 13:27:29 +01:00
Chen Kai
cc783f5e7a add comment
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-10 17:11:35 +08:00
Chen Kai
8a63d44af2 make findnode public
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-10 16:31:22 +08:00
Chen Kai
fbfb4083e1 revert some change
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-10 16:16:40 +08:00
Chen Kai
0f8cc5fcd2 add waitinit
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-10 14:33:42 +08:00
Chen Kai
5095282864 revert table modification
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-10 14:13:18 +08:00
thinkAfCod
c3669fd24c use lru cache to replace map 2024-12-09 22:18:26 +08:00
Chen Kai
6b4dc095e7 make some comment with discv5 modification
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-12-09 16:47:18 +08:00
Chen Kai
ee11806dd7 feat:migrate and remove portal wire in p2p package
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-11-26 12:19:30 +08:00
Chen Kai
71d8f7a842 feat:make portal wire out of p2p package
Signed-off-by: Chen Kai <281165273grape@gmail.com>
2024-11-20 22:19:37 +08:00
thinkAfCod
8bb4364475 fix: utp initial in test case 2024-11-19 12:12:02 +08:00
thinkAfCod
c394b097a5 fix: upgrade utp-go 2024-11-19 12:12:02 +08:00
thinkAfCod
caa38955fd fix: abstract utp socket and remove timeout nonce 2024-11-19 12:12:02 +08:00
rafaelss
dbd18558ec replace wrong connecitonId variable 2024-11-19 12:12:02 +08:00
rafaelss
80e20e6386 fixes go test 2024-11-19 12:12:02 +08:00
thinkAfCod
685123294b fix: connection memory leak 2024-11-19 12:12:02 +08:00
Chen Kai
e6f3769e93
Merge branch 'ethereum:master' into portal 2024-11-12 22:16:08 +07:00
tianyeyouyou
ae83912841
p2p/netutil: unittests for addrutil (#30439)
add unit tests for `p2p/addrutil`

---------

Co-authored-by: Martin HS <martin@swende.se>
2024-11-11 11:43:22 +01:00
Chen Kai
5111deac1d revert ssz generated file 2024-10-30 22:52:15 +08:00
Chen Kai
17e5c9ef83 Merge branch 'gethmaster' into selfportal 2024-10-30 22:39:43 +08:00
thinkAfCod
8a5c2d5340 fix: concurrent map read and writes 2024-10-30 20:58:17 +08:00
thinkAfCod
a75e981c5b fix: replace assert to require 2024-10-23 23:59:03 +08:00
Chen Kai
8563ce1d52 add wait discv5 table 2024-10-23 16:52:52 +08:00