From ccf9cd47ef965da49e462452f6ab60f46077e54e Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 30 May 2018 12:08:18 +0200 Subject: [PATCH] fundingmanager: delete empty peer in deleteReservationCtx --- fundingmanager.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index ab83a9de..b7b5af8b 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -2777,8 +2777,20 @@ func (f *fundingManager) deleteReservationCtx(peerKey *btcec.PublicKey, // channelManager? peerIDKey := newSerializedKey(peerKey) f.resMtx.Lock() - delete(f.activeReservations[peerIDKey], pendingChanID) - f.resMtx.Unlock() + defer f.resMtx.Unlock() + + nodeReservations, ok := f.activeReservations[peerIDKey] + if !ok { + // No reservations for this node. + return + } + delete(nodeReservations, pendingChanID) + + // If this was the last active reservation for this peer, delete the + // peer's entry altogether. + if len(nodeReservations) == 0 { + delete(f.activeReservations, peerIDKey) + } } // getReservationCtx returns the reservation context for a particular pending