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.
This commit is contained in:
yyforyongyu 2024-11-25 13:55:11 +08:00
parent 819c15fa0b
commit 63aa5aa6e9
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -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,