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

Add offer manager #2566

Merged
merged 23 commits into from Mar 27, 2023
Merged

Add offer manager #2566

merged 23 commits into from Mar 27, 2023

Conversation

thomash-acinq
Copy link
Member

Because offers are a very generic mechanism, handling them can require interacting with an inventory system (do we actually have the quantity that the payer is requesting) or other such systems which do not have their place inside eclair. For this reason offer handlers must be implemented as plugins that communicate with the offer manager. On startup, the offer handlers must register their offers with the offer manager, the offer manager will then forward the invoice requests and blinded payments to the relevant offer handler for approval.

Because offer invoices can be requested by any node, we do not store them in DB when they are created (which could be a DoS vector) but only when they are paid. To do that, we store some metadata about the invoice (offer id, preimage, payer id, created at, quantity, amount, features and extra data from the offer handler) in the pathId of the blinded route to use for the payment. This data is encrypted and signed by us so that it can't be forged by the payer. By default, this is not enough to fully reconstruct the invoice, so what is eventually stored in the DB once the payment succeeds does not exactly match the invoice that was sent to the payer, if that's a requirement for some use case, all of it can be put in the extra data passed by the offer handler.

@thomash-acinq thomash-acinq force-pushed the bolt12-option-db branch 4 times, most recently from d3dc04b to fee48ff Compare January 20, 2023 16:31
@thomash-acinq thomash-acinq force-pushed the bolt12-option-db branch 6 times, most recently from 558ebaf to bcf72e0 Compare January 26, 2023 16:36
@thomash-acinq thomash-acinq force-pushed the bolt12-option-db branch 2 times, most recently from 4cc0fc0 to e915059 Compare February 3, 2023 14:02
@thomash-acinq thomash-acinq force-pushed the bolt12-option-db branch 2 times, most recently from 0c19ff8 to 4250061 Compare February 16, 2023 18:36
@thomash-acinq thomash-acinq marked this pull request as ready for review February 16, 2023 18:39
Because offers are a very generic mechanism, handling them can require interacting with an inventory system (do we actually have the quantity that the payer is requesting) or other such systems which do not have their place inside eclair. For this reason offer handlers must be implemented as plugins that communicate with the offer manager.
On startup, the offer handlers must register their offers with the offer manager, the offer manager will then forward the invoice requests and blinded payments to the relevant offer handler for approval.
Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

Concept ACK on the architecture, this is going in the right direction.

@codecov-commenter
Copy link

Codecov Report

Merging #2566 (8d9c79f) into master (ddcb978) will increase coverage by 0.22%.
The diff coverage is 92.19%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #2566      +/-   ##
==========================================
+ Coverage   85.50%   85.72%   +0.22%     
==========================================
  Files         211      212       +1     
  Lines       16827    16992     +165     
  Branches      725      714      -11     
==========================================
+ Hits        14388    14567     +179     
+ Misses       2439     2425      -14     
Impacted Files Coverage Δ
.../main/scala/fr/acinq/eclair/db/DualDatabases.scala 11.11% <0.00%> (ø)
...src/main/scala/fr/acinq/eclair/db/PaymentsDb.scala 85.29% <ø> (+0.29%) ⬆️
...a/fr/acinq/eclair/payment/offer/OfferManager.scala 83.56% <83.56%> (ø)
...cinq/eclair/payment/receive/MultiPartHandler.scala 93.36% <96.55%> (-0.88%) ⬇️
...r-core/src/main/scala/fr/acinq/eclair/Eclair.scala 60.39% <100.00%> (+3.96%) ⬆️
...ir-core/src/main/scala/fr/acinq/eclair/Setup.scala 75.81% <100.00%> (+0.11%) ⬆️
...ain/scala/fr/acinq/eclair/db/pg/PgPaymentsDb.scala 98.61% <100.00%> (+<0.01%) ⬆️
...a/fr/acinq/eclair/db/sqlite/SqlitePaymentsDb.scala 98.63% <100.00%> (-0.02%) ⬇️
...c/main/scala/fr/acinq/eclair/message/Postman.scala 100.00% <100.00%> (ø)
.../scala/fr/acinq/eclair/payment/Bolt12Invoice.scala 97.43% <100.00%> (+0.42%) ⬆️
... and 4 more

... and 32 files with indirect coverage changes

Dummy is usually used for test or invalid data, whereas here we're just
storing a minimal version of the Bolt 12 invoice, so we rename it
MinimalBolt12Invoice.

We also add an explicit constructor for it that forces callers to provide
the data we expect to store.

Note that we remove the `features` field: using `nodeParams.features`
could be incorrect if the invoice_request's features don't include some
of our node's optional features. This is unused now anyway, but more
future-proof this way.
This commit refactors the offer manager without any meaningful change
in the business logic itself:

- move types to a separate file to isolate codec details
- make plugin data optional
- add debug logs in failure cases
- let plugin specify the `invoice_error` message
- avoid repeated calls to `Behaviors.setup`
- split OfferManager tests
- add more tests to the OfferManager
- remove test duplication in MultiPartHandlerSpec
- refactor BlindedPaymentSpec
Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

This is looking mostly good, I've done some refactoring to improve readability and tests in #2618 and then we should be good to go.

@thomash-acinq
Copy link
Member Author

Thank you for the refactoring. It looks very nice now.

Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 ⚡

@thomash-acinq thomash-acinq merged commit df0e712 into master Mar 27, 2023
1 check passed
@t-bast t-bast deleted the bolt12-option-db branch March 27, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants