Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TheBlueMatt@ldk-reviews-bot@jkczyz@wpaulino
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Integrate Splicing with Quiescence - #4019

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real
Aug 29, 2025
Merged

Integrate Splicing with Quiescence#4019
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
TheBlueMatt:2025-08-splice-quiescent-real

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator

Based on #4007 this does the actual integration. Will probably go after #3979 so drafting for now.

@codecov

codecovBot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.71%. Comparing base (a18f362) to head (9200308).
⚠️ Report is 40 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs77.35%12 Missing ⚠️
lightning/src/util/ser.rs0.00%7 Missing ⚠️
lightning/src/ln/channelmanager.rs81.25%2 Missing and 1 partial ⚠️
lightning/src/ln/quiescence_tests.rs92.30%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4019 +/- ##
==========================================
- Coverage 88.76% 88.71% -0.05% 
==========================================
Files 176 176 Lines 128139 128891 +752 Branches 128139 128891 +752 ==========================================
+ Hits 113743 114348 +605 - Misses 11822 11947 +125 - Partials 2574 2596 +22 
FlagCoverage Δ
fuzzing21.92% <15.27%> (+<0.01%)⬆️
tests88.54% <76.47%> (-0.05%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from be3b93a to ddb3b37CompareAugust 20, 2025 17:25
Comment threadlightning/src/ln/channel.rs Outdated
let tx16 = TransactionU16LenLimited::new(tx)
.map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;

// TODO(splicing): Check that transactions aren't too big for the splice_init message here.

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.

We probably just want to do all input validation here before we even attempt quiescence so that we can fail early and fast. No point in going through the whole stfu dance just to immediately fail back to the user with "insufficient fees" or something similar.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, that's definitely the goal. Kinda leaving this until the parameters are clear and I'll clean it up then.

@ldk-reviews-bot

ldk-reviews-bot commented Aug 21, 2025

Copy link
Copy Markdown

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

When doing an outbound splice, we check some of the instructions
first in utility methods, then convert errors to `APIError`s. These
utility methods should thus either return an `APIError` or more
generic (string or `()`) error type, but they currently return a
`ChannelError`, which is only approprite when the calling code will
do what the `ChannelError` instructs (including closing the
channel).
Here we fix that by returning `String`s instead.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from ddb3b37 to d9a278cCompareAugust 26, 2025 16:36
@TheBlueMatt
TheBlueMatt marked this pull request as ready for review August 26, 2025 16:36
@wpaulino
wpaulino requested review from jkczyz and removed request for valentinewallaceAugust 26, 2025 16:47
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/quiescence_tests.rs Outdated
Comment threadlightning/src/ln/channel.rs
// Assumes we are either awaiting quiescence or our counterparty has requested quiescence.
#[rustfmt::skip]
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, ChannelError>
pub fn send_stfu<L: Deref>(&mut self, logger: &L) -> Result<msgs::Stfu, &'static str>

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.

May as well return String if we'll just need to call to_owned.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think we'd end up with strictly more to_owneds, and we'll already have the map at the callsites to convert to a ChannelError, plus rustfmt is much more likely to blow up an Err(long string.to_owned()) than a map(|e| e.to_string()). Seems simpler to just keep the &'static str?

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

Would this happen when both counterparties initiated quiescence simultaneously? Ties should go to the channel opener. Would we lose the user-initiated quiescent_action in that case? Or rather would we possibly be stuck when the user tries to initiate the splice again since quiescent_action is Some?

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMattTheBlueMattAug 27, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We wouldn't lose it immediately, we'd wait until the counterparty's splice completes, then try to initialize our own splice and then fail at that point (because another splice is now in progress).

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.

What I mean here is that we don't retry quiescence after we've exited if we still have a quiescent_action lingering. It's generally applicable once we have other quiescence protocols, but also relevant for zero conf splices since it'll be immediately locked in and we can attempt another splice.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We should retry quiescence after we've exited, it'll just fail. We don't yet have any exiting-quiescence logic yet, however, so there's nowhere to put it yet...

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.

Should we address the TODO now (i.e., contribute using splice_ack) instead of adding retry or SpliceFailed event? Only issue would be if there were another quiescence protocol that we understood. Then we'd again have a stuck action, IIUC.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We'll ultimately need a splice failed event for the general case even if, eg a peer simply nak's a splice, no? I'm definitely happy to address the TODO now, however, is doing it trivial? Its not quite clear to me it is.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I spent some time looking at addressing the TODO and I think it really needs to come with a SpliceInstructions refactor - we need to add a max-fee and min-fee field, with some default (ie push things through a constructor rather than a public enum) and then want to move the fee-calculation logic so that we can recalculate fees if we have to. Would rather wait on this.

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

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +10950 to +10953
if self.funding.get_funding_txo() != Some(original_funding_txo) {
// This should be unreachable once we opportunistically merge splices if the
// counterparty initializes a splice.
return Err("Funding changed out from under us".to_owned());

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.

So this is preventing a user-initiated splice from happening if the counterparty happens to splice first. Why do we want this? Presumably, if they spliced, they still want to splice-in/out funds from their side of the channel and that hasn't happened yet.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

We can't splice in that case anyway until the first splice locks, so I'm not really sure its worth holding the pending splice around in that case? Also the current code would break cause we need to recalculate if the splice as proposed is possible, and what the fees should be. But I didn't bother fixing it cause I'm not sure we should wait 6 blocks then do it.

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.

We could initiate an RBF to do our splice but that's not supported yet either. Without that or being able to contribute on an incoming splice_init, then it seems we should queue a SpliceFailed event to the user?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yep, seems like we should. We don't yet have a SpliceFailed event upstream yet, tho.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +11155 to +11159
// TODO(splicing): if post_quiescence_action is set, integrate what the user wants to do
// into the counterparty-initiated splice. For always-on nodes this probably isn't a useful
// optimization, but for often-offline nodes it may be, as we may connect and immediately
// go into splicing from both sides.

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.

If we lose the tie, we don't seem to consume the quiescent_action, but we also don't seem to attempt quiescence again once we exit so that we can perform ours. We only seem to retry quiescence with a pending quescient_action after a reconnection.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from d9a278c to b37b5e4CompareAugust 27, 2025 20:45

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

Feel free to squash

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Now that we have a `QuiescentAction` to track what we intend to do
once we reach quiescence, we need to use it to initiate splices.
Here we do so, adding a new `SpliceInstructions` to track the
arguments that are currently passed to `splice_channel`. While
these may not be exactly the right arguments to track in the end,
a lot of the splice logic is still in flight, so we can worry about
it later.
While we have a test to disconnect a peer if we're waiting on an
`stfu` message, we also disconnect if we've reached quiescence but
we're waiting on a peer to do "something fundamental" and they take
too long to do so. We test that behavior here.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-08-splice-quiescent-real branch from b37b5e4 to 9200308CompareAugust 28, 2025 21:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed and addressed @wpaulino's feeedback, plus a rustfmt thing

$ git diff-tree -U3 b37b5e4e7 9200308e8
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 0ee9319df8..12d3b53905 100644
--- a/lightning/src/ln/channel.rs+++ b/lightning/src/ln/channel.rs@@ -10799,7 +10799,7 @@ where
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
- if self.pending_splice.is_some() {+ if self.pending_splice.is_some() || self.quiescent_action.is_some() {
return Err(APIError::APIMisuseError {
err: format!(
"Channel {} cannot be spliced, as it has already a splice pending",
@@ -10913,9 +10913,7 @@ where
let original_funding_txo = self.funding.get_funding_txo().ok_or_else(|| {
debug_assert!(false);
- APIError::APIMisuseError {- err: "Channel isn't yet fully funded".to_owned(),- }+ APIError::APIMisuseError { err: "Channel isn't yet fully funded".to_owned() }
})?;
let (our_funding_inputs, our_funding_outputs, change_script) = contribution.into_tx_parts();
@@ -10947,12 +10945,6 @@ where
original_funding_txo,
} = instructions;
- if self.funding.get_funding_txo() != Some(original_funding_txo) {- // This should be unreachable once we opportunistically merge splices if the- // counterparty initializes a splice.- return Err("Funding changed out from under us".to_owned());- }-
// Check if a splice has been initiated already.
// Note: only a single outstanding splice is supported (per spec)
if self.pending_splice.is_some() {
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 81c507b7d2..89992dd831 100644
--- a/lightning/src/ln/channelmanager.rs+++ b/lightning/src/ln/channelmanager.rs@@ -4495,8 +4495,12 @@ where
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
- let msg_opt = chan- .splice_channel(contribution, funding_feerate_per_kw, locktime, &&logger)?;+ let msg_opt = chan.splice_channel(+ contribution,+ funding_feerate_per_kw,+ locktime,+ &&logger,+ )?;
if let Some(msg) = msg_opt {
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {
node_id: *counterparty_node_id,

change_script: Option<ScriptBuf>,
funding_feerate_per_kw: u32,
locktime: u32,
original_funding_txo: OutPoint,

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.

This can be dropped now

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Will do in a followup, thanks.

@TheBlueMatt
TheBlueMatt merged commit 2150f24 into lightningdevkit:mainAug 29, 2025
25 checks passed
@TheBlueMattTheBlueMatt mentioned this pull request Aug 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

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