From 921f02fe22749148b42839489880711bd2ec270f Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 22 May 2018 14:04:53 +0200 Subject: [PATCH] contractcourt/chain_arbitrator: markChanClosed->notifyChanClosed We no longer have to mark the channel as fully closed in the database, as it is done directly in the chainWatcher. Instead, we stop the watcher and delete it from the set of active watchers. --- contractcourt/chain_arbitrator.go | 36 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 1e2079b7..944b6cc8 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -341,9 +341,22 @@ func (c *ChainArbitrator) Start() error { pCache: c.cfg.PreimageDB, signer: c.cfg.Signer, isOurAddr: c.cfg.IsOurAddress, - markChanClosed: func() error { - // TODO(roasbeef): also need to pass in log? - return c.resolveContract(chanPoint, nil) + notifyChanClosed: func() error { + c.Lock() + delete(c.activeChannels, chanPoint) + + chainWatcher, ok := c.activeWatchers[chanPoint] + if ok { + // Since the chainWatcher is + // calling notifyChanClosed, we + // must stop it in a goroutine + // to not deadlock. + go chainWatcher.Stop() + } + delete(c.activeWatchers, chanPoint) + c.Unlock() + + return nil }, contractBreach: func(retInfo *lnwallet.BreachRetribution) error { return c.cfg.ContractBreach(chanPoint, retInfo) @@ -677,8 +690,21 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error pCache: c.cfg.PreimageDB, signer: c.cfg.Signer, isOurAddr: c.cfg.IsOurAddress, - markChanClosed: func() error { - return c.resolveContract(chanPoint, nil) + notifyChanClosed: func() error { + c.Lock() + delete(c.activeChannels, chanPoint) + + chainWatcher, ok := c.activeWatchers[chanPoint] + if ok { + // Since the chainWatcher is calling + // notifyChanClosed, we must stop it in + // a goroutine to not deadlock. + go chainWatcher.Stop() + } + delete(c.activeWatchers, chanPoint) + c.Unlock() + + return nil }, contractBreach: func(retInfo *lnwallet.BreachRetribution) error { return c.cfg.ContractBreach(chanPoint, retInfo)