-
Notifications
You must be signed in to change notification settings - Fork 24
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
Rework IncomingPayment
model
#722
Conversation
src/commonMain/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, this is a good clean-up! It's simpler than I thought, the hard part is probably the DB part on the Phoenix side?
I don't see any issue on the lightning-kmp
side, everything is much clearer now.
src/commonTest/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandlerTestsCommon.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as far as backwards-compatibility doesn't create any issue for Phoenix!
77db5b6
to
d50f720
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
5450bb3
to
600c04d
Compare
This allows for a unified identifier for all payments that affect the balance. For `IncomingPayment`, the `payment_hash` is currently abusively used as a primary key, which is hacky in the context of swap-ins. To minimize integration effort, the payment id simply derived from that existing key, with no other changes.
We move from a flat model with a single `IncomingPayment` class and a combination of `Origin` + `ReceivedWith` parts to a hierarchical model. This new model: - makes incoming/outgoing databases symmetrical - removes impossible combinations allowed in the previous model (e.g. an on-chain origin with a fee-credit part) - removes hacks required for the handling of on-chain deposits, which were shoe-horned in what was originally a lightning-only model Before: ``` Origin | `--- Invoice | `--- Offer | `--- SwapIn | `--- OnChain ReceivedWith | `--- LightningPayment | `--- AddedToFeeCredit | `--- OnChainIncomingPayment | `--- NewChannel | `--- SpliceIn ``` After: ``` IncomingPayment | `--- LightningIncomingPayment | | | `--- Bolt11IncomingPayment | | | `--- Bolt12IncomingPayment | `--- OnChainIncomingPayment | `--- NewChannelIncomingPayment | `--- SpliceInIncomingPayment | `--- LegacySwapInIncomingPayment | `--- LegacyPayToOpenIncomingPayment LightningIncomingPayment.Part | `--- LightningPayment | `--- AddedToFeeCredit ``` The handling of backward compatible data is tricky, especially for legacy pay-to-open/pay-to-splice, which can be a mix of lightning parts and on-chain parts, and either Bolt11 or Bolt12. Note that `Legacy*` classes are not used at all within `lightning-kmp`, they are just meant to handle pre-existing data in the database.
(Simple rename, no functional changes) Also: - `ReceivedWith.LightningPayment` -> `Part.Htlc` - `ReceivedWith.AddedToFeeCredit` -> `Part.FeeCredit`
Instead, the `parts` are a direct member of `LightningIncomingPayment`. It makes the object simpler to manipulate and update. Each of them has a `receivedAt` timestamp, offering more precision.
a110612
to
bad4ec3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits, otherwise LGTM 👍
We move from a flat model with a single
IncomingPayment
class and a combination ofOrigin
+ReceivedWith
parts to a hierarchical model.This new model:
Before:
After:
The handling of backward compatible data is tricky, especially for legacy pay-to-open/pay-to-splice, which can be a mix of lightning parts and on-chain parts, and either Bolt11 or Bolt12. Note that
Legacy*
classes are not used at all withinlightning-kmp
, they are just meant to handle pre-existing data in the database.