Skip to content

Remove AvailableBalances::balance_msat - #2476

Merged
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
wvanlint:remove_balance_msat
Aug 15, 2023
Merged

Remove AvailableBalances::balance_msat#2476
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
wvanlint:remove_balance_msat

Conversation

@wvanlint

Copy link
Copy Markdown
Contributor

This PR removes the AvailableBalances::balance_msat field.

After a discussion on Discord, it was mentioned ChannelMonitor::get_claimable_balances provides a more straightforward approach to the balance of a channel, which satisfies most use cases. The computation of AvailableBalances::balance_msat is complex and originally had a different purpose that is not applicable anymore.

Its computation takes into account holding cell HTLCs and fulfills inbound-claimed HTLCs since https://github.com/lightningdevkit/rust-lightning/pull/1268/files. However, the root cause of the underflow that was the motivation of that PR does not exist anymore. At that time, the amount in send_htlc was verified against the CommitmentStats (and this commitment transaction resolves the pending HTLC in the InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) state). Currently, we're verifying against AvailableBalances::next_outbound_htlc_limit_msat which does not resolve such pending HTLCs. I copied and reran the test in #1268 from the main branch and it is not possible to send an HTLC back anymore and cause an underflow (sending the return payment fails with Cannot send more than our next-HTLC maximum). This is likely why the test has been removed.

@wvanlint
wvanlintforce-pushed the remove_balance_msat branch from 31b7419 to 124d2a9CompareAugust 6, 2023 00:47
@codecov-commenter

codecov-commenter commented Aug 6, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage has no change and project coverage change: -0.01%⚠️

Comparison is base (a24626b) 90.40% compared to head (ef5be58) 90.40%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@ Coverage Diff @@## main #2476 +/- ##
==========================================
- Coverage 90.40% 90.40% -0.01% 
==========================================
Files 106 106 Lines 56328 56321 -7 Branches 56328 56321 -7 ==========================================
- Hits 50926 50916 -10 - Misses 5402 5405 +3 
Files ChangedCoverage Δ
lightning/src/chain/chainmonitor.rs95.03% <ø> (ø)
lightning/src/ln/channel.rs89.44% <ø> (-0.02%)⬇️
lightning/src/ln/channelmanager.rs85.69% <ø> (-0.01%)⬇️
lightning/src/routing/router.rs93.60% <ø> (-0.04%)⬇️

... and 2 files with indirect coverage changes

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

@valentinewallace

Copy link
Copy Markdown
Contributor

Could you add a release note regarding serialization compatibility to the pending_changelog folder and a bit more detail to the commit message? Basically LGTM otherwise. thanks!

Comment threadlightning/src/ln/channelmanager.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, thanks.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wvanlint
wvanlintforce-pushed the remove_balance_msat branch 3 times, most recently from 817548d to c1bb5d3CompareAugust 9, 2023 23:40
Comment on lines -68 to -69
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
pub balance_msat: u64,

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 remove this, is there still a way to calculate our balance with msat precision since ChannelMonitor::get_claimable_balances will be rounded to sats?

@wvanlintwvanlintAug 10, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not currently. With regard to AvailableBalances::balance_msat, its computation was very specific to a use case that is not applicable anymore and its value is likely not what is expected. For introspection at msat precision, perhaps Channel::value_to_self_msat and the pending HTLCs can be exposed? For the latter, see #2442.

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.

perhaps Channel::value_to_self_msat

Hm, perhaps. Will take a look at #2442, thanks!

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.

Hmm, what would the use case be for getting a claimable balance in msat? on-chain doesn't have msats

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking just to get our channel balance in general, not necessarily on-chain

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.

Ah okay. It's nice to have a specific use case for a balance IMO, pretty vague term in lightning. Maybe something like that would be useful for accounting reasons, though 🤷‍♀️

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.

Yea it's probably not a big deal to not have it for now

@wvanlint
wvanlint marked this pull request as ready for review August 10, 2023 06:56
@wvanlint

Copy link
Copy Markdown
ContributorAuthor

Adjusted documentation and serialization compatibility.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment threadpending_changelog/remove_balance_msat.txt Outdated
Comment on lines -68 to -69
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
pub balance_msat: u64,

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.

Hmm, what would the use case be for getting a claimable balance in msat? on-chain doesn't have msats

@wvanlint
wvanlintforce-pushed the remove_balance_msat branch 2 times, most recently from fb4b56f to 67b47bfCompareAugust 10, 2023 22:38
valentinewallace
valentinewallace previously approved these changes Aug 11, 2023
(12, unspendable_punishment_reserve, option),
(14, user_channel_id_low, required),
(16, balance_msat, required),
(16, _balance_msat, option), // Backwards compatibility for removed balance_msat field.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

God rustc pisses me off for doing this - it just blindly picks a type (IIRC i64, so we're okay) and assumes that that's the type we want here. Its completely nonsense and results in code that does surprising things. Can you re-add the let _balance_msat: Option<u64> = _balance_msat below?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ah thanks for catching this! Re-added the type hint.

The ChannelMonitor::get_claimable_balances method provides a more
straightforward approach to the balance of a channel, which satisfies
most use cases. The computation of AvailableBalances::balance_msat is
complex and originally had a different purpose that is not applicable
anymore.
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.

5 participants

@wvanlint@codecov-commenter@valentinewallace@TheBlueMatt@alecchendev