From c823aeafab11a6ffab381fd8bce6a14590363ef0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 31 Jan 2018 13:52:21 -0800 Subject: [PATCH 1/2] funding: during funding error fail before sending Error to peer In this commit, we modify the logic executed when we decide that we need to fail a funding flow. Before this commit, if the remote party disconnected while we were attempting to fail the funding flow with an error. Then we'd never actually cancel the reservation. This meant that any inputs selected for that transaction would be locked until a restart. We fix this issue by always cancelling the reservation first, and ensuring that failure to cancel the reservation doesn't prevent us from sending the error. Partially addresses #710. --- fundingmanager.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fundingmanager.go b/fundingmanager.go index 656e728e..9e6b128b 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -676,13 +676,16 @@ func (f *fundingManager) failFundingFlow(peer *btcec.PublicKey, fndgLog.Errorf("Failing funding flow: %v", spew.Sdump(errMsg)) + if _, err := f.cancelReservationCtx(peer, tempChanID); err != nil { + fndgLog.Errorf("unable to cancel reservation: %v", err) + } + err := f.cfg.SendToPeer(peer, errMsg) if err != nil { fndgLog.Errorf("unable to send error message to peer %v", err) return } - f.cancelReservationCtx(peer, tempChanID) return } From 246c05fcd870a2779eb090a72118e2abd50aadd8 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 31 Jan 2018 14:00:01 -0800 Subject: [PATCH 2/2] lnwallet: add additional debug logging for txns during funding flows --- lnwallet/wallet.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index e96e20a6..6d3bac07 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -807,6 +807,9 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { fundingOutpoint := wire.NewOutPoint(&fundingTxID, multiSigIndex) pendingReservation.partialState.FundingOutpoint = *fundingOutpoint + walletLog.Debugf("Funding tx for ChannelPoint(%v) generated: %v", + fundingOutpoint, spew.Sdump(fundingTx)) + // Initialize an empty sha-chain for them, tracking the current pending // revocation hash (we don't yet know the preimage so we can't add it // to the chain). @@ -879,6 +882,11 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { txsort.InPlaceSort(ourCommitTx) txsort.InPlaceSort(theirCommitTx) + walletLog.Debugf("Local commit tx for ChannelPoint(%v): %v", + fundingOutpoint, spew.Sdump(ourCommitTx)) + walletLog.Debugf("Remote commit tx for ChannelPoint(%v): %v", + fundingOutpoint, spew.Sdump(theirCommitTx)) + // Record newly available information within the open channel state. chanState.FundingOutpoint = *fundingOutpoint chanState.LocalCommitment.CommitTx = ourCommitTx @@ -1181,6 +1189,11 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) { chanState.LocalCommitment.CommitTx = ourCommitTx chanState.RemoteCommitment.CommitTx = theirCommitTx + walletLog.Debugf("Local commit tx for ChannelPoint(%v): %v", + req.fundingOutpoint, spew.Sdump(ourCommitTx)) + walletLog.Debugf("Remote commit tx for ChannelPoint(%v): %v", + req.fundingOutpoint, spew.Sdump(theirCommitTx)) + channelValue := int64(pendingReservation.partialState.Capacity) hashCache := txscript.NewTxSigHashes(ourCommitTx) theirKey := pendingReservation.theirContribution.MultiSigKey