Skip to content

Conversation

wpaulino
Copy link
Contributor

Similar to FundedChannel::get_available_balances, we should reflect the correct balance in the monitor based on the current state of a splice. While the channel is still open, we consider our balance to be the lowest balance across all commitment transaction candidates for the current state. Once the channel has a confirmed commitment transaction, we report the balance specific to the corresponding FundingScope being spent.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 26, 2025

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

@wpaulino wpaulino self-assigned this Aug 26, 2025
@wpaulino wpaulino requested review from TheBlueMatt and jkczyz August 26, 2025 16:46
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 97.72727% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.36%. Comparing base (b40dca0) to head (5adf873).
⚠️ Report is 84 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 94.73% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4029      +/-   ##
==========================================
- Coverage   88.56%   88.36%   -0.21%     
==========================================
  Files         175      177       +2     
  Lines      129175   131529    +2354     
  Branches   129175   131529    +2354     
==========================================
+ Hits       114408   116226    +1818     
- Misses      12246    12649     +403     
- Partials     2521     2654     +133     
Flag Coverage Δ
fuzzing 21.62% <0.00%> (?)
tests 88.20% <97.72%> (-0.37%) ⬇️

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.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

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

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

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

@TheBlueMatt
Copy link
Collaborator

Discussed this one offline, needs the balance stuff to consider splices.

@TheBlueMatt TheBlueMatt removed the request for review from jkczyz August 30, 2025 17:18
@wpaulino wpaulino force-pushed the splice-claimable-balances branch 3 times, most recently from 3ae60bf to b5244ee Compare September 2, 2025 16:31
@wpaulino wpaulino requested a review from TheBlueMatt September 2, 2025 16:39
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

I think this LGTM.

@@ -928,7 +946,11 @@ impl Balance {
#[rustfmt::skip]
pub fn claimable_amount_satoshis(&self) -> u64 {
match self {
Balance::ClaimableOnChannelClose { amount_satoshis, .. }|
Balance::ClaimableOnChannelClose { balance_candidates, .. } => {
// FIXME: Should we report the balance for the currently confirmed splice
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is right. In practice if a splice happens you want to see your balance go down/up in accordance with where the channel is going, not where it was. We need to update the docs to describe this behavior, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if the docs added are sufficient or if we should clarify a bit more elsewhere

@ldk-reviews-bot
Copy link

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

@wpaulino wpaulino force-pushed the splice-claimable-balances branch 2 times, most recently from 0dcabb9 to a33a7bd Compare September 2, 2025 21:49
Comment on lines +821 to +825
/// The index within [`Balance::ClaimableOnChannelClose::balance_candidates`] for the
/// balance according to the current onchain state of the channel. This can be helpful when
/// wanting to determine the claimable amount when the holder commitment transaction for the
/// current funding transaction is broadcast and/or confirms.
confirmed_balance_candidate_index: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

This almost seems like an implementation detail. Should we just direct readers to claimable_amount_satoshis? Or is there another reason why they would need to use this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They could use it to always report the balance according to the chain, as opposed to claimable_amount_satoshis which only reports it when one of the splice transactions has confirmed.

Comment on lines 952 to +963
pub fn claimable_amount_satoshis(&self) -> u64 {
match self {
Balance::ClaimableOnChannelClose { amount_satoshis, .. }|
Balance::ClaimableOnChannelClose {
balance_candidates, confirmed_balance_candidate_index, ..
} => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth adding another function for transaction_fee_satoshis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be weird to only have it available for this specific variant.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

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

Balance::ClaimableOnChannelClose {
balance_candidates, confirmed_balance_candidate_index, ..
} => {
// If we have multiple candidates due to a splice, and one of the splice
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this should be mentioned in the public API as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I meant include this in the docs on confirmed_balance_candidate_index since there is meaning to non-zero values that isn't explained fully.

There are two states in which a pending splice balance should be
considered:

1. The channel has closed with a confirmed holder commitment transaction
   from a splice that did not become locked. The balance from this
   transaction is reported.
2. The channel is open and has multiple holder commitment transaction
   candidates that are valid based on the funding transaction that
   confirms. We want to report the pending splice balance to users while
   it has yet to become locked, such that they are able to see their
   funds have moved from their onchain wallet to the channel. We default
   to reporting the latest splice/RBF balance via
   `Balance::claimable_amount_satoshis` to mimic how an onchain wallet
   would behave when reporting unconfirmed balance, otherwise we report
   the balance for the confirmed splice transaction.
@wpaulino wpaulino force-pushed the splice-claimable-balances branch from a33a7bd to 5adf873 Compare September 11, 2025 19:31
Balance::ClaimableOnChannelClose {
balance_candidates, confirmed_balance_candidate_index, ..
} => {
// If we have multiple candidates due to a splice, and one of the splice
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I meant include this in the docs on confirmed_balance_candidate_index since there is meaning to non-zero values that isn't explained fully.

/// When multiple candidates exist, the last one reflects the balance of the
/// latest splice/RBF attempt, while the first reflects the balance prior to the splice
/// occurring.
balance_candidates: Vec<HolderCommitmentTransactionBalance>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Presumably this should also have docs for when things are removed from this vec.

@TheBlueMatt TheBlueMatt merged commit e5594ea into lightningdevkit:main Sep 12, 2025
25 checks passed
@wpaulino wpaulino deleted the splice-claimable-balances branch September 12, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants