Skip to content
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

tapchannel: enforce strict forwarding for asset invoices #1144

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

GeorgeTsagk
Copy link
Member

@GeorgeTsagk GeorgeTsagk commented Oct 8, 2024

This PR adds a few extra steps to the AuxInvoiceManager before it settles an invoice. Previously we wouldn't check that we received an asset HTLC for an asset invoice, leading to some undesired behavior.

With these changes we enforce that if the invoice corresponds to an asset invoice then we only settle it if we received assets.

Todo:

  • Tests

Closes #1008

@GeorgeTsagk GeorgeTsagk self-assigned this Oct 8, 2024
@coveralls
Copy link

coveralls commented Oct 8, 2024

Pull Request Test Coverage Report for Build 11385013038

Details

  • 31 of 47 (65.96%) changed or added relevant lines in 2 files are covered.
  • 23 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.3%) to 40.663%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rfq/manager.go 0 4 0.0%
tapchannel/aux_invoice_manager.go 31 43 72.09%
Files with Coverage Reduction New Missed Lines %
tapchannel/aux_leaf_signer.go 2 36.29%
asset/asset.go 2 81.8%
tapgarden/caretaker.go 4 68.87%
commitment/tap.go 5 83.64%
universe/interface.go 10 51.12%
Totals Coverage Status
Change from base Build 11293509981: 0.3%
Covered Lines: 24450
Relevant Lines: 60128

💛 - Coveralls

@dstadulis
Copy link
Collaborator

Before assigning reviewers, tests will need to be added.

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 approach! And great to have a unit test. Though I wonder what would actually happen on the sender and receiver side with this change? My assumption is that things would just time out (rather than rejecting the HTLC).
So I think we should also have an integration test for this.

tapchannel/aux_invoice_manager.go Show resolved Hide resolved
sellQuote, isSell := acceptedSellQuotes[rfqmsg.SerialisedScid(scid)]

switch {
case isBuy:
Copy link
Member

Choose a reason for hiding this comment

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

I wonder: Shouldn't an invoice always relate to a buy order only? Even in a direct peer payment, when I create an invoice, there should be a buy quote for it.

//
// TODO(george): Strict-forwarding could be configurable?
if s.isAssetInvoice(req.Invoice) {
resp.AmtPaid = 0
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, interesting approach. What does actually happen with this though? Did you try this in an itest?
I'm assuming the payment will just time out if it's MPP (since the sender is waiting for settle and the receiver is waiting for more shards that pay toward the invoice since none of them actually held any value yet).
Or does the zero amount here lead to a direct error that is propagated back to the sender?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're intercepting the invoice at the htlc level, which means that for mpp payments we'll intercept N times for N shards. Within the context of intercepting a single htlc we can only signal what the effective value of that single htlc is (i.e we can only ignore the "value contribution")

In the payment context we'll see a timeout, as we're still waiting for other htlcs that may sum up to the expected value

tapchannel/aux_invoice_manager_test.go Outdated Show resolved Hide resolved
@GeorgeTsagk
Copy link
Member Author

An itest that covers this behavior has been added in a litd PR

@GeorgeTsagk GeorgeTsagk requested review from jharveyb and removed request for ffranr October 17, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

tapchannel/[feature]: update AuxInvoiceManager to enforce strict forwarding for invoices
4 participants