From 22711ade3af1b3117cc54b2466df8ec8e4bb3168 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Mon, 11 Jan 2021 22:48:41 +0100 Subject: [PATCH] cnct: dispatch contract breach after channel close summary is serialized This commit moves the contract breach event dispatch after the channel close summary has been added to the database. This is important otherwise it may occur that we attempt to mark the channel fully closed while the channel close summary is not yet serialized. --- contractcourt/chain_watcher.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 97aa7852..6cd3c9dc 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -1128,19 +1128,6 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail return err } - // With the event processed, we'll now notify all subscribers of the - // event. - c.Lock() - for _, sub := range c.clientSubscriptions { - select { - case sub.ContractBreach <- retribution: - case <-c.quit: - c.Unlock() - return fmt.Errorf("quitting") - } - } - c.Unlock() - // At this point, we've successfully received an ack for the breach // close. We now construct and persist the close summary, marking the // channel as pending force closed. @@ -1182,6 +1169,19 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail log.Infof("Breached channel=%v marked pending-closed", c.cfg.chanState.FundingOutpoint) + // With the event processed and channel closed, we'll now notify all + // subscribers of the event. + c.Lock() + for _, sub := range c.clientSubscriptions { + select { + case sub.ContractBreach <- retribution: + case <-c.quit: + c.Unlock() + return fmt.Errorf("quitting") + } + } + c.Unlock() + return nil }