Skip to content

Conversation

@hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Dec 15, 2025

We need to re-register for htlc tx confs if the registration fires a conf error in MonitorInvoiceAndHtlcTxAction. Otherwise we miss sweeping the htlc timeout-path.

@hieblmi hieblmi requested a review from bhandras December 15, 2025 13:06
@gemini-code-assist
Copy link

Summary of Changes

Hello @hieblmi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability of HTLC (Hashed Timelock Contract) transaction monitoring by introducing a re-registration process. Previously, an error during the initial HTLC confirmation registration could lead to the system failing to track the transaction, potentially missing critical sweep operations. The updated logic now attempts to re-establish monitoring upon encountering such an error, ensuring continuous and correct handling of HTLCs.

Highlights

  • HTLC Confirmation Error Handling: Implemented a mechanism to re-register for HTLC transaction confirmations if an error is received on the htlcErrConfChan within the MonitorInvoiceAndHtlcTxAction function.
  • Preventing Missed Sweeps: This change ensures that the system does not miss sweeping the HTLC timeout-path due to a transient registration error, improving the robustness of HTLC handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@hieblmi hieblmi requested review from sputn1ck and starius December 15, 2025 13:06
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where an error on the HTLC transaction confirmation channel would cause the system to stop monitoring for the confirmation, potentially leading to failure in sweeping the HTLC timeout path. The proposed change correctly re-registers for confirmation notifications upon such an error. My review identifies a potential issue with the error handling of this re-registration. If the re-registration fails, the error is only logged, which could lead to a deadlock in the monitoring loop. I've provided a suggestion to propagate this error to the state machine for proper handling, which will make the implementation more robust.

@hieblmi hieblmi force-pushed the reregister branch 2 times, most recently from 356dbfd to c83bc3b Compare December 15, 2025 13:17
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@starius
Copy link
Collaborator

starius commented Dec 16, 2025

Thanks! 🏂

I added code coverage and a couple of related fixes here: hieblmi#3 PTAL

case err = <-invoiceErrChan:
f.Errorf("invoice subscription error: %v", err)

return f.HandleError(err)
Copy link
Collaborator Author

@hieblmi hieblmi Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case occurs if the invoice deadline was reached and the invoice got cancelled. In this case we can't return here, but need to keep monitoring the htlc publication. So I am going to revert this line. @starius

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the invoice subscription (not the invoice!) fails / cancels, we have to re-subscribe, otherwise we won't know that invoice was paid.

This is not critical so let's just add a TODO.

- propagate invoice subscription errors in MonitorInvoiceAndHtlcTx via
  HandleError instead of silently logging
- add regression tests covering HTLC conf re-registration and invoice
  subscription error propagation
- reset htlcConfirmed when the HTLC conf subscription errors and we re-register
- add regression test ensuring re-registers after a conf error require a fresh
  confirmation instead of sweeping on a stale one
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thank you!

@hieblmi hieblmi merged commit 3441575 into lightninglabs:master Dec 18, 2025
9 checks passed
@hieblmi hieblmi deleted the reregister branch December 18, 2025 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants