Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
routerrpc: add a default value for timeout_seconds in SendPaymentV2
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>

routerrpc: update itests to validate default timeout_seconds

Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
NishantBansal2003 committed Dec 19, 2024
1 parent 6298f76 commit a6bd8c1
Showing 8 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
@@ -94,6 +94,11 @@
are now [sorted](https://github.com/lightningnetwork/lnd/pull/9337) based on
the `InvoiceHTLC.HtlcIndex`.

* [routerrpc.SendPaymentV2](https://github.com/lightningnetwork/lnd/pull/9359)
RPC method now applies a default timeout of 60 seconds when the
`timeout_seconds` field is not set. Explicitly setting `timeout_seconds` to 0
is no longer allowed.

## lncli Additions

* [A pre-generated macaroon root key can now be specified in `lncli create` and
2 changes: 0 additions & 2 deletions itest/lnd_amp_test.go
Original file line number Diff line number Diff line change
@@ -127,7 +127,6 @@ func testSendPaymentAMPInvoiceCase(ht *lntest.HarnessTest,
sendReq := &routerrpc.SendPaymentRequest{
PaymentRequest: addInvoiceResp.PaymentRequest,
PaymentAddr: externalPayAddr,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
Amp: true,
}
@@ -417,7 +416,6 @@ func testSendPaymentAMP(ht *lntest.HarnessTest) {
Dest: mts.bob.PubKey[:],
Amt: int64(paymentAmt),
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
Amp: true,
}
1 change: 0 additions & 1 deletion itest/lnd_channel_balance_test.go
Original file line number Diff line number Diff line change
@@ -153,7 +153,6 @@ func testChannelUnsettledBalance(ht *lntest.HarnessTest) {
Amt: int64(payAmt),
PaymentHash: ht.Random32Bytes(),
FinalCltvDelta: finalCltvDelta,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
}
alice.RPC.SendPayment(req)
2 changes: 0 additions & 2 deletions itest/lnd_channel_force_close_test.go
Original file line number Diff line number Diff line change
@@ -147,7 +147,6 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
Amt: int64(paymentAmt),
PaymentHash: ht.Random32Bytes(),
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
}
alice.RPC.SendPayment(req)
@@ -905,7 +904,6 @@ func testFailingChannel(ht *lntest.HarnessTest) {
// won't work as the channel cannot be found.
req := &routerrpc.SendPaymentRequest{
PaymentRequest: resp.PaymentRequest,
TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat,
}
ht.SendPaymentAndAssertStatus(alice, req, lnrpc.Payment_IN_FLIGHT)
11 changes: 6 additions & 5 deletions lnrpc/routerrpc/router.proto
Original file line number Diff line number Diff line change
@@ -227,12 +227,13 @@ message SendPaymentRequest {
string payment_request = 5;

/*
An upper limit on the amount of time we should spend when attempting to
fulfill the payment. This is expressed in seconds. If we cannot make a
successful payment within this time frame, an error will be returned.
This field must be non-zero.
An optional upper limit on the amount of time we should spend when
attempting to fulfill the payment. This is expressed in seconds. If we
cannot make a successful payment within this time frame, an error will be
returned. If the field is not set, the default value of 60 seconds will be
used. This field must be non-zero.
*/
int32 timeout_seconds = 6;
optional int32 timeout_seconds = 6;

/*
The maximum number of satoshis that will be paid as a fee of the payment.
2 changes: 1 addition & 1 deletion lnrpc/routerrpc/router.swagger.json
Original file line number Diff line number Diff line change
@@ -1894,7 +1894,7 @@
"timeout_seconds": {
"type": "integer",
"format": "int32",
"description": "An upper limit on the amount of time we should spend when attempting to\nfulfill the payment. This is expressed in seconds. If we cannot make a\nsuccessful payment within this time frame, an error will be returned.\nThis field must be non-zero."
"description": "An optional upper limit on the amount of time we should spend when\nattempting to fulfill the payment. This is expressed in seconds. If we\ncannot make a successful payment within this time frame, an error will be\nreturned. If the field is not set, the default value of 60 seconds will be\nused. This field must be non-zero."
},
"fee_limit_sat": {
"type": "string",
5 changes: 0 additions & 5 deletions lnrpc/routerrpc/router_backend.go
Original file line number Diff line number Diff line change
@@ -878,11 +878,6 @@ func (r *RouterBackend) extractIntentFromSendRequest(
return nil, err
}

// Set payment attempt timeout.
if rpcPayReq.TimeoutSeconds == 0 {
return nil, errors.New("timeout_seconds must be specified")
}

customRecords := record.CustomSet(rpcPayReq.DestCustomRecords)
if err := customRecords.Validate(); err != nil {
return nil, err
9 changes: 9 additions & 0 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
@@ -40,6 +40,10 @@ const (
// routeFeeLimitSat is the maximum routing fee that we allow to occur
// when estimating a routing fee.
routeFeeLimitSat = 100_000_000

// DefaultPaymentTimeout is the default value of time we should spend
// when attempting to fulfill the payment.
DefaultPaymentTimeout = 60
)

var (
@@ -344,6 +348,11 @@ func (r *ServerShell) CreateSubServer(configRegistry lnrpc.SubServerConfigDispat
func (s *Server) SendPaymentV2(req *SendPaymentRequest,
stream Router_SendPaymentV2Server) error {

// Set payment request attempt timeout.
if req.TimeoutSeconds == 0 {
req.TimeoutSeconds = DefaultPaymentTimeout
}

payment, err := s.cfg.RouterBackend.extractIntentFromSendRequest(req)
if err != nil {
return err

0 comments on commit a6bd8c1

Please sign in to comment.