fundingmanager make waitForFundingConfirmation decrement waitgroup

Since waitForFundingConfirmation is always called in a goroutine, we
make this explicit by requireing the caller to always increment the
waitgroup before calling it.
This commit is contained in:
Johan T. Halseth 2018-09-16 10:40:10 +02:00
parent 76857dbcdc
commit ea196f6e8f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1789,11 +1789,8 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
// this process to finish (either successfully or with some // this process to finish (either successfully or with some
// error), before the fundingManager can be shut down. // error), before the fundingManager can be shut down.
f.wg.Add(1) f.wg.Add(1)
go func() { go f.waitForFundingConfirmation(completeChan, cancelChan,
defer f.wg.Done() confChan)
f.waitForFundingConfirmation(completeChan, cancelChan,
confChan)
}()
var shortChanID *lnwire.ShortChannelID var shortChanID *lnwire.ShortChannelID
var ok bool var ok bool
@ -1849,11 +1846,8 @@ func (f *fundingManager) waitForFundingWithTimeout(completeChan *channeldb.OpenC
// Add this goroutine to wait group so we can be sure that it is // Add this goroutine to wait group so we can be sure that it is
// properly stopped before the funding manager can be shut down. // properly stopped before the funding manager can be shut down.
f.wg.Add(1) f.wg.Add(1)
go func() { go f.waitForFundingConfirmation(completeChan, cancelChan,
defer f.wg.Done() waitingConfChan)
f.waitForFundingConfirmation(completeChan, cancelChan,
waitingConfChan)
}()
// On block maxHeight we will cancel the funding confirmation wait. // On block maxHeight we will cancel the funding confirmation wait.
maxHeight := completeChan.FundingBroadcastHeight + maxWaitNumBlocksFundingConf maxHeight := completeChan.FundingBroadcastHeight + maxWaitNumBlocksFundingConf
@ -1927,10 +1921,13 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
// when a channel has become active for lightning transactions. // when a channel has become active for lightning transactions.
// The wait can be canceled by closing the cancelChan. In case of success, // The wait can be canceled by closing the cancelChan. In case of success,
// a *lnwire.ShortChannelID will be passed to confChan. // a *lnwire.ShortChannelID will be passed to confChan.
//
// NOTE: This MUST be run as a goroutine.
func (f *fundingManager) waitForFundingConfirmation( func (f *fundingManager) waitForFundingConfirmation(
completeChan *channeldb.OpenChannel, cancelChan <-chan struct{}, completeChan *channeldb.OpenChannel, cancelChan <-chan struct{},
confChan chan<- *lnwire.ShortChannelID) { confChan chan<- *lnwire.ShortChannelID) {
defer f.wg.Done()
defer close(confChan) defer close(confChan)
// Register with the ChainNotifier for a notification once the funding // Register with the ChainNotifier for a notification once the funding