contractcourt/chain_watcher: use commitPoint directly instead of isPendingCommit

This commit is contained in:
Johan T. Halseth 2018-07-12 11:02:52 +02:00
parent d9e9b6197c
commit 2626bba105
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -5,14 +5,15 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/davecgh/go-spew/spew" "github.com/btcsuite/btcd/btcec"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwallet"
) )
// LocalUnilateralCloseInfo encapsulates all the informnation we need to act // LocalUnilateralCloseInfo encapsulates all the informnation we need to act
@ -343,7 +344,8 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) {
// as necessary. // as necessary.
case broadcastStateNum == remoteStateNum: case broadcastStateNum == remoteStateNum:
err := c.dispatchRemoteForceClose( err := c.dispatchRemoteForceClose(
commitSpend, *remoteCommit, false, commitSpend, *remoteCommit,
c.cfg.chanState.RemoteCurrentRevocation,
) )
if err != nil { if err != nil {
log.Errorf("unable to handle remote "+ log.Errorf("unable to handle remote "+
@ -362,7 +364,7 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) {
err := c.dispatchRemoteForceClose( err := c.dispatchRemoteForceClose(
commitSpend, remoteChainTip.Commitment, commitSpend, remoteChainTip.Commitment,
true, c.cfg.chanState.RemoteNextRevocation,
) )
if err != nil { if err != nil {
log.Errorf("unable to handle remote "+ log.Errorf("unable to handle remote "+
@ -557,12 +559,19 @@ func (c *chainWatcher) dispatchLocalForceClose(
// the remote party. This function will prepare a UnilateralCloseSummary which // the remote party. This function will prepare a UnilateralCloseSummary which
// will then be sent to any subscribers allowing them to resolve all our funds // will then be sent to any subscribers allowing them to resolve all our funds
// in the channel on chain. Once this close summary is prepared, all registered // in the channel on chain. Once this close summary is prepared, all registered
// subscribers will receive a notification of this event. The // subscribers will receive a notification of this event. The commitPoint
// isRemotePendingCommit argument should be set to true if the remote node // argument should be set to the per_commitment_point corresponding to the
// broadcast their pending commitment (w/o revoking their current settled // spending commitment.
// commitment). //
func (c *chainWatcher) dispatchRemoteForceClose(commitSpend *chainntnfs.SpendDetail, // NOTE: The remoteCommit argument should be set to the stored commitment for
remoteCommit channeldb.ChannelCommitment, isRemotePendingCommit bool) error { // this particular state. If we don't have the commitment stored (should only
// happen in case we have lost state) it should be set to an empty struct, in
// which case we will attempt to sweep the non-HTLC output using the passed
// commitPoint.
func (c *chainWatcher) dispatchRemoteForceClose(
commitSpend *chainntnfs.SpendDetail,
remoteCommit channeldb.ChannelCommitment,
commitPoint *btcec.PublicKey) error {
log.Infof("Unilateral close of ChannelPoint(%v) "+ log.Infof("Unilateral close of ChannelPoint(%v) "+
"detected", c.cfg.chanState.FundingOutpoint) "detected", c.cfg.chanState.FundingOutpoint)
@ -572,7 +581,7 @@ func (c *chainWatcher) dispatchRemoteForceClose(commitSpend *chainntnfs.SpendDet
// channel on-chain. // channel on-chain.
uniClose, err := lnwallet.NewUnilateralCloseSummary( uniClose, err := lnwallet.NewUnilateralCloseSummary(
c.cfg.chanState, c.cfg.signer, c.cfg.pCache, commitSpend, c.cfg.chanState, c.cfg.signer, c.cfg.pCache, commitSpend,
remoteCommit, isRemotePendingCommit, remoteCommit, commitPoint,
) )
if err != nil { if err != nil {
return err return err