Skip to content

Commit b4b4194

Browse files
committed
multi: thread context through SendPayment
1 parent 5053821 commit b4b4194

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

routing/router.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,8 @@ func (l *LightningPayment) Identifier() [32]byte {
896896
// will be returned which describes the path the successful payment traversed
897897
// within the network to reach the destination. Additionally, the payment
898898
// preimage will also be returned.
899-
func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte,
900-
*route.Route, error) {
899+
func (r *ChannelRouter) SendPayment(ctx context.Context,
900+
payment *LightningPayment) ([32]byte, *route.Route, error) {
901901

902902
paySession, shardTracker, err := r.PreparePayment(payment)
903903
if err != nil {
@@ -908,7 +908,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte,
908908
spewPayment(payment))
909909

910910
return r.sendPayment(
911-
context.Background(), payment.FeeLimit, payment.Identifier(),
911+
ctx, payment.FeeLimit, payment.Identifier(),
912912
payment.PayAttemptTimeout, paySession, shardTracker,
913913
payment.FirstHopCustomRecords,
914914
)

routing/router_test.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ func TestSendPaymentRouteFailureFallback(t *testing.T) {
324324

325325
// Send off the payment request to the router, route through pham nuwen
326326
// should've been selected as a fall back and succeeded correctly.
327-
paymentPreImage, route, err := ctx.router.SendPayment(payment)
327+
paymentPreImage, route, err := ctx.router.SendPayment(
328+
t.Context(), payment,
329+
)
328330
require.NoErrorf(t, err, "unable to send payment: %v",
329331
payment.paymentHash)
330332

@@ -403,7 +405,9 @@ func TestSendPaymentRouteInfiniteLoopWithBadHopHint(t *testing.T) {
403405

404406
// Send off the payment request to the router, should succeed
405407
// ignoring the bad channel id hint.
406-
paymentPreImage, route, paymentErr := ctx.router.SendPayment(payment)
408+
paymentPreImage, route, paymentErr := ctx.router.SendPayment(
409+
t.Context(), payment,
410+
)
407411
require.NoErrorf(t, paymentErr, "unable to send payment: %v",
408412
payment.paymentHash)
409413

@@ -634,7 +638,9 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
634638

635639
// Send off the payment request to the router, route through phamnuwen
636640
// should've been selected as a fall back and succeeded correctly.
637-
paymentPreImage, route, err := ctx.router.SendPayment(payment)
641+
paymentPreImage, route, err := ctx.router.SendPayment(
642+
t.Context(), payment,
643+
)
638644
require.NoErrorf(t, err, "unable to send payment: %v",
639645
payment.paymentHash)
640646

@@ -741,7 +747,9 @@ func TestSendPaymentErrorFeeInsufficientPrivateEdge(t *testing.T) {
741747

742748
// Send off the payment request to the router, route through son
743749
// goku and then across the private channel to elst.
744-
paymentPreImage, route, err := ctx.router.SendPayment(payment)
750+
paymentPreImage, route, err := ctx.router.SendPayment(
751+
t.Context(), payment,
752+
)
745753
require.NoErrorf(t, err, "unable to send payment: %v",
746754
payment.paymentHash)
747755

@@ -867,7 +875,9 @@ func TestSendPaymentPrivateEdgeUpdateFeeExceedsLimit(t *testing.T) {
867875

868876
// Send off the payment request to the router, route through son
869877
// goku and then across the private channel to elst.
870-
paymentPreImage, route, err := ctx.router.SendPayment(payment)
878+
paymentPreImage, route, err := ctx.router.SendPayment(
879+
t.Context(), payment,
880+
)
871881
require.NoErrorf(t, err, "unable to send payment: %v",
872882
payment.paymentHash)
873883

@@ -990,7 +1000,9 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
9901000
// Send off the payment request to the router, this payment should
9911001
// succeed as we should actually go through Pham Nuwen in order to get
9921002
// to Sophon, even though he has higher fees.
993-
paymentPreImage, rt, err := ctx.router.SendPayment(payment)
1003+
paymentPreImage, rt, err := ctx.router.SendPayment(
1004+
t.Context(), payment,
1005+
)
9941006
require.NoErrorf(t, err, "unable to send payment: %v",
9951007
payment.paymentHash)
9961008

@@ -1016,7 +1028,9 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
10161028
// w.r.t to the block height, and instead go through Pham Nuwen. We
10171029
// flip a bit in the payment hash to allow resending this payment.
10181030
payment.paymentHash[1] ^= 1
1019-
paymentPreImage, rt, err = ctx.router.SendPayment(payment)
1031+
paymentPreImage, rt, err = ctx.router.SendPayment(
1032+
t.Context(), payment,
1033+
)
10201034
require.NoErrorf(t, err, "unable to send payment: %v",
10211035
payment.paymentHash)
10221036

@@ -1085,7 +1099,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
10851099

10861100
// When we try to dispatch that payment, we should receive an error as
10871101
// both attempts should fail and cause both routes to be pruned.
1088-
_, _, err = ctx.router.SendPayment(payment)
1102+
_, _, err = ctx.router.SendPayment(t.Context(), payment)
10891103
require.Error(t, err, "payment didn't return error")
10901104

10911105
// The final error returned should also indicate that the peer wasn't
@@ -1130,7 +1144,9 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
11301144
// This shouldn't return an error, as we'll make a payment attempt via
11311145
// the pham nuwen channel based on the assumption that there might be an
11321146
// intermittent issue with the songoku <-> sophon channel.
1133-
paymentPreImage, rt, err := ctx.router.SendPayment(payment)
1147+
paymentPreImage, rt, err := ctx.router.SendPayment(
1148+
t.Context(), payment,
1149+
)
11341150
require.NoErrorf(t, err, "unable to send payment: %v",
11351151
payment.paymentHash)
11361152

@@ -1170,7 +1186,9 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
11701186

11711187
// We flip a bit in the payment hash to allow resending this payment.
11721188
payment.paymentHash[1] ^= 1
1173-
paymentPreImage, rt, err = ctx.router.SendPayment(payment)
1189+
paymentPreImage, rt, err = ctx.router.SendPayment(
1190+
t.Context(), payment,
1191+
)
11741192
require.NoErrorf(t, err, "unable to send payment: %v",
11751193
payment.paymentHash)
11761194

@@ -1302,7 +1320,7 @@ func TestUnknownErrorSource(t *testing.T) {
13021320
// the route a->b->c is tried first. An unreadable faiure is returned
13031321
// which should pruning the channel a->b. We expect the payment to
13041322
// succeed via a->d.
1305-
_, _, err = ctx.router.SendPayment(payment)
1323+
_, _, err = ctx.router.SendPayment(t.Context(), payment)
13061324
require.NoErrorf(t, err, "unable to send payment: %v",
13071325
payment.paymentHash)
13081326

@@ -1327,7 +1345,7 @@ func TestUnknownErrorSource(t *testing.T) {
13271345
// Send off the payment request to the router. We expect the payment to
13281346
// fail because both routes have been pruned.
13291347
payment.paymentHash[1] ^= 1
1330-
_, _, err = ctx.router.SendPayment(payment)
1348+
_, _, err = ctx.router.SendPayment(t.Context(), payment)
13311349
if err == nil {
13321350
t.Fatalf("expected payment to fail")
13331351
}

rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5960,7 +5960,7 @@ func (r *rpcServer) dispatchPaymentIntent(ctx context.Context,
59605960
}
59615961

59625962
preImage, route, routerErr = r.server.chanRouter.SendPayment(
5963-
payment,
5963+
ctx, payment,
59645964
)
59655965
} else {
59665966
var attempt *paymentsdb.HTLCAttempt

0 commit comments

Comments
 (0)