staticaddr/withdraw: add retry and reorg handling for withdrawals#1129
staticaddr/withdraw: add retry and reorg handling for withdrawals#1129kaldun-tech wants to merge 2 commits intolightninglabs:masterfrom
Conversation
Summary of ChangesHello, 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 improves the reliability of the static address withdrawal manager by addressing critical gaps in error handling and state management. By introducing retry mechanisms, reorg awareness, and ensuring atomic state persistence, the changes ensure that withdrawal monitoring is resilient against network instability and node restarts. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements retry logic and reorg handling for static address withdrawal confirmations to prevent silent failures. It reorders state persistence to occur before monitoring setup, ensuring recovery on restart, and refactors withdrawal monitoring into an asynchronous process with dedicated loops for spend and confirmation notifications. Feedback identifies critical resource leaks in the notification registration loops, where subscriptions are not canceled during retries, and recommends using sub-contexts to manage these resources properly.
This commit fixes three related issues in the withdrawal manager: 1. No retry when RegisterSpendNtfn/RegisterConfirmationsNtfn fails 2. No handling for reorgs (tx confirmed then reorged out) 3. State not persisted before handleWithdrawal, causing recovery failures Changes: - Reorder state persistence to happen BEFORE handleWithdrawal so recoverWithdrawals can find deposits in Withdrawing state on restart - Add retry-on-next-block for registration failures using block notifications - Add reorg detection via lndclient.WithReOrgChan for both spend and confirmation notifications - On reorg after spend detection, return to spend watching (not just re-register for confirmations) since the spend tx may be invalidated - Make handleWithdrawal async/best-effort since tx is already published Fixes issue lightninglabs#1087 Signed-off-by: kaldun-tech <tsmereka@protonmail.com>
Signed-off-by: kaldun-tech <tsmereka@protonmail.com>
Summary
Fixes #1087
Addresses three related issues in the static address withdrawal manager:
RegisterSpendNtfn/RegisterConfirmationsNtfnfailures silently stopped monitoringhandleWithdrawalfailure prevented state persistence, breaking recoveryChanges
handleWithdrawalso recovery works even if monitoring setup failslndclient.WithReOrgChan()- on reorg after spend detection, returns to spendwatching (not just confirmation re-registration) since the spend tx itself may be invalidated
handleWithdrawalasync/best-effort since tx is already publishedTesting
go test -v ./staticaddr/withdraw/...🤖 Generated with Claude Code