chancloser: don't log potential closes to the chainwatcher
This commit stops the chan closer from sending the potential coop close transactions to the chainwatcher, as this is no longer needed. The chainwatcher recently was modified to watch for any potential close, and will because of this handle the close regardless of which one appears in chain. When the chancloser broadcast the final close transaction, we mark it as CommitmentBroadcasted in the database.
This commit is contained in:
parent
9ddd484524
commit
0809880426
@ -4,8 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -135,8 +133,6 @@ type channelCloser struct {
|
|||||||
// TODO(roasbeef): abstract away
|
// TODO(roasbeef): abstract away
|
||||||
closeReq *htlcswitch.ChanClose
|
closeReq *htlcswitch.ChanClose
|
||||||
|
|
||||||
closeCtx *contractcourt.CooperativeCloseCtx
|
|
||||||
|
|
||||||
// localDeliveryScript is the script that we'll send our settled
|
// localDeliveryScript is the script that we'll send our settled
|
||||||
// channel funds to.
|
// channel funds to.
|
||||||
localDeliveryScript []byte
|
localDeliveryScript []byte
|
||||||
@ -151,8 +147,7 @@ type channelCloser struct {
|
|||||||
// only be populated iff, we're the initiator of this closing request.
|
// only be populated iff, we're the initiator of this closing request.
|
||||||
func newChannelCloser(cfg chanCloseCfg, deliveryScript []byte,
|
func newChannelCloser(cfg chanCloseCfg, deliveryScript []byte,
|
||||||
idealFeePerKw lnwallet.SatPerKWeight, negotiationHeight uint32,
|
idealFeePerKw lnwallet.SatPerKWeight, negotiationHeight uint32,
|
||||||
closeReq *htlcswitch.ChanClose,
|
closeReq *htlcswitch.ChanClose) *channelCloser {
|
||||||
closeCtx *contractcourt.CooperativeCloseCtx) *channelCloser {
|
|
||||||
|
|
||||||
// Given the target fee-per-kw, we'll compute what our ideal _total_
|
// Given the target fee-per-kw, we'll compute what our ideal _total_
|
||||||
// fee will be starting at for this fee negotiation.
|
// fee will be starting at for this fee negotiation.
|
||||||
@ -186,7 +181,6 @@ func newChannelCloser(cfg chanCloseCfg, deliveryScript []byte,
|
|||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
negotiationHeight: negotiationHeight,
|
negotiationHeight: negotiationHeight,
|
||||||
idealFeeSat: idealFeeSat,
|
idealFeeSat: idealFeeSat,
|
||||||
closeCtx: closeCtx,
|
|
||||||
localDeliveryScript: deliveryScript,
|
localDeliveryScript: deliveryScript,
|
||||||
priorFeeOffers: make(map[btcutil.Amount]*lnwire.ClosingSigned),
|
priorFeeOffers: make(map[btcutil.Amount]*lnwire.ClosingSigned),
|
||||||
}
|
}
|
||||||
@ -420,7 +414,7 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b
|
|||||||
remoteSigBytes := closeSignedMsg.Signature.ToSignatureBytes()
|
remoteSigBytes := closeSignedMsg.Signature.ToSignatureBytes()
|
||||||
remoteSig := append(remoteSigBytes, byte(txscript.SigHashAll))
|
remoteSig := append(remoteSigBytes, byte(txscript.SigHashAll))
|
||||||
|
|
||||||
closeTx, finalLocalBalance, err := c.cfg.channel.CompleteCooperativeClose(
|
closeTx, _, err := c.cfg.channel.CompleteCooperativeClose(
|
||||||
localSig, remoteSig, c.localDeliveryScript,
|
localSig, remoteSig, c.localDeliveryScript,
|
||||||
c.remoteDeliveryScript, remoteProposedFee,
|
c.remoteDeliveryScript, remoteProposedFee,
|
||||||
)
|
)
|
||||||
@ -438,33 +432,16 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b
|
|||||||
if err := c.cfg.broadcastTx(closeTx); err != nil {
|
if err := c.cfg.broadcastTx(closeTx); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
if c.cfg.channel.MarkCommitmentBroadcasted(); err != nil {
|
||||||
// Clear out the current channel state, marking the channel as
|
return nil, false, err
|
||||||
// being closed within the database.
|
}
|
||||||
closingTxid := closeTx.TxHash()
|
|
||||||
chanInfo := c.cfg.channel.StateSnapshot()
|
|
||||||
c.closeCtx.Finalize(&channeldb.ChannelCloseSummary{
|
|
||||||
ChanPoint: c.chanPoint,
|
|
||||||
ChainHash: chanInfo.ChainHash,
|
|
||||||
ClosingTXID: closingTxid,
|
|
||||||
CloseHeight: c.negotiationHeight,
|
|
||||||
RemotePub: &chanInfo.RemoteIdentity,
|
|
||||||
Capacity: chanInfo.Capacity,
|
|
||||||
SettledBalance: finalLocalBalance,
|
|
||||||
CloseType: channeldb.CooperativeClose,
|
|
||||||
ShortChanID: c.cfg.channel.ShortChanID(),
|
|
||||||
IsPending: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO(roasbeef): don't need, ChainWatcher will handle
|
|
||||||
|
|
||||||
c.state = closeFinished
|
|
||||||
|
|
||||||
// Finally, we'll transition to the closeFinished state, and
|
// Finally, we'll transition to the closeFinished state, and
|
||||||
// also return the final close signed message we sent.
|
// also return the final close signed message we sent.
|
||||||
// Additionally, we return true for the second argument to
|
// Additionally, we return true for the second argument to
|
||||||
// indicate we're finished with the channel closing
|
// indicate we're finished with the channel closing
|
||||||
// negotiation.
|
// negotiation.
|
||||||
|
c.state = closeFinished
|
||||||
matchingOffer := c.priorFeeOffers[remoteProposedFee]
|
matchingOffer := c.priorFeeOffers[remoteProposedFee]
|
||||||
return []lnwire.Message{matchingOffer}, true, nil
|
return []lnwire.Message{matchingOffer}, true, nil
|
||||||
|
|
||||||
@ -493,7 +470,7 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b
|
|||||||
// current compromise fee.
|
// current compromise fee.
|
||||||
func (c *channelCloser) proposeCloseSigned(fee btcutil.Amount) (*lnwire.ClosingSigned, error) {
|
func (c *channelCloser) proposeCloseSigned(fee btcutil.Amount) (*lnwire.ClosingSigned, error) {
|
||||||
|
|
||||||
rawSig, txid, localAmt, err := c.cfg.channel.CreateCloseProposal(
|
rawSig, _, _, err := c.cfg.channel.CreateCloseProposal(
|
||||||
fee, c.localDeliveryScript, c.remoteDeliveryScript,
|
fee, c.localDeliveryScript, c.remoteDeliveryScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -521,20 +498,6 @@ func (c *channelCloser) proposeCloseSigned(fee btcutil.Amount) (*lnwire.ClosingS
|
|||||||
// accepts our offer. This way, we don't have to re-sign.
|
// accepts our offer. This way, we don't have to re-sign.
|
||||||
c.priorFeeOffers[fee] = closeSignedMsg
|
c.priorFeeOffers[fee] = closeSignedMsg
|
||||||
|
|
||||||
chanInfo := c.cfg.channel.StateSnapshot()
|
|
||||||
c.closeCtx.LogPotentialClose(&channeldb.ChannelCloseSummary{
|
|
||||||
ChanPoint: c.chanPoint,
|
|
||||||
ChainHash: chanInfo.ChainHash,
|
|
||||||
ClosingTXID: *txid,
|
|
||||||
CloseHeight: c.negotiationHeight,
|
|
||||||
RemotePub: &chanInfo.RemoteIdentity,
|
|
||||||
Capacity: chanInfo.Capacity,
|
|
||||||
SettledBalance: localAmt,
|
|
||||||
CloseType: channeldb.CooperativeClose,
|
|
||||||
ShortChanID: c.cfg.channel.ShortChanID(),
|
|
||||||
IsPending: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
return closeSignedMsg, nil
|
return closeSignedMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user