Skip to content
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

fix bug: connection with DirInbound may not have addresses in Peerstore. #316

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions ethstorage/p2p/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,27 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.EsConfig,
shards map[common.Address][]uint64
remotePeerId = conn.RemotePeer()
)
if len(n.host.Peerstore().Addrs(remotePeerId)) == 0 {
// As the node host enable NATService, which will create a new connection with another
// peer id and its Addrs will not be set to Peerstore, so if len of peer Addrs is 0,
// then ignore this connection.
log.Debug("No addresses to get shard list, return without close conn", "peer", remotePeerId)
return
}
css, err := n.Host().Peerstore().Get(remotePeerId, protocol.EthStorageENRKey)
if err != nil {
// for node which is new to the ethstorage network, and it dial the nodes which do not contain
// the new node's enr, so the nodes do not know its shard list from enr, so it needs to call
// n.RequestShardList to fetch the shard list of the new node.
remoteShardList, e := n.RequestShardList(remotePeerId)
if e != nil {
log.Debug("Get remote shard list fail", "peer", remotePeerId, "err", e.Error())
if e != nil && len(n.host.Peerstore().Addrs(remotePeerId)) == 0 {
// As the node host enable NATService, which will create a new connection with another
// peer id and its Addrs will not be set to Peerstore. So if len of peer Addrs is 0 and
// cannot get the remote node's shard list, then ignore this connection.
log.Debug("No addresses to get shard list, return without close conn", "peer", n.host.ID(), "remote peer",
remotePeerId, "Direction", conn.Stat().Direction, "remote address", conn.RemoteMultiaddr().String(), "error", e.Error())
return
} else if e != nil {
log.Debug("Get remote shard list fail", "peer", remotePeerId, "Direction", conn.Stat().Direction,
"remote address", conn.RemoteMultiaddr().String(), "err", e.Error())
conn.Close()
return
}
log.Debug("Get remote shard list success", "peer", remotePeerId, "shards", remoteShardList)
log.Debug("Get remote shard list success", "peer", remotePeerId, "shards", remoteShardList,
"Direction", conn.Stat().Direction, "remote address", conn.RemoteMultiaddr().String())
n.Host().Peerstore().Put(remotePeerId, protocol.EthStorageENRKey, remoteShardList)
shards = protocol.ConvertToShardList(remoteShardList)
} else {
Expand Down
4 changes: 2 additions & 2 deletions ethstorage/p2p/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func (notif *notifications) ListenClose(n network.Network, a ma.Multiaddr) {
}
func (notif *notifications) Connected(n network.Network, v network.Conn) {
notif.m.IncPeerCount()
notif.log.Info("Connected to peer", "peer", v.RemotePeer(), "addr", v.RemoteMultiaddr())
notif.log.Info("Connected to peer", "peer", v.RemotePeer(), "Direction", v.Stat().Direction, "addr", v.RemoteMultiaddr())
}
func (notif *notifications) Disconnected(n network.Network, v network.Conn) {
notif.m.DecPeerCount()
notif.log.Info("Disconnected from peer", "peer", v.RemotePeer(), "addr", v.RemoteMultiaddr())
notif.log.Info("Disconnected from peer", "peer", v.RemotePeer(), "Direction", v.Stat().Direction, "addr", v.RemoteMultiaddr())
}
func (notif *notifications) OpenedStream(n network.Network, v network.Stream) {
notif.m.IncStreamCount()
Expand Down
Loading