Skip to content

Conversation

@ziggie1984
Copy link
Collaborator

@ziggie1984 ziggie1984 commented Oct 21, 2025

Part 2 of the Context Threading refactor. Depends on #10307

@ziggie1984 ziggie1984 changed the base branch from master to elle-payment-sql-series-new October 21, 2025 09:48
@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch from d78c447 to 7e67836 Compare October 21, 2025 09:51
@ziggie1984 ziggie1984 self-assigned this Oct 21, 2025
@ziggie1984 ziggie1984 added payments Related to invoices/payments refactoring sql labels Oct 21, 2025
@ziggie1984 ziggie1984 added this to v0.21 Oct 21, 2025
@ziggie1984 ziggie1984 added this to the v0.21.0 milestone Oct 21, 2025
@ziggie1984 ziggie1984 removed the sql label Oct 21, 2025
@saubyk saubyk moved this to In progress in v0.21 Oct 23, 2025
@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch from 7e67836 to bf83aca Compare November 11, 2025 17:52
@ziggie1984 ziggie1984 marked this pull request as ready for review November 11, 2025 18:00
@ziggie1984 ziggie1984 force-pushed the elle-payment-sql-series-new branch 4 times, most recently from e991cd0 to 6860702 Compare November 13, 2025 06:45
@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch 2 times, most recently from 90a87b0 to 49087c8 Compare November 17, 2025 13:54
@ziggie1984 ziggie1984 moved this from In progress to In review in v0.21 Nov 17, 2025
Copy link
Collaborator

@ellemouton ellemouton left a 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

@ziggie1984 ziggie1984 force-pushed the elle-payment-sql-series-new branch 2 times, most recently from 47606dd to 01d9986 Compare November 20, 2025 13:26
@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch 3 times, most recently from b187798 to e3f9e98 Compare November 25, 2025 13:57
@lightninglabs-deploy
Copy link

@ziggie1984, remember to re-request review from reviewers when ready

@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch from e3f9e98 to c9d13d2 Compare November 27, 2025 07:46
Copy link
Member

@yyforyongyu yyforyongyu left a 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)
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

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.

Copy link
Collaborator Author

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

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.

Copy link
Collaborator Author

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.

@ziggie1984 ziggie1984 force-pushed the introduce-sql-schema-payments-part-6 branch from c9d13d2 to aae5a33 Compare November 28, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

payments Related to invoices/payments refactoring

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants