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)