') + ')', '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); } })(); })(); Add Shared Input support in interactive TX construction by optout21 · Pull Request #3842 · lightningdevkit/rust-lightning · GitHub
Skip to content

Add Shared Input support in interactive TX construction - #3842

Merged
wpaulino merged 3 commits into
lightningdevkit:mainfrom
optout21:shared-input
Jul 15, 2025
Merged

Add Shared Input support in interactive TX construction#3842
wpaulino merged 3 commits into
lightningdevkit:mainfrom
optout21:shared-input

Conversation

@optout21

@optout21optout21 commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

In interactive TX construction, add support for shared input:

  • if we expect a shared input, make sure that the remote node provides it
  • if we provide a shared input, make sure that it's accounted appropriately

Additionally, the prevtx field of the TxAddInput message is changed to Optional, as it should not be set for the shared input (it cannot, as the full funding transaction is not stored on the acceptor side) (spec discussion: lightning/bolts#1160 (comment))

To be used by splicing, see #3736 .

Note: this PR does not include splicing negotiation.

@ldk-reviews-bot

ldk-reviews-bot commented Jun 10, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @wpaulino 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.

@optout21
optout21 marked this pull request as ready for review June 11, 2025 19:03
Comment threadlightning/src/ln/msgs.rs Outdated
Comment threadlightning/src/ln/msgs.rs
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @dunxen@jkczyz! 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.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @dunxen@jkczyz! 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.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @dunxen@jkczyz! 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.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @dunxen@jkczyz! 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.

@optout21

Copy link
Copy Markdown
ContributorAuthor

Great, can you push those changes here then and rework the shared funding input work to follow a similar approach?

I managed to do it: first I refactored the shared output support as discussed, then added shared input support in a similar style. Although this PR does not include spicing, I also checked the changes with splicing (shared input is used there).

@optout21
optout21force-pushed the shared-input branch 5 times, most recently from 166e364 to b2e0da8CompareJune 16, 2025 13:47
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs
@optout21
optout21 requested a review from wpaulinoJune 17, 2025 03:10
@optout21

Copy link
Copy Markdown
ContributorAuthor

@wpaulino thanks for the comments. I will process them (I've re-requested review accidentally, please ignore that).

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 3rd Reminder

Hey @dunxen@jkczyz@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.

1 similar comment
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 3rd Reminder

Hey @dunxen@jkczyz@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.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @dunxen@jkczyz@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.

Comment threadlightning/src/ln/msgs.rs Outdated
@codecov

codecovBot commented Jun 19, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.61240% with 67 lines in your changes missing coverage. Please review.

Project coverage is 90.10%. Comparing base (bed20cf) to head (e4dd8be).
Report is 34 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/interactivetxs.rs90.30%51 Missing and 7 partials ⚠️
lightning/src/ln/channel.rs54.54%5 Missing ⚠️
lightning/src/util/ser.rs63.63%4 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3842 +/- ##
==========================================
+ Coverage 89.72% 90.10% +0.38% 
==========================================
Files 164 165 +1 Lines 133359 132400 -959 Branches 133359 132400 -959 ==========================================
- Hits 119651 119296 -355 + Misses 11037 10728 -309 + Partials 2671 2376 -295 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
@optout21

optout21 commented Jul 2, 2025

Copy link
Copy Markdown
ContributorAuthor

Review comments addressed, some minor (doc) changes applied.
I've squashed the fixups into the 2 main commits.
Ready for review from my part.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 10th 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.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 3rd 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.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 11th 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.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 4th 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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment on lines +1926 to +1928
if is_initiator {
our_funding_inputs_weight =
our_funding_inputs_weight.saturating_add(estimate_input_weight(output).to_wu());
} else {
return Err(AbortReason::PrevTxOutInvalid);
our_funding_inputs_weight.saturating_add(P2WSH_INPUT_WEIGHT_LOWER_BOUND);

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.

As a reader of the method though, it seems clearer to keep all the additional weight tracking when we're the initiator in one place.

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

ghost commented Jul 9, 2025

Copy link
Copy Markdown

🔔 12th Reminder

Hey @dunxen! 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.

@jkczyzjkczyz self-assigned this Jul 10, 2025

ghost 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.

Taking this PR on since @optout21 is unavailable for a week.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment on lines +1926 to +1928
if is_initiator {
our_funding_inputs_weight =
our_funding_inputs_weight.saturating_add(estimate_input_weight(output).to_wu());
} else {
return Err(AbortReason::PrevTxOutInvalid);
our_funding_inputs_weight.saturating_add(P2WSH_INPUT_WEIGHT_LOWER_BOUND);

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.

I ended up moving this since doing so is more consistent with how the shared output is included in the weight. That is, shared output weight is not included in our_funding_outputs_weight, so including the shared input in our_funding_inputs_weight is not consistent.

Comment threadlightning/src/ln/interactivetxs.rs

ghost 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.

LGTM after squash

script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
};

let interactive_tx_constructor = Some(InteractiveTxConstructor::new(

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.

Pre-existing, but it looks like we shouldn't be initializing a constructor now, and should be relying on begin_interactive_funding_tx_construction to do it instead. Let's leave it for a follow-up.

Comment threadlightning/src/ln/interactivetxs.rs
optout added 2 commits July 11, 2025 09:45
This simplifies tracking separately the expected and actual shared output.
In the initiator case, we can just provide the shared output separately,
instead of including it within other outputs, and marking which one is the output.
We can use the same field for the intended shared output in the initiator
case, and the expected one in the acceptor case.
In interactivetxs, add support for shared inputs, similar to shared outputs.
A shared input is optional, and is used in case of splicing to add
the current funding as an input.
Comment threadlightning/src/ln/interactivetxs.rs Outdated
@ldk-reviews-bot

ghost commented Jul 12, 2025

Copy link
Copy Markdown

🔔 13th 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.

@ldk-reviews-bot

ghost commented Jul 14, 2025

Copy link
Copy Markdown

🔔 14th 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.

@ldk-reviews-bot

ghost commented Jul 14, 2025

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.

Instead of calculating the fee for the entire weight contributed by the
counterparty, each portion of the weight was calculated individually
before summed. That caused a rounding error that is avoided by summing
the weights first.
Comment threadlightning/src/ln/interactivetxs.rs
@wpaulino

ghost commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Merging with one approval since @jkczyz took over and his is implicit.

@wpaulino
wpaulino merged commit 1d507f2 into lightningdevkit:mainJul 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

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