ChainSafe / lodestar

🌟 TypeScript Implementation of Ethereum Consensus
https://lodestar.chainsafe.io
Apache License 2.0
1.2k stars 300 forks source link

Request peer ENR via discv5 PING on eth/v1/node/peers #3377

Open twoeths opened 3 years ago

twoeths commented 3 years ago

Describe the bug

enr field is empty when I issue this curl

curl http://127.0.0.1:4000/eth/v1/node/peers/16Uiu2HAmSFKTBw2ydr3efM5QNZRBA9LYxpCBJw8SFWtA61rAmEzp
{"data":{"peer_id":"16Uiu2HAmSFKTBw2ydr3efM5QNZRBA9LYxpCBJw8SFWtA61rAmEzp","enr":"","last_seen_p2p_address":"/ip4/137.184.110.216/tcp/38254","direction":"inbound","state":"connected"}}

Expected behavior

enr should have some value inside like in the api spec https://ethereum.github.io/beacon-APIs/#/Node/getPeer

twoeths commented 3 years ago

Using this

const keypair = createKeypairFromPeerId(conn.remotePeer);
    const nodeIdValue = nodeId(keypair.publicKey);
    const enr = network.discv5?.getKadValue(nodeIdValue);
    if (enr) {
      enrStr = enr.encodeTxt();
    }

I can only find enr of 1 per 10-15 peers. I guess one of the reasons is not all peers go through discv5, they could come from libp2p. @wemeetagain are there any apis to request enr of these peers somehow?

wemeetagain commented 3 years ago

If we know that the peer is running discv5 (and we know which port), we can issue a discv5 PING to the peer, then the PONG will include their ENR.

wemeetagain commented 1 month ago

Currently, there is no foolproof way to retrieve a peer's ENR from their peer-id+ip+tcp since we don't know their discovery port. We would need something like https://github.com/ethereum/consensus-specs/pull/3861