-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix height hint Zero issue in utxonursery #10273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix height hint Zero issue in utxonursery #10273
Conversation
Summary of ChangesHello @ziggie1984, 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 resolves a critical issue within the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 a bug in the legacy utxonursery
where HTLCs with a zero timelock would not be swept due to an invalid height hint. The fix introduces a fallback mechanism to derive a valid height hint from the channel's close height, ensuring these outputs can be processed correctly. The changes are well-implemented, include comprehensive unit tests for the new logic, and update the release notes accordingly. The code quality is high, and I have no further suggestions for improvement.
That was the error for the reviewer:
|
f3ebaff
to
fc1ce54
Compare
The patch worked as foreseen. The node operator had however one node which had corrupted data entries, if this happens we error out which is the best way imo otherwise we do not recognise this behaviour.
We removed those entries manually, they can still be swept with chantools. |
fc1ce54
to
e2bf220
Compare
/gemini review |
There was a problem hiding this 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 introduces a fix for a crash in utxonursery
when handling outputs with a zero expiry height, which is a remnant of a historical bug. The core of the change is the new patchZeroHeightHint
function, which provides a fallback mechanism to determine a valid height hint for the chain notifier.
The logic for the fallback mechanism is sound, and the addition of comprehensive unit tests is commendable. However, I've identified a critical issue in the implementation that could lead to the same crash it intends to fix, along with corresponding adjustments needed in the tests.
My review is based on the LND Style Guide provided in the repository.
e2bf220
to
07da0e0
Compare
@gemini-code-assist can you check if this current approach solves all the priority problems from before. |
Hello @ziggie1984, Thank you for the update and for sharing the detailed error logs. It's very helpful to see the real-world impact of the changes. Regarding your question, "can you check if this current approach solves all the priority problems from before?": Based on the logs you provided, the patch successfully addresses the initial critical issue where a However, your second log snippet highlights an important edge case:
This indicates that while the patch provides a robust fallback mechanism, it still relies on the availability of the So, to directly answer your question:
This approach ensures that the system doesn't proceed with invalid height hints and provides clear diagnostics when necessary channel data is missing. It's a significant step forward in handling these problematic legacy outputs. |
Decided to still error out in case the closeSummary is borked. |
Tests need to be updated after the latest change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest logic looks good, but the tests need patching.
07da0e0
to
8c102d4
Compare
/gemini review |
There was a problem hiding this 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 a zero height hint in the utxonursery could cause failures. The fix introduces a new function, patchZeroHeightHint
, to provide a fallback height hint by using channel closing information. The changes are logical and well-supported by a comprehensive set of new unit tests that cover various edge cases. My review focuses on improving the clarity and accuracy of comments within the new function to enhance code maintainability, aligning with the style guide's emphasis on readable code.
8c102d4
to
44d2fb6
Compare
/gemini review |
There was a problem hiding this 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 effectively addresses an issue where the utxonursery
could fail to sweep HTLCs with a zero expiry height. The core of the fix, the patchZeroHeightHint
function, introduces a robust fallback mechanism for determining a valid height hint by using the channel's close summary. The logic is well-considered, handling various edge cases such as a zero channel close height and ensuring the derived hint is sane with respect to SegWit activation and confirmation depth. The accompanying tests are comprehensive and validate the new logic paths thoroughly.
I have a couple of suggestions to enhance the clarity and maintainability of the error messages within the new function. Overall, this is a solid and well-tested fix.
a3ced6d
to
473a423
Compare
/gemini review |
There was a problem hiding this 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 introduces a fix for an issue where the utxonursery
would fail to sweep HTLCs that have a zero expiry height, a situation caused by a historical bug. The fix introduces a fallback mechanism in patchZeroHeightHint
to determine a valid height hint using the channel's close summary. The changes are well-tested with a new comprehensive unit test.
My main feedback is regarding a hardcoded mainnet constant for the SegWit activation height, which will cause issues on other networks. This should be made dynamic based on the channel's network parameters. The tests will also need to be updated accordingly.
contractcourt/utxonursery.go
Outdated
// segwitActiveHeight is the height at which segwit was activated. There | ||
// can only be lightning channels after segwit was activated. | ||
segwitActiveHeight = 481824 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The segwitActiveHeight
is hardcoded to the mainnet value. This will cause issues on other networks like testnet, where SegWit activated at a different height. This constant should be removed. Instead, the SegWit activation height should be determined dynamically within patchZeroHeightHint
based on the channel's network parameters, which can be derived from the ChainHash
available in the ChannelCloseSummary
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decided to remove this check to have a cleaner design rather than hardcoding mainnet values, this should never happen in the first place anyways.
473a423
to
286be51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ⛵
// conf. depth since channels should have a minimum close height of the | ||
// segwit activation height and the conf. depth which is a config | ||
// parameter should be in the single digit range. | ||
if heightHint <= u.cfg.ConfDepth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally this should be impossible right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
// Use the close height minus the confirmation depth as a conservative | ||
// height hint. This ensures we don't miss the confirmation even if it | ||
// happened around the close height. | ||
heightHint -= u.cfg.ConfDepth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like this should be impossible as the outputs can only be spent after the closing tx is confirmed, but also not very important as we are just scanning a few more blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took the logic from other parts in the utxo nursery where we would do that, so tried to keep it (maybe there is a race I don't know about haha)
Older LND versions had a bug which would create HTLCs with 0 locktime. The utxonursery will have problems dealing with such htlc outputs because we do not allow height hints of 0. Now we will fetch the closeSummary of the channel and will add a conservative height for rescanning.
286be51
to
7c92c88
Compare
Fixes: #8383
please try-out this patch if you can @robtex