From 6d2dfed03da16529d46faea90d28588c42398cf6 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Tue, 9 Apr 2019 16:22:50 +0200 Subject: [PATCH] htlcswitch: increase batch counter for exit hop settle and fail The idea of the batch counter is to increase it for commit tx updates, so that if the commit tx cannot be updated immediately (revocation window exhausted), the batch ticker makes sure it happens later. The batch counter was increased for forwarded htlcs, but not for exit hop resolutions. This lead to the situation where the commitment tx would not be updated, even though the htlc was settled locally. When no other changes happen on the channel, the htlc eventually reaches its expiry and the channel is force closed. --- htlcswitch/link.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 076415b2..66063875 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -945,6 +945,13 @@ out: break out } + // If the previous event resulted in a non-empty + // batch, reinstate the batch ticker so that it can be + // cleared. + if l.batchCounter > 0 { + l.cfg.BatchTicker.Resume() + } + select { // Our update fee timer has fired, so we'll check the network // fee to see if we should adjust our commitment fee. @@ -1047,13 +1054,6 @@ out: l.handleDownStreamPkt(packet, true) - // If the downstream packet resulted in a non-empty - // batch, reinstate the batch ticker so that it can be - // cleared. - if l.batchCounter > 0 { - l.cfg.BatchTicker.Resume() - } - // A message from the switch was just received. This indicates // that the link is an intermediate hop in a multi-hop HTLC // circuit. @@ -1076,13 +1076,6 @@ out: l.handleDownStreamPkt(pkt, false) - // If the downstream packet resulted in a non-empty - // batch, reinstate the batch ticker so that it can be - // cleared. - if l.batchCounter > 0 { - l.cfg.BatchTicker.Resume() - } - // A message from the connected peer was just received. This // indicates that we have a new incoming HTLC, either directly // for us, or part of a multi-hop HTLC circuit. @@ -1197,6 +1190,8 @@ func (l *channelLink) processHodlEvent(hodlEvent invoices.HodlEvent, if err := hodlAction(htlc); err != nil { return err } + + l.batchCounter++ } return nil