Skip to content

staticaddr: channel funding with deposits#1040

Merged
hieblmi merged 16 commits intolightninglabs:masterfrom
hieblmi:static-open-channel
Feb 26, 2026
Merged

staticaddr: channel funding with deposits#1040
hieblmi merged 16 commits intolightninglabs:masterfrom
hieblmi:static-open-channel

Conversation

@hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Nov 11, 2025

depends on #1073

This PR introduces a openchannel subcommand to static addresses.

It provides the same experience as lncli openchannel.
Exmples:

Open a channel with all available deposits:

loop static openchannel --fundmax --sat_per_vbyte XXX --private ...

Open a channel with specified local funding amount, coin-selected from available deposits under fee and dust considerations.

loop static openchannel --local_amt XXX --sat_per_vbyte YYY --private ...

Open a channel from two deposits AAA and BBB while taking their combined value(fundmax) as funding amount and considering fees and dust limit.

loop static openchannel --utxo AAA --utxo BBB --fundmax --sat_per_vbyte YYY --private ...

Open a channel from two deposits AAA and BBB while taking a specified amount(local_amt) as funding amount and considering fees and dust limit.

loop static openchannel --utxo AAA --utxo BBB --local_amt --sat_per_vbyte YYY --private ...

TODOs:

  • Integration tests

@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 significantly extends the functionality of static addresses by enabling them to be used as a source for funding Lightning channels. It introduces a new openchannel command that integrates a robust PSBT-based funding flow with lnd, offering flexible options for selecting deposits. This enhancement allows users to seamlessly convert their static address funds into channel liquidity, thereby increasing the utility and versatility of static addresses within the Lightning ecosystem.

Highlights

  • New openchannel subcommand: Introduced a new openchannel subcommand under loop static which allows users to fund Lightning channels directly from their static address deposits.
  • Flexible Channel Funding Options: The new command supports various funding options, including fundmax to use all available deposits, local_amt for a specified amount, and explicit UTXO selection, mirroring the experience of lncli openchannel.
  • PSBT-based Funding Flow: The channel funding process leverages a Partially Signed Bitcoin Transaction (PSBT) flow, enabling secure and collaborative transaction construction with lnd.
  • New Deposit States: Added new deposit states, opening_channel and channel_published, to track the lifecycle of deposits used for channel funding.
  • Code Refactoring and Reusability: Common utility functions related to PSBTs, Musig2 sessions, and outpoint handling have been refactored into a new staticutil package, improving code organization and reusability across static address features.
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.

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 introduces a new openchannel subcommand for static addresses, allowing users to fund channels from their deposits. The implementation is comprehensive, covering the command-line interface, RPC definitions, daemon logic, and documentation.

My review focuses on the new cmd/loop/openchannel.go file, where I've identified a few issues related to context handling, input validation, and error wrapping. These are important for ensuring the robustness and maintainability of the new command.

The refactoring to move utility functions into a staticutil package is a great improvement for code organization and reuse. The protocol changes to use PSBT for withdrawals are also a solid enhancement.

Overall, this is a well-structured PR that adds significant functionality. Addressing the feedback will further improve its quality.

@hieblmi hieblmi force-pushed the static-open-channel branch 4 times, most recently from f9b49dc to 9d37fca Compare November 12, 2025 10:24
@hieblmi hieblmi self-assigned this Nov 17, 2025
@hieblmi hieblmi force-pushed the static-open-channel branch 9 times, most recently from 94f45cc to 375cf47 Compare November 19, 2025 07:55
@hieblmi hieblmi force-pushed the static-open-channel branch 9 times, most recently from 2b9378a to 5b6631d Compare December 9, 2025 15:05
@hieblmi
Copy link
Collaborator Author

hieblmi commented Dec 12, 2025

@gemini-code-assist review

@hieblmi hieblmi force-pushed the static-open-channel branch 3 times, most recently from b5a9b2e to fae04ea Compare February 26, 2026 16:24
@hieblmi
Copy link
Collaborator Author

hieblmi commented Feb 26, 2026

@starius addressed recent comments in commit e0934b6

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! 💎
Thanks! Great work!

@hieblmi hieblmi force-pushed the static-open-channel branch from fae04ea to d5d124b Compare February 26, 2026 19:26
@hieblmi hieblmi force-pushed the static-open-channel branch 2 times, most recently from 788a7b2 to 092740d Compare February 26, 2026 19:48
Remove unreachable error check after filterNewDeposits which does not
return an error. The err variable was already handled from the
ListUnspent call above and could never be non-nil at this point.
Block-based deposit fetching from the internal lnd wallet was
susceptible to wallet syncing issues. Replace it with interval-based
polling. Reconciliation errors are now logged instead of being fatal,
improving resilience during transient failures.
Protect the shimPending variable with a sync.Mutex since it is accessed
from multiple goroutines: the main loop goroutine and the server error
handling goroutine. Without synchronization this is a data race.
Return an error instead of just logging when chainhash.NewHash fails in
the ChanPending handler. The hash variable would be nil and crash on the
subsequent String() call.
…ublished

Both OpeningChannel and ChannelPublished lacked OnExpiry transitions.
handleBlockNotification fires OnExpiry on every new block once the
deposit is expired, regardless of the current state. Since both states
use NoOpAction or FinalizeDepositAction which release the FSM mutex
briefly, an OnExpiry SendEvent can sneak in. Add self-transitions so
the event is safely absorbed.
Duplicate outpoints in the request lead to fee miscalculation and an
invalid PSBT with the same input listed twice. Validate early and return
a clear error message.
If the PSBT finalize step succeeds but the stream fails before
ChanPending, deposits would remain stuck in OpeningChannel until the
next daemon restart. Run the recovery logic immediately so deposits are
resolved without requiring a restart.

Also, add tests for the following edge cases requested in review:

- Reorg: channel tx reorged, UTXOs reappear as unspent, deposits
  return to Deposited state.
- Daemon restart during channel opening: deposits in OpeningChannel
  recovered based on UTXO status (spent → ChannelPublished, unspent →
  Deposited).
- Mempool eviction: tx evicted, UTXOs unspent, deposits return to
  Deposited.
- Mempool rejection: tx never accepted, same recovery as eviction.
- Stream errors: lnd stream fails before PSBT finalize, error returned
  without errPsbtFinalized so deposits can be safely rolled back.
- PSBT finalize then stream abort: finalize succeeds but stream dies
  before ChanPending, error wrapped with errPsbtFinalized so caller
  triggers recovery instead of blind rollback.
- Duplicate outpoints: already covered by TestOpenChannelDuplicateOutpoints.
@hieblmi hieblmi force-pushed the static-open-channel branch from 092740d to a9e763f Compare February 26, 2026 19:57
@hieblmi hieblmi force-pushed the static-open-channel branch from a9e763f to f192914 Compare February 26, 2026 20:16
@hieblmi hieblmi force-pushed the static-open-channel branch from f192914 to c700650 Compare February 26, 2026 20:22
@hieblmi hieblmi merged commit 802cf87 into lightninglabs:master Feb 26, 2026
9 checks passed
@hieblmi hieblmi deleted the static-open-channel branch February 26, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants