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

Simplify outgoing payment state machine #692

Merged
merged 6 commits into from
Oct 21, 2024
Merged

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Aug 7, 2024

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.

@t-bast t-bast force-pushed the simplify-outgoing-payment-fsm branch from c070ae3 to d3b37a9 Compare August 7, 2024 11:55
@t-bast t-bast force-pushed the simplify-outgoing-payment-fsm branch from d3b37a9 to 23c1dc7 Compare August 8, 2024 07:22
@t-bast t-bast force-pushed the simplify-outgoing-payment-fsm branch from 23c1dc7 to 59a4a1d Compare September 16, 2024 09:42
@t-bast t-bast force-pushed the simplify-outgoing-payment-fsm branch from 59a4a1d to 956ae55 Compare October 8, 2024 07:49
@t-bast t-bast marked this pull request as ready for review October 14, 2024 10:55
@t-bast t-bast requested a review from thomash-acinq October 14, 2024 10:55
Copy link
Member

@thomash-acinq thomash-acinq left a 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>

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.
Copy link
Member

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.

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 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...

Copy link
Member

Choose a reason for hiding this comment

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

Like this: #717

Copy link
Member Author

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.

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.
@t-bast t-bast force-pushed the simplify-outgoing-payment-fsm branch from 956ae55 to baf8ce2 Compare October 16, 2024 03:32
t-bast and others added 4 commits October 16, 2024 05:48
And rename those methods for clarify.
And correctly handle other payment details types, such as blinded
payments.
It's a weird hierarchy to have `SendPaymentResult` be a
`ProcessFailureResult`. We instead return an `Either`
and upcast.

The logger belongs to the parent function and can simply
be provided in the function call.
@t-bast t-bast merged commit 192f3bf into master Oct 21, 2024
2 checks passed
@t-bast t-bast deleted the simplify-outgoing-payment-fsm branch October 21, 2024 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants