lnwallet: modify CreateCloseProposal to also return the close txid and local balance
This commit is contained in:
parent
bbca53507f
commit
1604c75a9c
@ -4740,7 +4740,8 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
|
|||||||
// TODO(roasbeef): caller should initiate signal to reject all incoming HTLCs,
|
// TODO(roasbeef): caller should initiate signal to reject all incoming HTLCs,
|
||||||
// settle any in flight.
|
// settle any in flight.
|
||||||
func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
||||||
localDeliveryScript, remoteDeliveryScript []byte) ([]byte, error) {
|
localDeliveryScript []byte,
|
||||||
|
remoteDeliveryScript []byte) ([]byte, *chainhash.Hash, btcutil.Amount, error) {
|
||||||
|
|
||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
@ -4748,7 +4749,7 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
// If we've already closed the channel, then ignore this request.
|
// If we've already closed the channel, then ignore this request.
|
||||||
if lc.status == channelClosed {
|
if lc.status == channelClosed {
|
||||||
// TODO(roasbeef): check to ensure no pending payments
|
// TODO(roasbeef): check to ensure no pending payments
|
||||||
return nil, ErrChanClosing
|
return nil, nil, 0, ErrChanClosing
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract the proposed fee from the appropriate balance, taking care
|
// Subtract the proposed fee from the appropriate balance, taking care
|
||||||
@ -4777,7 +4778,7 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
// negative output.
|
// negative output.
|
||||||
tx := btcutil.NewTx(closeTx)
|
tx := btcutil.NewTx(closeTx)
|
||||||
if err := blockchain.CheckTransactionSanity(tx); err != nil {
|
if err := blockchain.CheckTransactionSanity(tx); err != nil {
|
||||||
return nil, err
|
return nil, nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, sign the completed cooperative closure transaction. As the
|
// Finally, sign the completed cooperative closure transaction. As the
|
||||||
@ -4787,14 +4788,15 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
lc.signDesc.SigHashes = txscript.NewTxSigHashes(closeTx)
|
lc.signDesc.SigHashes = txscript.NewTxSigHashes(closeTx)
|
||||||
sig, err := lc.signer.SignOutputRaw(closeTx, lc.signDesc)
|
sig, err := lc.signer.SignOutputRaw(closeTx, lc.signDesc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// As everything checks out, indicate in the channel status that a
|
// As everything checks out, indicate in the channel status that a
|
||||||
// channel closure has been initiated.
|
// channel closure has been initiated.
|
||||||
lc.status = channelClosing
|
lc.status = channelClosing
|
||||||
|
|
||||||
return sig, nil
|
closeTXID := closeTx.TxHash()
|
||||||
|
return sig, &closeTXID, ourBalance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteCooperativeClose completes the cooperative closure of the target
|
// CompleteCooperativeClose completes the cooperative closure of the target
|
||||||
|
@ -754,7 +754,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
|
|||||||
// We'll store with both Alice and Bob creating a new close proposal
|
// We'll store with both Alice and Bob creating a new close proposal
|
||||||
// with the same fee.
|
// with the same fee.
|
||||||
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate))
|
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate))
|
||||||
aliceSig, err := aliceChannel.CreateCloseProposal(
|
aliceSig, _, _, err := aliceChannel.CreateCloseProposal(
|
||||||
aliceFee, aliceDeliveryScript, bobDeliveryScript,
|
aliceFee, aliceDeliveryScript, bobDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -763,7 +763,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
|
|||||||
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
||||||
|
|
||||||
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate))
|
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate))
|
||||||
bobSig, err := bobChannel.CreateCloseProposal(
|
bobSig, _, _, err := bobChannel.CreateCloseProposal(
|
||||||
bobFee, bobDeliveryScript, aliceDeliveryScript,
|
bobFee, bobDeliveryScript, aliceDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1875,7 +1875,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
|||||||
// balances. As a result, performing a cooperative closure now result
|
// balances. As a result, performing a cooperative closure now result
|
||||||
// in both sides having an output within the closure transaction.
|
// in both sides having an output within the closure transaction.
|
||||||
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) + 1000
|
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) + 1000
|
||||||
aliceSig, err := aliceChannel.CreateCloseProposal(aliceFee,
|
aliceSig, _, _, err := aliceChannel.CreateCloseProposal(aliceFee,
|
||||||
aliceDeliveryScript, bobDeliveryScript)
|
aliceDeliveryScript, bobDeliveryScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
@ -1883,7 +1883,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
|||||||
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
||||||
|
|
||||||
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + 1000
|
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + 1000
|
||||||
bobSig, err := bobChannel.CreateCloseProposal(bobFee,
|
bobSig, _, _, err := bobChannel.CreateCloseProposal(bobFee,
|
||||||
bobDeliveryScript, aliceDeliveryScript)
|
bobDeliveryScript, aliceDeliveryScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
@ -1914,14 +1914,14 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
|||||||
|
|
||||||
// Attempt another cooperative channel closure. It should succeed
|
// Attempt another cooperative channel closure. It should succeed
|
||||||
// without any issues.
|
// without any issues.
|
||||||
aliceSig, err = aliceChannel.CreateCloseProposal(aliceFee,
|
aliceSig, _, _, err = aliceChannel.CreateCloseProposal(aliceFee,
|
||||||
aliceDeliveryScript, bobDeliveryScript)
|
aliceDeliveryScript, bobDeliveryScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
}
|
}
|
||||||
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
||||||
|
|
||||||
bobSig, err = bobChannel.CreateCloseProposal(bobFee,
|
bobSig, _, _, err = bobChannel.CreateCloseProposal(bobFee,
|
||||||
bobDeliveryScript, aliceDeliveryScript)
|
bobDeliveryScript, aliceDeliveryScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
@ -1956,15 +1956,17 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
|||||||
|
|
||||||
// Our final attempt at another cooperative channel closure. It should
|
// Our final attempt at another cooperative channel closure. It should
|
||||||
// succeed without any issues.
|
// succeed without any issues.
|
||||||
aliceSig, err = aliceChannel.CreateCloseProposal(aliceFee,
|
aliceSig, _, _, err = aliceChannel.CreateCloseProposal(
|
||||||
aliceDeliveryScript, bobDeliveryScript)
|
aliceFee, aliceDeliveryScript, bobDeliveryScript,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
}
|
}
|
||||||
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
||||||
|
|
||||||
bobSig, err = bobChannel.CreateCloseProposal(bobFee,
|
bobSig, _, _, err = bobChannel.CreateCloseProposal(
|
||||||
bobDeliveryScript, aliceDeliveryScript)
|
bobFee, bobDeliveryScript, aliceDeliveryScript,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user