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

[MPP] "slow settle" for TrackPayment #4142

Closed
wants to merge 2 commits into from

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Apr 2, 2020

Similar to what is done currently for ListPayments, we only report the Success/Failed state of a payment when there is no longer any payment shards in flight.

halseth added 2 commits April 2, 2020 18:46
Similar to what is done for SettleAttempt.
In case settling an attempt doesn't lead to the payment moving to the
success status (if there are more attempts still in flight), we don't
send the success event yet. We wait until all shards are done, and the
paymetnt move to the final success state.

For failures we do the same, we don't notify about failures before we
are certain the payment has moved completely to the Failed state.
@halseth halseth added the mpp label Apr 2, 2020
@halseth halseth added this to the 0.10.0 milestone Apr 2, 2020
@halseth halseth requested a review from Roasbeef as a code owner April 2, 2020 16:51
@halseth halseth removed the request for review from Roasbeef April 2, 2020 16:57
// can happen if the payment had no more attempts in flight at this
// point, and recording this payment failure took the payment to a
// final failure state.
p.notifyFinalEvent(payment)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't notify here, because there are still htlcs in-flight, is this Fail method guarantueed to be called again? (does every failed htlc eventually trigger a call to this method?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. That's why we also call it in FailAttemp above

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, clear.

// should notify all subscribers of the final payment status. This can
// happen if the payment already had a settled attempt or terminal
// failure recorded, and this attempt was the last one in-flight.
p.notifyFinalEvent(payment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this causing a duplicate event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea is that only the first event that take the payment to Settle/failed state will produce the notification. The second one will find the payment also in this state, but by that time the subscribers list will be empty (and cannot be filled again since we only add to it for in-flight payments)

Copy link
Contributor

Choose a reason for hiding this comment

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

And there is no race condition possible there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the first one that gets the lock on the subscribers will empty the list, and at that point it is impossible to add more to the list, so I think it is okay.

If we merge #3970 first I can add some more testcases here for MPP scenarios.

Copy link
Contributor

@joostjager joostjager Apr 3, 2020

Choose a reason for hiding this comment

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

I was actually thinking about a race between subscribe and notify, because the payment update in FailAttempt isn't inside the subscriber lock.

I think the bottom line of this discussion is that the concurrent behavior isn't very clear. There is potentially a duplicate notification, but it is never broadcast because the subscriber lock makes sure the list is already empty.

Also control tower notification needs to be updated anyway to sends updates for non-final state transitions.

Isn't a single PR on top of #3970 that fixes both things a better idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

in order to be totally consistent i think, yes, there would need to be a lock around the db operation as well. this is preexisting tho, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the direction that I am thinking of atm: master...joostjager:notify-htlc-arrival-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants