Skip to content

PaymentBandwidth uses HtlcView #1462

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 4 commits into from
Apr 22, 2025
Merged

PaymentBandwidth uses HtlcView #1462

merged 4 commits into from
Apr 22, 2025

Conversation

GeorgeTsagk
Copy link
Member

Description

When AuxTrafficShaper.PaymentBandwidth is called asynchonously we could previously report the same bandwidth for 2 different HTLCs that are validating whether they can be added to the channel. This could lead to false-positives and payment failures as the latter HTLC should be checked against the correct bandwidth.

Instead of always consulting the commitment blob on what the current asset balance is, we now use the existing helper ComputeView to get a more precise representation of the asset balance, which is enabled by the new argument lnwallet.HtlcView.

@GeorgeTsagk GeorgeTsagk requested a review from guggero April 8, 2025 18:23
@GeorgeTsagk GeorgeTsagk self-assigned this Apr 8, 2025
@GeorgeTsagk GeorgeTsagk changed the title Aux bandwidth htlcview PaymentBandwidth uses HtlcView Apr 8, 2025
@coveralls
Copy link

coveralls commented Apr 8, 2025

Pull Request Test Coverage Report for Build 14597823788

Details

  • 0 of 93 (0.0%) changed or added relevant lines in 4 files are covered.
  • 10 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+26.5%) to 55.234%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapchannel/aux_funding_controller.go 0 1 0.0%
server.go 0 2 0.0%
tapchannel/commitment.go 0 7 0.0%
tapchannel/aux_traffic_shaper.go 0 83 0.0%
Files with Coverage Reduction New Missed Lines %
tapchannel/aux_traffic_shaper.go 1 8.19%
asset/asset.go 3 80.08%
asset/mock.go 3 71.6%
tapchannel/aux_leaf_signer.go 3 43.08%
Totals Coverage Status
Change from base Build 14595006553: 26.5%
Covered Lines: 50990
Relevant Lines: 92317

💛 - Coveralls

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Code wise this looks good to me. But IMO we'd want a bit more certainty around whether this really works in all cases.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, I think the code is correct now for our use case.
Now it's just code style and reviewer friendliness that can be improved somewhat.

// The asset balance of the channel is simply not enough to
// route the asset units, we report 0 bandwidth in order for the
// HTLC to fail back.
return 0, nil

default:
Copy link
Member

Choose a reason for hiding this comment

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

This should not be possible, so it's just confusing to have the default case.
In fact, now that we definitely return from this function, we can turn the first case into an if. Then have the second case non-indented as the implicit else.

Copy link
Member Author

@GeorgeTsagk GeorgeTsagk Apr 16, 2025

Choose a reason for hiding this comment

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

the default was only added here for golang to not complain about the default return missing, could also add a default return outside the switch

Sure can switch to if , although I find switch much more readable as you see both cases explicitly being captured

Copy link
Member Author

Choose a reason for hiding this comment

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

Can add a comment like "we shouldn't reach this" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's should return an error if it ever reaches a point it shouldn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

if it ever reaches a point it shouldn't.

It's not a "shouldn't" it's a "can't". We're not trusting that certain properties are respected in the code, the above 2 cases catch the full numerical range so any value will be satisfied by the 2 cases above.

Regardless, I'll still add an error.

@GeorgeTsagk GeorgeTsagk force-pushed the aux-bandwidth-htlcview branch 2 times, most recently from 98260c9 to 8e9b450 Compare April 17, 2025 12:41
@GeorgeTsagk GeorgeTsagk requested a review from guggero April 17, 2025 12:44
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@GeorgeTsagk GeorgeTsagk force-pushed the aux-bandwidth-htlcview branch 2 times, most recently from 3182e35 to 9500e22 Compare April 17, 2025 15:02
Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

nice comments 👍

// The asset balance of the channel is simply not enough to
// route the asset units, we report 0 bandwidth in order for the
// HTLC to fail back.
return 0, nil

default:
Copy link
Contributor

Choose a reason for hiding this comment

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

It's should return an error if it ever reaches a point it shouldn't.

To make `PaymentBandwidth` more readable, we separate the main codepaths
into helper functions. One is used when we're directly comparing asset
units to each other, and the other one is the path that calculates an
msat amount based on an RFQ quote.
We now make use of the AuxHtlcView to calculate a more precise value of
our local balance. This is using the ComputeView helper in order to
manually process HTLC adds from our side, providing us with the correct
value of local balance. We also add the DecodedView as a return value of
the helper function, but this will only be used in the next commit for
verbose logging.
We add a trace log which includes a pretty print of the HTLCs that are
part of our local update log.
@GeorgeTsagk GeorgeTsagk force-pushed the aux-bandwidth-htlcview branch from 8958945 to 3b5aace Compare April 22, 2025 14:50
@GeorgeTsagk GeorgeTsagk enabled auto-merge April 22, 2025 14:50
@GeorgeTsagk GeorgeTsagk added this pull request to the merge queue Apr 22, 2025
Merged via the queue into main with commit b4feb3e Apr 22, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Apr 22, 2025
@guggero guggero deleted the aux-bandwidth-htlcview branch April 22, 2025 16:54
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