From 8865bcf3d961800415657dad07e9c9e77e335f84 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 26 Jul 2018 15:11:53 +0200 Subject: [PATCH] fundingmanager: delete active reservation after channel is in DB This commit makes sure we delete a pending channel from the set of activeReservations within the fundingmanager immediately after the channel is moved to the openChannelBucket in the DB. Previously we wouldn't do this before the funding tx was confirmed, making it possible that failing the funding flow at a later point would try to cancel a non-existent reservation context. --- fundingmanager.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 7753204d..796fd885 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1351,6 +1351,10 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) { return } + // The channel is marked IsPending in the database, and can be removed + // from the set of active reservations. + f.deleteReservationCtx(peerKey, fmsg.msg.PendingChannelID) + // If something goes wrong before the funding transaction is confirmed, // we use this convenience method to delete the pending OpenChannel // from the database. @@ -1420,11 +1424,6 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) { // At this point we have sent our last funding message to the // initiating peer before the funding transaction will be broadcast. - // The only thing left to do before we can delete this reservation - // is wait for the funding transaction. Lock the reservation so it - // is not pruned by the zombie sweeper. - resCtx.lock() - // With this last message, our job as the responder is now complete. // We'll wait for the funding transaction to reach the specified number // of confirmations, then start normal operations. @@ -1473,8 +1472,6 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) { } // Success, funding transaction was confirmed. - f.deleteReservationCtx(peerKey, fmsg.msg.PendingChannelID) - err := f.handleFundingConfirmation( fmsg.peer, completeChan, shortChanID, ) @@ -1549,6 +1546,10 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { return } + // The channel is now marked IsPending in the database, and we can + // delete it from our set of active reservations. + f.deleteReservationCtx(peerKey, pendingChanID) + // Now that we have a finalized reservation for this funding flow, // we'll send the to be active channel to the ChainArbitrator so it can // watch for any on-chin actions before the channel has fully @@ -1576,11 +1577,7 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { } // At this point we have broadcast the funding transaction and done all - // necessary processing. The only thing left to do before we can delete - // this reservation is wait for the funding transaction. Lock the - // reservation so it is not pruned by the zombie sweeper. - resCtx.lock() - + // necessary processing. f.wg.Add(1) go func() { defer f.wg.Done() @@ -1659,8 +1656,6 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { }, } - f.deleteReservationCtx(peerKey, pendingChanID) - err = f.annAfterSixConfs(completeChan, shortChanID) if err != nil { fndgLog.Errorf("failed sending channel announcement: %v",