') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Batch `commitment_signed` messages for splicing by jkczyz · Pull Request #3651 · lightningdevkit/rust-lightning · GitHub
Skip to content

Batch commitment_signed messages for splicing - #3651

Merged
wpaulino merged 7 commits into
lightningdevkit:mainfrom
jkczyz:2025-03-multiple-funding-scopes
Apr 4, 2025
Merged

Batch commitment_signed messages for splicing#3651
wpaulino merged 7 commits into
lightningdevkit:mainfrom
jkczyz:2025-03-multiple-funding-scopes

Conversation

@jkczyz

@jkczyzjkczyz commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

Once a channel is funded, it may be spliced to add or remove funds. The new funding transaction is pending until confirmed on chain and thus needs to be tracked. Additionally, it may be replaced by another transaction using RBF with a higher fee. Hence, there may be more than one pending FundingScope to track for a splice.

This PR adds support for tracking pending funding scopes and accounting for any pending scopes where applicable (e.g., when handling and sending commitment_signed messages).

@ldk-reviews-bot

ldk-reviews-bot commented Mar 6, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@jkczyz
jkczyz requested a review from wpaulinoMarch 6, 2025 22:59
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

@wpaulino Just looking for a quick concept ACK. Still needed:

  • serialization of pending_funding, presumably?
  • tests for commitment_signed
  • update get_available_balances

@wpaulinowpaulino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah this makes sense. We'll need to support sending a commitment_signed for each scope as well.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Yeah this makes sense. We'll need to support sending a commitment_signed for each scope as well.

By this do you mean we'll need msgs::CommitmentUpdate to contain a Vec of msgs::CommitmentSigned messages instead of a single one?

@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Pushed another commit for get_available_balances.

@wpaulino

Copy link
Copy Markdown
Contributor

By this do you mean we'll need msgs::CommitmentUpdate to contain a Vec of msgs::CommitmentSigned messages instead of a single one?

Yeah we'll need to go through each case where we owe the counterparty a commitment_signed (except for the initial one sent in dual funding/splicing) and make sure we always consider all scopes.

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from eac7be9 to 8b4e46aCompareMarch 11, 2025 22:44
@jkczyzjkczyz changed the title Add pending funding scopes to FundedChannelBatch commitment_signed messages for splicingMar 11, 2025
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Yeah we'll need to go through each case where we owe the counterparty a commitment_signed (except for the initial one sent in dual funding/splicing) and make sure we always consider all scopes.

Pushed a couple commits that I think accomplish this. Though I'm not sure about the following line from build_commitment_no_status_check:

let(mut htlcs_ref, counterparty_commitment_tx) =
self.build_commitment_no_state_update(&self.funding, logger);

It is called from methods like send_htlc_and_commit but for producing a ChannelMonitorUpdate. IIUC, I'll need to do this for all funding scopes?

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from c66e554 to 2db5c60CompareMarch 12, 2025 22:34
@jkczyz
jkczyz marked this pull request as ready for review March 12, 2025 22:35
@jkczyz
jkczyz requested a review from wpaulinoMarch 12, 2025 22:35
Comment threadlightning/src/ln/channel.rs Outdated
@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch 2 times, most recently from 3872586 to e371143CompareMarch 12, 2025 22:46
@jkczyzjkczyz added the weekly goal Someone wants to land this this week label Mar 12, 2025
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Rebased on main.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
@jkczyz
jkczyz requested a review from dunxenMarch 17, 2025 15:45
@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from e371143 to 0362159CompareMarch 18, 2025 23:01
@jkczyz
jkczyz requested a review from wpaulinoMarch 18, 2025 23:02
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @dunxen@wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from 0362159 to 7021e01CompareMarch 19, 2025 21:45
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Responded and addressed a couple lingering comments.

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch 3 times, most recently from 48bdd52 to 6db1c42CompareMarch 21, 2025 14:42
@TheBlueMatt
TheBlueMatt removed their request for review April 2, 2025 17:57
@wpaulino
wpaulino removed their request for review April 2, 2025 22:13
@wpaulino

