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,37 +520,13 @@ func (c *ChainArbitrator) watchForChannelClose(closeInfo *channeldb.ChannelClose
return 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("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", log.Infof("ChannelPoint(%v) is fully closed, at height: %v",
closeInfo.ChanPoint, confInfo.BlockHeight) closeInfo.ChanPoint, commitSpend.SpendingHeight)
err := c.resolveContract(closeInfo.ChanPoint, nil) if err := c.resolveContract(closeInfo.ChanPoint, nil); err != nil {
if err != nil {
log.Errorf("unable to resolve contract: %v", err) log.Errorf("unable to resolve contract: %v", err)
} }
case <-c.quit:
return
}
} }
// ContractSignals wraps the two signals that affect the state of a channel // ContractSignals wraps the two signals that affect the state of a channel