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,
|
||||
// settle any in flight.
|
||||
func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
||||
localDeliveryScript, remoteDeliveryScript []byte) ([]byte, error) {
|
||||
localDeliveryScript []byte,
|
||||
remoteDeliveryScript []byte) ([]byte, *chainhash.Hash, btcutil.Amount, error) {
|
||||
|
||||
lc.Lock()
|
||||
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 lc.status == channelClosed {
|
||||
// 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
|
||||
@ -4777,7 +4778,7 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
||||
// negative output.
|
||||
tx := btcutil.NewTx(closeTx)
|
||||
if err := blockchain.CheckTransactionSanity(tx); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
sig, err := lc.signer.SignOutputRaw(closeTx, lc.signDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
// As everything checks out, indicate in the channel status that a
|
||||
// channel closure has been initiated.
|
||||
lc.status = channelClosing
|
||||
|
||||
return sig, nil
|
||||
closeTXID := closeTx.TxHash()
|
||||
return sig, &closeTXID, ourBalance, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
// with the same fee.
|
||||
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate))
|
||||
aliceSig, err := aliceChannel.CreateCloseProposal(
|
||||
aliceSig, _, _, err := aliceChannel.CreateCloseProposal(
|
||||
aliceFee, aliceDeliveryScript, bobDeliveryScript,
|
||||
)
|
||||
if err != nil {
|
||||
@ -763,7 +763,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
|
||||
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
||||
|
||||
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate))
|
||||
bobSig, err := bobChannel.CreateCloseProposal(
|
||||
bobSig, _, _, err := bobChannel.CreateCloseProposal(
|
||||
bobFee, bobDeliveryScript, aliceDeliveryScript,
|
||||
)
|
||||
if err != nil {
|
||||
@ -1875,7 +1875,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
||||
// balances. As a result, performing a cooperative closure now result
|
||||
// in both sides having an output within the closure transaction.
|
||||
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate)) + 1000
|
||||
aliceSig, err := aliceChannel.CreateCloseProposal(aliceFee,
|
||||
aliceSig, _, _, err := aliceChannel.CreateCloseProposal(aliceFee,
|
||||
aliceDeliveryScript, bobDeliveryScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
@ -1883,7 +1883,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
||||
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
|
||||
|
||||
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + 1000
|
||||
bobSig, err := bobChannel.CreateCloseProposal(bobFee,
|
||||
bobSig, _, _, err := bobChannel.CreateCloseProposal(bobFee,
|
||||
bobDeliveryScript, aliceDeliveryScript)
|
||||
if err != nil {
|
||||
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
|
||||
// without any issues.
|
||||
aliceSig, err = aliceChannel.CreateCloseProposal(aliceFee,
|
||||
aliceSig, _, _, err = aliceChannel.CreateCloseProposal(aliceFee,
|
||||
aliceDeliveryScript, bobDeliveryScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
}
|
||||
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
||||
|
||||
bobSig, err = bobChannel.CreateCloseProposal(bobFee,
|
||||
bobSig, _, _, err = bobChannel.CreateCloseProposal(bobFee,
|
||||
bobDeliveryScript, aliceDeliveryScript)
|
||||
if err != nil {
|
||||
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
|
||||
// succeed without any issues.
|
||||
aliceSig, err = aliceChannel.CreateCloseProposal(aliceFee,
|
||||
aliceDeliveryScript, bobDeliveryScript)
|
||||
aliceSig, _, _, err = aliceChannel.CreateCloseProposal(
|
||||
aliceFee, aliceDeliveryScript, bobDeliveryScript,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
}
|
||||
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
|
||||
|
||||
bobSig, err = bobChannel.CreateCloseProposal(bobFee,
|
||||
bobDeliveryScript, aliceDeliveryScript)
|
||||
bobSig, _, _, err = bobChannel.CreateCloseProposal(
|
||||
bobFee, bobDeliveryScript, aliceDeliveryScript,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user