-
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
Simplify outgoing payment state machine #692
Conversation
c070ae3
to
d3b37a9
Compare
d3b37a9
to
23c1dc7
Compare
23c1dc7
to
59a4a1d
Compare
59a4a1d
to
956ae55
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.
If we drop the support for multiple channels, we should modify Peer.kt
to only have a single channel
instead of the current channels: Map<ByteVector32, ChannelState>
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
removeFromState(payment.request.paymentId) | ||
Failure(payment.request, OutgoingPaymentFailure(finalError, payment.failures + failure)) | ||
} else { | ||
// The trampoline node is asking us to retry the payment with more fees or a larger expiry delta. |
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.
It feels like we should should be able to share code with sendPayment
instead of duplicating it.
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.
Can you detail how exactly you'd do that? What we do in each case here is slightly different from what we do when sending the first attempt in sendPayment
, I haven't found a way to share more code that doesn't sacrifice clarity...
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.
Like this: #717
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.
Thanks, added with a small refactoring.
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Outdated
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentHandler.kt
Show resolved
Hide resolved
src/commonMain/kotlin/fr/acinq/lightning/payment/OutgoingPaymentPacket.kt
Show resolved
Hide resolved
We previously supported having multiple channels with our peer, because we didn't yet support splicing. Now that we support splicing, we always have at most one active channel with our peer. This lets us simplify greatly the outgoing payment state machine: payments are always made with a single outgoing HTLC instead of potentially multiple HTLCs (MPP). We don't need any kind of path-finding: we simply need to check the balance of our active channel, if any. We may introduce support for connecting to multiple peers in the future. When that happens, we will still have a single active channel per peer, but we may allow splitting outgoing payments across our peers. We will need to re-work the outgoing payment state machine when this happens, but it is too early to support this now anyway. This refactoring makes it easier to create payment onion, by creating the trampoline onion *and* the outer onion in the same function call. This will make it simpler to migrate to the version of trampoline that is currently specified in lightning/bolts#836 where some fields will be included in the payment onion instead of the trampoline onion.
Each outgoing HTLC will have its own ID in the payments DB. Since we support retries, we have a 1-to-N mapping from a payment ID to its child IDs.
956ae55
to
baf8ce2
Compare
And rename those methods for clarify.
And correctly handle other payment details types, such as blinded payments.
We previously supported having multiple channels with our peer, because we didn't yet support splicing. Now that we support splicing, we always have at most one active channel with our peer. This lets us simplify greatly the outgoing payment state machine: payments are always made with a single outgoing HTLC instead of potentially multiple HTLCs (MPP).
We don't need any kind of path-finding: we simply need to check the balance of our active channel, if any.
We may introduce support for connecting to multiple peers in the future. When that happens, we will still have a single active channel per peer, but we may allow splitting outgoing payments across our peers. We will need to re-work the outgoing payment state machine when this happens, but it is too early to support this now anyway.
This refactoring makes it easier to create payment onion, by creating the trampoline onion and the outer onion in the same function call. This will make it simpler to migrate to the version of trampoline that is currently specified in lightning/bolts#836.