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.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-07 22:38:46 -08:00
parent 60f66fe2d7
commit e0c09a016b
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 5 additions and 6 deletions

@ -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)
}

@ -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.

@ -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)