-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Part 6|*] Thread Contexts through payment methods Part 2 #10308
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
base: elle-payment-sql-series-new
Are you sure you want to change the base?
[Part 6|*] Thread Contexts through payment methods Part 2 #10308
Conversation
d78c447 to
7e67836
Compare
7e67836 to
bf83aca
Compare
e991cd0 to
6860702
Compare
90a87b0 to
49087c8
Compare
ellemouton
left a comment
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.
nice! will give final ack once all dependent prs are in.
I think YY will have more context (no pun intended) around what is safe to do in payment lifecycle re context threading
47606dd to
01d9986
Compare
b187798 to
e3f9e98
Compare
|
@ziggie1984, remember to re-request review from reviewers when ready |
e3f9e98 to
c9d13d2
Compare
yyforyongyu
left a comment
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.
I think the current version is good enough, only have a question about the ctx used in reloadPayment, but that can be addressed in the final PR.
Re the ctx, in general for db write txns, we always want it to be finished. And for reads, we want it to be canceled if the parent ctx is canceled. We could rename cleanupCtx to be writeCtx to make it clear, or create a struct to hold two contexts - one from the caller, and one inherits the caller ctx which is used for writing. Tho I don't think it's urgent.
One last thing is what Elle has brought up before, that for the inherited context, we should add a timeout, just in case the db is locked, we need to funnel that error to the caller. But this is an open question, as we have a config for db timeout already, so I wander if we should use that here. There's also the question that, if the postgres is configured with a timeout, it seems unnecessary to add a timeout to the ctx as the call will return an error anyway?
|
|
||
| // We update the payment state on every iteration. | ||
| currentPayment, ps, err := p.reloadPayment() | ||
| currentPayment, ps, err := p.reloadPayment(cleanupCtx) |
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.
similar to reloadInflightAttempts, we should also use ctx here to cancel the read operation?
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.
no we can't use the ctx context here, because we rely on this function recollect all INFLIGHT results, if we do use the other context we will basically abort as soon as we timeout.
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.
I tried to describe it in the todo where I introduced the new context:
// TODO(ziggie): This is a workaround to avoid a greater refactor of the
// payment lifecycle. We can currently not rely on the parent context
// because this method is also collect the results of inflight HTLCs
// after the context is cancelled. So we need to make sure we only use
// the current context to stop creating new attempts but use this
// cleanupCtx to do all the db operations.
|
|
||
| // Now request a route to be used to create our HTLC attempt. | ||
| rt, err := p.requestRoute(ps) | ||
| rt, err := p.requestRoute(cleanupCtx, ps) |
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.
We still have this downside such that, when the user cancels the operation, the path finding won't be stopped, but this is already a pre-existing issue, tho this will likely come up again when adding ctx to RequestRoute.
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.
agree, but luckily we are only talking probably of 1 sec waisted time and as described before we cannot fail this call because we depend on this for loop to collect potential inflight attempts for this payment.
| // bi-directional stream allowing clients to rapidly send payments through the | ||
| // Lightning Network with a single persistent connection. | ||
| func (r *rpcServer) SendPayment(stream lnrpc.Lightning_SendPaymentServer) error { | ||
| func (r *rpcServer) SendPayment( |
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.
I think this RPC is deprecated and will be removed, but guess we can remove after the PR is merged.
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.
yes let's do it in a separate PR.
A context is added to failPaymentAndAttempt and its dependant function calls.
c9d13d2 to
aae5a33
Compare
Part 2 of the Context Threading refactor. Depends on #10307