Skip to content

Include inbound-claimed-HTLCs in reported channel balances #1268

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

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

TheBlueMatt
Copy link
Collaborator

@TheBlueMatt TheBlueMatt commented Jan 20, 2022

Given the balance is reported as "total balance if we went to chain
ignoring fees", it seems reasonable to include claimed HTLCs - if
we went to chain we'd get those funds, less on-chain fees. Further,
if we do not include them, its possible to have pending outbound
holding-cell HTLCs underflow the balance calculation, causing a
panic in debug mode, and bogus values in release.

This resolves a subtraction underflow bug found by the
chanmon_consistency fuzz target.

@TheBlueMatt TheBlueMatt added this to the 0.0.105 milestone Jan 20, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2022

Codecov Report

Merging #1268 (1818c4a) into main (35d4ebb) will increase coverage by 1.55%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1268      +/-   ##
==========================================
+ Coverage   90.40%   91.96%   +1.55%     
==========================================
  Files          71       71              
  Lines       38135    47519    +9384     
==========================================
+ Hits        34476    43700    +9224     
- Misses       3659     3819     +160     
Impacted Files Coverage Δ
lightning/src/ln/channel.rs 92.95% <100.00%> (+3.60%) ⬆️
lightning/src/ln/functional_tests.rs 98.48% <100.00%> (+1.11%) ⬆️
lightning/src/util/enforcing_trait_impls.rs 86.82% <0.00%> (-2.66%) ⬇️
lightning-invoice/src/de.rs 79.55% <0.00%> (-1.18%) ⬇️
lightning/src/ln/chanmon_update_fail_tests.rs 97.73% <0.00%> (+0.03%) ⬆️
lightning/src/util/test_utils.rs 82.39% <0.00%> (+0.18%) ⬆️
lightning/src/chain/channelmonitor.rs 91.80% <0.00%> (+0.23%) ⬆️
lightning/src/routing/scoring.rs 94.31% <0.00%> (+1.04%) ⬆️
lightning/src/routing/router.rs 93.01% <0.00%> (+1.20%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35d4ebb...1818c4a. Read the comment docs.

@TheBlueMatt TheBlueMatt force-pushed the 2022-01-balance-underflow branch from 83588a3 to 584920c Compare January 24, 2022 23:16
@TheBlueMatt
Copy link
Collaborator Author

Added a test, while adding it I discovered this is even harder to hit than I thought, you have to write a custom router on top and can only happen on the first HTLC after open cause otherwise the reserve value protects us against underflow. Would still be nice to land for 105, but its really hard to hit.

arik-so
arik-so previously approved these changes Feb 10, 2022
Given the balance is reported as "total balance if we went to chain
ignoring fees", it seems reasonable to include claimed HTLCs - if
we went to chain we'd get those funds, less on-chain fees. Further,
if we do not include them, its possible to have pending outbound
holding-cell HTLCs underflow the balance calculation, causing a
panic in debug mode, and bogus values in release.

This resolves a subtraction underflow bug found by the
`chanmon_consistency` fuzz target.
@TheBlueMatt TheBlueMatt dismissed stale reviews from arik-so and valentinewallace via 1818c4a February 10, 2022 22:25
@TheBlueMatt TheBlueMatt force-pushed the 2022-01-balance-underflow branch from 584920c to 1818c4a Compare February 10, 2022 22:25
Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

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

looks great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants