-
Notifications
You must be signed in to change notification settings - Fork 20.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: add random nodes as discovery source in setupDiscovery #31232
Conversation
We do add discv5 into the dialer as a source, but not in the same way as v4. Since discv5 has full ENR support (i.e. all nodes are exchanged as ENRs), we can actually pre-filter the results and only try connecting to nodes which are known to support the eth protocol on the correct chain. We add the discv5 iterator as a protocol-specific peer source here: Line 410 in d103f17
The dialer should be pulling nodes from that, which should trigger a random walk. If that's not happening, we need to investigate why. |
pr #30302 added // ENRKey implements enr.Entry.
func (e enrEntry) ENRKey() string {
return "eth"
} But how can I add the ENRKey to the bootstrap nodes? devp2p doesn't have the implementation either go-ethereum/cmd/devp2p/keycmd.go Lines 128 to 139 in d103f17
|
Because of NewNodeFilter, v5 only node can't add any bootstrap nodes to peer list. I think geth should remove it. |
The "eth" ENR key is added when the node is actually running the "eth" p2p protocol. You can see how it's added in Line 385 in d103f17
If a bootstrap node is run with |
If you want to add a peer to Geth permanently, it is best to use the |
I guess what you are talking about with the |
I have a simple example to replicate the bug. Add logs diff --git a/eth/protocols/eth/discovery.go b/eth/protocols/eth/discovery.go
index 075a85b69..580c3b7ba 100644
--- a/eth/protocols/eth/discovery.go
+++ b/eth/protocols/eth/discovery.go
@@ -19,6 +19,7 @@ package eth
import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/forkid"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -72,6 +73,9 @@ func NewNodeFilter(chain *core.BlockChain) func(*enode.Node) bool {
return func(n *enode.Node) bool {
var entry enrEntry
if err := n.Load(entry); err != nil {
+ if n.IP().IsLoopback() {
+ log.Error("Failed to load ENR entry", "node", n.ID(), "ip", n.IP().String(), "err", err)
+ }
return false
}
err := filter(entry.ForkID) Start the first node $ ./build/bin/geth init --datadir ./tmp/node1 tmp/genesis.json
$ ./build/bin/geth --datadir ./tmp/node1 --discovery.v4=false --port 30303
INFO [02-25|13:56:14.814] New local node record seq=1,740,461,693,194 id=d6f17090a0b9467b ip=127.0.0.1 udp=30303 tcp=30303
INFO [02-25|13:56:14.814] Started P2P networking self=enode://d5b44c982f699e26c9ef399c016671e7a77d8bde2a811f9cf21de1e686a9b092d514e5b2283020af31efac2c878b81ddc89e7ae1a718bfc4efc003bad1624d93@127.0.0.1:30303 Start the second node $ ./build/bin/geth init --datadir ./tmp/node2 tmp/genesis.json
$ ./build/bin/geth --datadir ./tmp/node2 --discovery.v4=false --authrpc.port=8552 --port 30304 --bootnodes `./build/bin/devp2p key to-enr -ip 127.0.0.1 -udp 30303 -tcp 30303 ./tmp/node1/geth/nodekey`
ERROR[02-25|13:56:23.756] Failed to load ENR entry node=d6f17090a0b9467b ip=127.0.0.1 err="missing ENR key \"eth\"" You can see that the node2 can't connect to bootstrap node1. |
Yes, like I said, it doesn't get the correct node right away. However, the node should be tried eventually. |
It doesn't work node1
node2
they both have the valid eth enrKey, but node2 can't connect to node1 |
Well. I found the bug. ENR key "eth": rlp: interface given to Decode must be a pointer it didn't use pointer.
|
I'm not sure if it's correct, but if there is no this line for v5 only node, the node won't have any peers.