From cebad6d0051721bc15fac4b2b224951b6bc8914f Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 25 Nov 2024 13:55:11 +0800 Subject: [PATCH] contractcourt: offer outgoing htlc one block earlier before its expiry We need to offer the outgoing htlc one block earlier to make sure when the expiry height hits, the sweeper will not miss sweeping it in the same block. This also means the outgoing contest resolver now only does one thing - watch for preimage spend till height expiry-1, which can easily be moved into the timeout resolver instead in the future. --- contractcourt/htlc_outgoing_contest_resolver.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contractcourt/htlc_outgoing_contest_resolver.go b/contractcourt/htlc_outgoing_contest_resolver.go index 19574dee27..b66a3fdf0b 100644 --- a/contractcourt/htlc_outgoing_contest_resolver.go +++ b/contractcourt/htlc_outgoing_contest_resolver.go @@ -155,7 +155,14 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) { // fail. newHeight := uint32(newBlock.Height) expiry := h.htlcResolution.Expiry - if newHeight >= expiry { + + // Check if the expiry height is about to be reached. + // We offer this HTLC one block earlier to make sure + // when the next block arrives, the sweeper will pick + // up this input and sweep it immediately. The sweeper + // will handle the waiting for the one last block till + // expiry. + if newHeight >= expiry-1 { h.log.Infof("HTLC about to expire "+ "(height=%v, expiry=%v), transforming "+ "into timeout resolver", h,