From f7c0aba9a6f8cc9252e272b64c2ecc320f2f6580 Mon Sep 17 00:00:00 2001 From: weiihann Date: Mon, 8 Jan 2024 17:50:59 +0800 Subject: [PATCH] p2p: disconnect itself will reset the disconnect list --- p2p/server.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index d9c5cc5bcf..f5fbacddf3 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -225,8 +225,9 @@ type Server struct { checkpointAddPeer chan *conn // State of run loop and listenLoop. - inboundHistory expHeap - disconnectEnodeSet map[enode.ID]struct{} + inboundHistory expHeap + disconnectEnodeSet map[enode.ID]struct{} + disconnectEnodeSetMu sync.Mutex } type peerOpFunc func(map[enode.ID]*Peer) @@ -367,6 +368,16 @@ func (srv *Server) RemovePeer(node *enode.Node) { ch chan *PeerEvent sub event.Subscription ) + + // Special case: sending a disconnect request with its own enode ID will reset the disconnect enode set + if node.ID() == srv.localnode.ID() { + srv.disconnectEnodeSetMu.Lock() + srv.disconnectEnodeSet = make(map[enode.ID]struct{}) + srv.disconnectEnodeSetMu.Unlock() + srv.log.Debug("Reset disconnect enode set") + return + } + // Disconnect the peer on the main loop. srv.doPeerOp(func(peers map[enode.ID]*Peer) { srv.dialsched.removeStatic(node) @@ -839,7 +850,9 @@ running: // A peer disconnected. d := common.PrettyDuration(mclock.Now() - pd.created) if !pd.requested && pd.err == DiscRequested { + srv.disconnectEnodeSetMu.Lock() srv.disconnectEnodeSet[pd.ID()] = struct{}{} + srv.disconnectEnodeSetMu.Unlock() } delete(peers, pd.ID()) srv.log.Debug("Removing p2p peer", "peercount", len(peers), "id", pd.ID(), "duration", d, "req", pd.requested, "err", pd.err)