Copy link
Copy Markdown
Contributor

This is pretty much there, will give it a final pass once squashed and rebased

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from 1695c74 to 1456a7dCompareApril 2, 2025 23:40
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Rebased and fixed fuzz tests (compilation error and log assertion update).

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from 1456a7d to 19e8b5cCompareApril 3, 2025 00:01
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Rebased again to resolve a couple merge conflicts and squashed.

@jkczyz
jkczyzforce-pushed the 2025-03-multiple-funding-scopes branch from 19e8b5c to cbd7bf8CompareApril 3, 2025 00:15
@jkczyz

Copy link
Copy Markdown
ContributorAuthor

Looks like CI was failing because the benchmarks failed to compile. Fixed in the latest push.

TheBlueMatt
TheBlueMatt previously approved these changes Apr 3, 2025
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops already needs rebase.

jkczyz added 7 commits April 3, 2025 12:48
Once a channel is funded, it may be spliced to add or remove funds. The
new funding transaction is pending until confirmed on chain and thus
needs to be tracked. Additionally, it may be replaced by another
transaction using RBF with a higher fee. Hence, there may be more than
one pending FundingScope to track for a splice.
This commit adds support for tracking pending funding scopes. The
following commits will account for any pending scopes where applicable
(e.g., when handling commitment_signed).
A FundedChannel may have more than one pending FundingScope during
splicing, one for the splice attempt and one or more for any RBF
attempts. When this is the case, send a commitment_signed message for
each FundingScope and include the necessary batch information (i.e.,
batch_size and funding_txid) to the counterparty.
Splicing introduces a concept of batched commitment_signed messages for
each pending splice transaction. These can be treated as one logical
message, even though the protocol currently defines them as separate
commitment_signed messages with a TLV for batch information.
Add a LogicalMessage wrapper around wire::Message such that it can be
used internally by PeerManager. A CommitmentSignedBatch variant will be
added in the next commit.
During splicing, commitment_signed messages need to be collected into a
single batch before they are handled. Rather than including this as part
of the channel state machine logic, batch when reading messages from the
wire since they can be considered one logical message.
A FundedChannel may have more than one pending FundingScope during
splicing, one for the splice attempt and one or more for any RBF
attempts. The counterparty will send a commitment_signed message for
each pending splice transaction and the current funding transaction.
Defer handling these commitment_signed messages until the entire batch
has arrived. Then validate them individually, also checking if all the
pending splice transactions and the current funding transaction have a
corresponding commitment_signed in the batch.
A FundedChannel may have more than one pending FundingScope during
splicing, one for the splice attempt and one or more for any RBF
attempts. When calling get_available_balances, consider all funding
scopes and take the minimum by next_outbound_htlc_limit_msat. This is
used both informationally and to determine which channel to use to
forward an HTLC.
The choice of next_outbound_htlc_limit_msat is somewhat arbitrary but
matches the field used when determining which channel used to forward an
HTLC. Any field should do since each field should be adjusted by the
same amount relative to another FundingScope given the nature of the
fields (i.e., inbound/outbound capacity, min/max HTLC limit).
Using the minimum was chosen since an order for an HTLC to be sent over
the channel, it must be possible for each funding scope -- both the
confirmed one and any pending scopes, one of which may eventually
confirm.

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Rebased to resolve merge conflict.

Comment threadlightning/src/ln/channel.rs
@jkczyz
jkczyz requested a review from TheBlueMattApril 3, 2025 17:57
@wpaulino

Copy link
Copy Markdown
Contributor

Merging this as the linting failure has already been fixed separately.

@wpaulino
wpaulino merged commit c4d23bc into lightningdevkit:mainApr 4, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@jkczyz@ldk-reviews-bot@wpaulino@TheBlueMatt@dunxen