-
Notifications
You must be signed in to change notification settings - Fork 424
Expose our "offchain balance" in Balances
#4267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Expose our "offchain balance" in Balances
#4267
Conversation
`Balance` seeks to expose our balance accurate based on what we would get, less fees, if we were to force-close right now. This is great, but for an end-user wallet its not really what you want to display as the "balance" of the wallet. Instead, you want to give a balance which matches the sum of HTLCs received over time, which is only possible when balance information is avilable which ignores things like dust, anchors, fees, and reserve values. Here we provide such a balance - a new "offchain balance" in `HolderCommitmentTransactionBalance`.
|
I've assigned @joostjager as a reviewer! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4267 +/- ##
========================================
Coverage 89.32% 89.32%
========================================
Files 180 180
Lines 139267 139410 +143
Branches 139267 139410 +143
========================================
+ Hits 124402 124530 +128
- Misses 12235 12254 +19
+ Partials 2630 2626 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| pub struct HolderCommitmentTransactionBalance { | ||
| /// The amount available to claim, in satoshis, excluding the on-chain fees which will be | ||
| /// required to do so. | ||
| pub amount_satoshis: u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming to amount_onchain_satoshis might be helpful to avoid confusion. Or maybe it should be amount_unilateral_close_satoshis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good point. What about amount_claimable_satoshis? Initially I thought that might be confusing as there's a somewhat separate concept of "claimable" between on-chain and off-chain, but actually they're pretty related - the amount we're allowed to send off-chain is, basically, the amount we're able to claim on-chain in an FC, with the one exception being dust, but that only applies for channels with 0 reserve (which are mostly end-user channels and probably use the amount_offchain_satoshis. Its also a part of Balance::ClaimableOnChannelClose which makes it align better I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Claimable" as the unilaterally recoverable balance does seem like an improvement. And it often remains hard to capture the full meaning in a name when dealing with lightning concepts.
| /// | ||
| /// This is generally roughly equal to [`Self::amount_satoshis`] + | ||
| /// [`Self::transaction_fee_satoshis`] + any anchor outputs in the current commitment | ||
| /// transaction. It might differ slightly due to differences in rounding and HTLC calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What differences in rounding and htlc calculation cause this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fee is calculated by just totaling the transaction fee (funding amount minus sum of all the outputs). The amount-offchain is the actual channel balance minus HTLCs pending outbound (in msats) plus inbound HTLCs we have the preimage for.
The HTLC difference is the fees on outputs for inbound HTLCs we have the preimages for, rounding is totally different as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider describing some of this in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, spent a minute fighting with it but not sure how to add it such that its actually useful information. It shouldn't differ by more than a few sats, so going into detail about how its all calculated seems kinda overkill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes not critical to add. Just the question that came to mind when reading the comment.
| balance_candidates.last().map(|balance| balance.amount_offchain_satoshis.unwrap_or(balance.amount_satoshis)).unwrap_or(0) | ||
| } | ||
| }, | ||
| Balance::ClaimableAwaitingConfirmations { amount_satoshis, .. }| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't offchain_amount_satoshis be undefined if the channel is no longer offchain? Maybe this indicates that the name isn't fully covering the meaning of the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, maybe the name could use some workshopping. My intended use here is really "balance that an end-user wallet might care about" which obviously includes funds which we're in the process of claiming on-chain, but until we close its not really anything corresponding to anything "on-chain". I'm definitely open to a better name, if you have any thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_balance maybe? That is quite indirect though, but maybe it is good to steer away from onchain/offchain because there are nuances to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't want to imply that our devs should prefer this as the "balance". Its really not - the claimable amount is closer to the "balance" IMO, though of course its a bit misleading as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, don't know. Maybe 2nd reviewer has inspiration...
| #[derive(Clone, Debug)] | ||
| pub struct CommitmentTransaction { | ||
| commitment_number: u64, | ||
| to_broadcaster_value_offchain_msat: Option<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were there other data structures that could have stored this value? The field looks a bit out of place between all the on-chain properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could put it directly in the ChannelMonitorUpdateStep::LatestCounterpartyCommitment but it doesn't really feel like it belongs there any more. The nice thing about being in the CommitmentTransaction is it will (eventually) go through the custom commitment transaction API, which I think feels right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LatestCounterpartyCommitment does have some additional non-on-chain info like htlc sources already. But not sure how those two options compare.
The nice thing about being in the CommitmentTransaction is it will (eventually) go through the custom commitment transaction API
Can you elaborate a bit more on what it brings to have to_broadcaster_value_offchain_msat go through the custom commit tx API? That the calculation of value_offchain can also be custom you mean?
|
👋 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. |
In a previous commit we introduced the concept of the "offchain balance" to `HolderCommitmentTransactionBalance` to better capture the type of balance that end-user walets likely wish to expose. Here we expose an accessor on `Balance` to fetch that concept across difference `Balance` variants easily. Fixes lightningdevkit#4241
0b0f140 to
4f1abd3
Compare
Fixes #4241.