Skip to content
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

Implement on-the-fly funding based on splicing and liquidity ads #2861

Merged
merged 9 commits into from
Sep 25, 2024

Commits on Sep 24, 2024

  1. Add on_the_fly_funding feature bit and messages

    Add the (disabled by default) `on_the_fly_funding` feature bit and
    codecs for the corresponding messages:
    
    - `will_add_htlc`
    - `will_fail_htlc`
    - `will_fail_malformed_htlc`
    - `cancel_on_the_fly_funding`
    
    We also add a TLV to `update_add_htlc` to notify the recipient that we
    relayed less data than what the onion encodes, in exchange for the fees
    of the specified funding transaction.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    e894d8a View commit details
    Browse the repository at this point in the history
  2. Add non_initiator_pays_commit_fees channel flag

    We add a non-standard channel flag to `open_channel2` to allow wallets
    to ask their peer to pay the commit tx fees, even when they're not the
    channel opener. This is necessary for on-the-fly funding, until we can
    move to 0-fee commit txs which will make it obsolete.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    e2e21a4 View commit details
    Browse the repository at this point in the history
  3. Allow underpaying feerate when using future HTLCs

    When an interactive-tx session is created for a liquidity purchase that
    uses future HTLCs to pay fees, the initiator may not have enough funds
    to honor the target feerate. We allow the transaction anyway, because
    we want to get paid for the liquidity we're providing. If the feerate
    is too low and the transaction doesn't confirm, we can double-spend it
    if we need that liquidity elsewhere.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    cddf848 View commit details
    Browse the repository at this point in the history
  4. Add funding_fee field to CMD_ADD_HTLC

    This commit adds the funding fee field to HTLCs, but never sets it.
    We update a lot of test files, but there is no functional change.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    fa2bf42 View commit details
    Browse the repository at this point in the history
  5. Implement on-the-fly funding

    Implement the on-the-fly funding protocol: when a payment cannot be
    relayed because of a liquidity issue, we notify the `Peer` actor that
    we'd like to trigger on-the-fly funding if available. If available, we
    we send a funding proposal to our peer and keep track of its status.
    
    Once a matching funding transaction is signed, we persist this funding
    attempt and wait for the additional liquidity to be available (once the
    channel is ready or the splice locked). We will then frequently try to
    relay the payment to get paid our liquidity fees. If the payment keeps
    getting rejected, or we cannot connect to our peer, we abandon the
    payment when it reaches its CLTV expiry, which ensures that the upstream
    channels are not at risk.
    
    When using on-the-fly funding, we use a single channel with our peer.
    If they try to open another channel while one is available, we reject
    their request and expect a splice instead.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    a4a7264 View commit details
    Browse the repository at this point in the history
  6. Add requireConfirmedInputs to non-initiator init

    Similar to #2461 but for the non-initiator of a channel open.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    2fe9265 View commit details
    Browse the repository at this point in the history
  7. Don't initiate on-the-fly-funding if remote feature not active

    We check the remote features before initiating an on-the-fly funding
    attempt: it doesn't make sense to initiate it if our peer has not
    activated the feature.
    t-bast committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    4c4d486 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    7e740e6 View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2024

  1. Process CommandResponse first, settlement next

    Instead of handling command responses and settlement in parallel (which
    is a bit confusing), we stash settlements, process all command
    responses, and then preocess all settlements.
    
    This makes the flow a bit more strict (as modifications to tests show),
    but it's easier to follow what the fsm does.
    t-bast committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    8938451 View commit details
    Browse the repository at this point in the history