Closed twoeths closed 2 years ago
there are too many connected peers too
looks like there are some peers disconnected without calling GossipSub.removePeer()
properly
Expected:
It seems that this library relies on the registrar properly registering a peer to this protocol in order for both the onPeerDisconnected and onPeerConnected routines to be triggered. So if we get an inbound-negotiated stream with a peer and libp2p doesn't successfully get a response from the identify protocol, then the registrar won't call onPeerDisconnected for that peer. Likewise, if we connect to a peer, but don't get a response from the identify protocol, then we won't initiate a gossipsub stream with that peer (unless that peer opens a gossipsub stream).
I think for the purposes of networks that do not necessarily support the identify protocol (eg: ethereum network) we need the following:
// in gossipsub
connectionManager.addEventListener('peer:disconnect', this.onPeerDisconnected.bind(this))
// in the application
const stream = await libp2p.dialProtocol(peerId, gossipsubProtocol)
gossip.addOutboundStream(peerId, stream)
@wemeetagain I don't see this issue happen in the current version of lodestar, do you know how does this work earlier (pre v3.x)?
old version of libp2p would trigger onDisconnect to all peers
https://github.com/libp2p/js-libp2p/blob/v0.36.2/src/registrar.js#L54 https://github.com/libp2p/js-libp2p/blob/v0.36.2/src/registrar.js#L122
Current version checks the protoBook, only calls onDisconnect for protocols that are registered to the peer https://github.com/libp2p/js-libp2p/blob/master/src/registrar.ts#L152
this issue could be the reason why memory keeps growing since the pushable
inside OutboundStream
stores a lot of internal buffers inside, see https://github.com/ChainSafe/js-libp2p-gossipsub/pull/314
resolved in latest libp2p + gossipsub
Description There are only 21 peers
But it showed a lot of topic peers
Quick debug