contractcourt/chain_arbitrator: make watchForChannelClose use confirmed spend

This commit is contained in:
Johan T. Halseth 2018-07-17 09:13:05 +02:00
parent 5bfa2f5912
commit a16bb662a4
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -497,13 +497,16 @@ func (c *ChainArbitrator) Stop() error {
// NOTE: This must be launched as a goroutine. // NOTE: This must be launched as a goroutine.
func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelCloseSummary) { func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelCloseSummary) {
spendNtfn, err := c.cfg.Notifier.RegisterSpendNtfn( spendNtfn, err := c.cfg.Notifier.RegisterSpendNtfn(
&closeInfo.ChanPoint, closeInfo.CloseHeight, true, &closeInfo.ChanPoint, closeInfo.CloseHeight, false,
) )
if err != nil { if err != nil {
log.Errorf("unable to register for spend: %v", err) log.Errorf("unable to register for spend: %v", err)
return return
} }
log.Infof("Waiting for ChannelPoint(%v) to be coop closed on chain",
closeInfo.ChanPoint)
var ( var (
commitSpend *chainntnfs.SpendDetail commitSpend *chainntnfs.SpendDetail
ok bool ok bool
@ -517,35 +520,11 @@ func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelClose
return return
} }
confNtfn, err := c.cfg.Notifier.RegisterConfirmationsNtfn( log.Infof("ChannelPoint(%v) is fully closed, at height: %v",
commitSpend.SpenderTxHash, 1, closeInfo.ChanPoint, commitSpend.SpendingHeight)
uint32(commitSpend.SpendingHeight),
)
if err != nil {
log.Errorf("unable to register for "+
"conf: %v", err)
return
}
log.Infof("Waiting for txid=%v to close ChannelPoint(%v) on chain", if err := c.resolveContract(closeInfo.ChanPoint, nil); err != nil {
commitSpend.SpenderTxHash, closeInfo.ChanPoint) log.Errorf("unable to resolve contract: %v", err)
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
} }
} }