From a16bb662a4bb968b2c8a68d75fe98859171a0bf1 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 17 Jul 2018 09:13:05 +0200 Subject: [PATCH] contractcourt/chain_arbitrator: make watchForChannelClose use confirmed spend --- contractcourt/chain_arbitrator.go | 37 +++++++------------------------ 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index fb5f1c97..a3a48d55 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -497,13 +497,16 @@ func (c *ChainArbitrator) Stop() error { // NOTE: This must be launched as a goroutine. func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelCloseSummary) { spendNtfn, err := c.cfg.Notifier.RegisterSpendNtfn( - &closeInfo.ChanPoint, closeInfo.CloseHeight, true, + &closeInfo.ChanPoint, closeInfo.CloseHeight, false, ) if err != nil { log.Errorf("unable to register for spend: %v", err) return } + log.Infof("Waiting for ChannelPoint(%v) to be coop closed on chain", + closeInfo.ChanPoint) + var ( commitSpend *chainntnfs.SpendDetail ok bool @@ -517,35 +520,11 @@ func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelClose return } - confNtfn, err := c.cfg.Notifier.RegisterConfirmationsNtfn( - commitSpend.SpenderTxHash, 1, - uint32(commitSpend.SpendingHeight), - ) - if err != nil { - log.Errorf("unable to register for "+ - "conf: %v", err) - return - } + log.Infof("ChannelPoint(%v) is fully closed, at height: %v", + closeInfo.ChanPoint, commitSpend.SpendingHeight) - log.Infof("Waiting for txid=%v to close ChannelPoint(%v) on chain", - commitSpend.SpenderTxHash, closeInfo.ChanPoint) - - select { - case confInfo, ok := <-confNtfn.Confirmed: - if !ok { - return - } - - log.Infof("ChannelPoint(%v) is fully closed, at height: %v", - closeInfo.ChanPoint, confInfo.BlockHeight) - - err := c.resolveContract(closeInfo.ChanPoint, nil) - if err != nil { - log.Errorf("unable to resolve contract: %v", err) - } - - case <-c.quit: - return + if err := c.resolveContract(closeInfo.ChanPoint, nil); err != nil { + log.Errorf("unable to resolve contract: %v", err) } }