From a9f93b29889a60295d344532fe7d47c1ef0d4031 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 20 Nov 2018 15:09:45 +0100 Subject: [PATCH] contractcourt/chain_watcher: add channel sync message to CloseChannelSummary --- contractcourt/chain_watcher.go | 27 +++++++++++++++++++++++++++ lnwallet/channel.go | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index c183788f..2d60b782 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -522,6 +522,15 @@ func (c *chainWatcher) dispatchCooperativeClose(commitSpend *chainntnfs.SpendDet LocalChanConfig: c.cfg.chanState.LocalChanCfg, } + // Attempt to add a channel sync message to the close summary. + chanSync, err := lnwallet.ChanSyncMsg(c.cfg.chanState) + if err != nil { + log.Errorf("ChannelPoint(%v): unable to create channel sync "+ + "message: %v", c.cfg.chanState.FundingOutpoint, err) + } else { + closeSummary.LastChanSyncMsg = chanSync + } + // Create a summary of all the information needed to handle the // cooperative closure. closeInfo := &CooperativeCloseInfo{ @@ -590,6 +599,15 @@ func (c *chainWatcher) dispatchLocalForceClose( closeSummary.TimeLockedBalance += htlcValue } + // Attempt to add a channel sync message to the close summary. + chanSync, err := lnwallet.ChanSyncMsg(c.cfg.chanState) + if err != nil { + log.Errorf("ChannelPoint(%v): unable to create channel sync "+ + "message: %v", c.cfg.chanState.FundingOutpoint, err) + } else { + closeSummary.LastChanSyncMsg = chanSync + } + // With the event processed, we'll now notify all subscribers of the // event. closeInfo := &LocalUnilateralCloseInfo{ @@ -749,6 +767,15 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail LocalChanConfig: c.cfg.chanState.LocalChanCfg, } + // Attempt to add a channel sync message to the close summary. + chanSync, err := lnwallet.ChanSyncMsg(c.cfg.chanState) + if err != nil { + log.Errorf("ChannelPoint(%v): unable to create channel sync "+ + "message: %v", c.cfg.chanState.FundingOutpoint, err) + } else { + closeSummary.LastChanSyncMsg = chanSync + } + if err := c.cfg.chanState.CloseChannel(&closeSummary); err != nil { return err } diff --git a/lnwallet/channel.go b/lnwallet/channel.go index d45ba296..ca6b2e10 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -5116,6 +5116,15 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer Signer, LocalChanConfig: chanState.LocalChanCfg, } + // Attempt to add a channel sync message to the close summary. + chanSync, err := ChanSyncMsg(chanState) + if err != nil { + walletLog.Errorf("ChannelPoint(%v): unable to create channel sync "+ + "message: %v", chanState.FundingOutpoint, err) + } else { + closeSummary.LastChanSyncMsg = chanSync + } + return &UnilateralCloseSummary{ SpendDetail: commitSpend, ChannelCloseSummary: closeSummary,