From e0c09a016bbd1f2923306099c16c7bff83b545af Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 7 Dec 2016 22:38:46 -0800 Subject: [PATCH] lnwallet: use stored initiator bool to properly construct close tx This commit modifies the channel closing logic to remove the hard coded bools indicating which side is attempting the closure. With the recent changes, the initiator must always pay the channel closure fees. This information is recently stored on disk, therefore we can use the boolean to ensure that the closure transaction is created properly no matter who initiates the close. This fixes a bug. --- lnd_test.go | 4 ++-- lnwallet/channel.go | 5 ++--- lnwallet/interface_test.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 291e0aa71..05f11ea8c 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -900,8 +900,8 @@ func testMaxPendingChannels(net *networkHarness, t *harnessTest) { chanPoints := make([]*lnrpc.ChannelPoint, maxPendingChannels) for i, stream := range openStreams { - ctx, _ = context.WithTimeout(context.Background(), timeout) - fundingChanPoint, err := net.WaitForChannelOpen(ctx, stream) + ctxt, _ := context.WithTimeout(context.Background(), timeout) + fundingChanPoint, err := net.WaitForChannelOpen(ctxt, stream) if err != nil { t.Fatalf("error while waiting for channel open: %v", err) } diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 824588484..f13a39599 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1949,11 +1949,10 @@ func (lc *LightningChannel) InitCooperativeClose() ([]byte, *wire.ShaHash, error // been initiated. lc.status = channelClosing - // TODO(roasbeef): assumes initiator pays fees closeTx := CreateCooperativeCloseTx(lc.fundingTxIn, lc.channelState.OurBalance, lc.channelState.TheirBalance, lc.channelState.OurDeliveryScript, lc.channelState.TheirDeliveryScript, - true) + lc.channelState.IsInitiator) closeTxSha := closeTx.TxSha() // Finally, sign the completed cooperative closure transaction. As the @@ -1995,7 +1994,7 @@ func (lc *LightningChannel) CompleteCooperativeClose(remoteSig []byte) (*wire.Ms closeTx := CreateCooperativeCloseTx(lc.fundingTxIn, lc.channelState.OurBalance, lc.channelState.TheirBalance, lc.channelState.OurDeliveryScript, lc.channelState.TheirDeliveryScript, - false) + lc.channelState.IsInitiator) // With the transaction created, we can finally generate our half of // the 2-of-2 multi-sig needed to redeem the funding output. diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 868cb1d2f..4eaeab136 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -496,7 +496,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, wallet *lnwallet bobCloseTx := lnwallet.CreateCooperativeCloseTx(fundingTxIn, chanInfo.RemoteBalance, chanInfo.LocalBalance, lnc.RemoteDeliveryScript, lnc.LocalDeliveryScript, - false) + true) bobSig, err := bobNode.signCommitTx(bobCloseTx, witnessScript, int64(lnc.Capacity)) if err != nil { t.Fatalf("unable to generate bob's signature for closing tx: %v", err)