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.
This commit is contained in:
Johan T. Halseth 2018-07-26 15:11:53 +02:00
parent c48ecb85f6
commit 8865bcf3d9
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1351,6 +1351,10 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) {
return 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, // If something goes wrong before the funding transaction is confirmed,
// we use this convenience method to delete the pending OpenChannel // we use this convenience method to delete the pending OpenChannel
// from the database. // 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 // At this point we have sent our last funding message to the
// initiating peer before the funding transaction will be broadcast. // 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. // With this last message, our job as the responder is now complete.
// We'll wait for the funding transaction to reach the specified number // We'll wait for the funding transaction to reach the specified number
// of confirmations, then start normal operations. // of confirmations, then start normal operations.
@ -1473,8 +1472,6 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) {
} }
// Success, funding transaction was confirmed. // Success, funding transaction was confirmed.
f.deleteReservationCtx(peerKey, fmsg.msg.PendingChannelID)
err := f.handleFundingConfirmation( err := f.handleFundingConfirmation(
fmsg.peer, completeChan, shortChanID, fmsg.peer, completeChan, shortChanID,
) )
@ -1549,6 +1546,10 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
return 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, // 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 // 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 // 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 // At this point we have broadcast the funding transaction and done all
// necessary processing. The only thing left to do before we can delete // necessary processing.
// this reservation is wait for the funding transaction. Lock the
// reservation so it is not pruned by the zombie sweeper.
resCtx.lock()
f.wg.Add(1) f.wg.Add(1)
go func() { go func() {
defer f.wg.Done() defer f.wg.Done()
@ -1659,8 +1656,6 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
}, },
} }
f.deleteReservationCtx(peerKey, pendingChanID)
err = f.annAfterSixConfs(completeChan, shortChanID) err = f.annAfterSixConfs(completeChan, shortChanID)
if err != nil { if err != nil {
fndgLog.Errorf("failed sending channel announcement: %v", fndgLog.Errorf("failed sending channel announcement: %v",