From 63ee31b83feed801d63eae6add7603601f1d7b25 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Fri, 23 Feb 2018 00:13:05 +0000 Subject: [PATCH] fundingmanager: Added additional check so that pending channels don't timeout for the channel initiator --- fundingmanager.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index ace5ea05..fcd8d7ce 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -430,19 +430,23 @@ func (f *fundingManager) Start() error { select { case <-timeoutChan: - // Timeout waiting for the funding transaction - // to confirm, so we forget the channel and - // delete it from the database. + // Timeout channel will be triggered if the number of blocks + // mined since the channel was initiated reaches + // maxWaitNumBlocksFundingConf and we are not the channel + // initiator. + closeInfo := &channeldb.ChannelCloseSummary{ ChainHash: ch.ChainHash, ChanPoint: ch.FundingOutpoint, RemotePub: ch.IdentityPub, CloseType: channeldb.FundingCanceled, } + if err := ch.CloseChannel(closeInfo); err != nil { fndgLog.Errorf("Failed closing channel "+ "%v: %v", ch.FundingOutpoint, err) } + case <-f.quit: // The fundingManager is shutting down, and will // resume wait on startup. @@ -1484,10 +1488,11 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { } // waitForFundingWithTimeout is a wrapper around waitForFundingConfirmation that -// will cancel the wait for confirmation if maxWaitNumBlocksFundingConf has -// passed from bestHeight. In the case of timeout, the timeoutChan will be -// closed. In case of error, confChan will be closed. In case of success, -// a *lnwire.ShortChannelID will be passed to confChan. +// will cancel the wait for confirmation if we are not the channel initiator and +// the maxWaitNumBlocksFundingConf has passed from bestHeight. +// In the case of timeout, the timeoutChan will be closed. In case of error, +// confChan will be closed. In case of success, a *lnwire.ShortChannelID will be +// passed to confChan. func (f *fundingManager) waitForFundingWithTimeout(completeChan *channeldb.OpenChannel, confChan chan<- *lnwire.ShortChannelID, timeoutChan chan<- struct{}) { @@ -1523,7 +1528,9 @@ func (f *fundingManager) waitForFundingWithTimeout(completeChan *channeldb.OpenC return } - if uint32(epoch.Height) >= maxHeight { + // If we are not the channel initiator it's safe + // to timeout the channel + if uint32(epoch.Height) >= maxHeight && !completeChan.IsInitiator { fndgLog.Warnf("waited for %v blocks without "+ "seeing funding transaction confirmed,"+ " cancelling.", maxWaitNumBlocksFundingConf) @@ -1536,6 +1543,11 @@ func (f *fundingManager) waitForFundingWithTimeout(completeChan *channeldb.OpenC close(timeoutChan) return } + + // TODO: If we are the channel initiator implement + // a method for recovering the funds from the funding + // transaction + case <-f.quit: // The fundingManager is shutting down, will resume // waiting for the funding transaction on startup.