mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
peer+server: remove persistent connections for peers with no open channels remaining
This commit is contained in:
parent
0e4d350e56
commit
38b52df51f
18
peer.go
18
peer.go
@ -1692,9 +1692,6 @@ func (p *peer) fetchActiveChanCloser(chanID lnwire.ChannelID) (*channelCloser, e
|
||||
|
||||
// handleLocalCloseReq kicks-off the workflow to execute a cooperative or
|
||||
// forced unilateral closure of the channel initiated by a local subsystem.
|
||||
//
|
||||
// TODO(roasbeef): if no more active channels with peer call Remove on connMgr
|
||||
// with peerID
|
||||
func (p *peer) handleLocalCloseReq(req *htlcswitch.ChanClose) {
|
||||
chanID := lnwire.NewChanIDFromOutPoint(req.ChanPoint)
|
||||
|
||||
@ -1847,6 +1844,18 @@ func (p *peer) finalizeChanClosure(chanCloser *channelCloser) {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the persistent connection to this peer if we
|
||||
// no longer have open channels with them.
|
||||
p.activeChanMtx.Lock()
|
||||
numActiveChans := len(p.activeChannels)
|
||||
p.activeChanMtx.Unlock()
|
||||
|
||||
if numActiveChans == 0 {
|
||||
p.server.prunePersistentPeerConnection(
|
||||
p.pubKeyBytes,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -1900,6 +1909,9 @@ func (p *peer) WipeChannel(chanPoint *wire.OutPoint) error {
|
||||
if channel, ok := p.activeChannels[chanID]; ok {
|
||||
channel.Stop()
|
||||
delete(p.activeChannels, chanID)
|
||||
if len(p.activeChannels) == 0 {
|
||||
p.server.prunePersistentPeerConnection(p.pubKeyBytes)
|
||||
}
|
||||
}
|
||||
p.activeChanMtx.Unlock()
|
||||
|
||||
|
16
server.go
16
server.go
@ -1476,6 +1476,22 @@ func (s *server) establishPersistentConnections() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// prunePersistentPeerConnection removes all internal state related to
|
||||
// persistent connections to a peer within the server. This is used to avoid
|
||||
// persistent connection retries to peers we do not have any open channels with.
|
||||
func (s *server) prunePersistentPeerConnection(compressedPubKey [33]byte) {
|
||||
srvrLog.Infof("Pruning peer %x from persistent connections, number of "+
|
||||
"open channels is now zero", compressedPubKey)
|
||||
|
||||
pubKeyStr := string(compressedPubKey[:])
|
||||
|
||||
s.mu.Lock()
|
||||
delete(s.persistentPeers, pubKeyStr)
|
||||
delete(s.persistentPeersBackoff, pubKeyStr)
|
||||
s.cancelConnReqs(pubKeyStr, nil)
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
// BroadcastMessage sends a request to the server to broadcast a set of
|
||||
// messages to all peers other than the one specified by the `skips` parameter.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user