From a6bd8c1ab3283b999b1fc3de8bad4bda7225ddb4 Mon Sep 17 00:00:00 2001 From: Nishant Bansal Date: Sat, 14 Dec 2024 18:04:28 +0530 Subject: [PATCH] routerrpc: add a default value for timeout_seconds in SendPaymentV2 Signed-off-by: Nishant Bansal routerrpc: update itests to validate default timeout_seconds Signed-off-by: Nishant Bansal --- docs/release-notes/release-notes-0.19.0.md | 5 +++++ itest/lnd_amp_test.go | 2 -- itest/lnd_channel_balance_test.go | 1 - itest/lnd_channel_force_close_test.go | 2 -- lnrpc/routerrpc/router.proto | 11 ++++++----- lnrpc/routerrpc/router.swagger.json | 2 +- lnrpc/routerrpc/router_backend.go | 5 ----- lnrpc/routerrpc/router_server.go | 9 +++++++++ 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index 0b576fc7de..3312e945ce 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -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 diff --git a/itest/lnd_amp_test.go b/itest/lnd_amp_test.go index 4b4cfb5a29..e5791cef62 100644 --- a/itest/lnd_amp_test.go +++ b/itest/lnd_amp_test.go @@ -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, } diff --git a/itest/lnd_channel_balance_test.go b/itest/lnd_channel_balance_test.go index 72dd16ea34..84501477e1 100644 --- a/itest/lnd_channel_balance_test.go +++ b/itest/lnd_channel_balance_test.go @@ -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) diff --git a/itest/lnd_channel_force_close_test.go b/itest/lnd_channel_force_close_test.go index 81bdfad431..b4a3cec000 100644 --- a/itest/lnd_channel_force_close_test.go +++ b/itest/lnd_channel_force_close_test.go @@ -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) diff --git a/lnrpc/routerrpc/router.proto b/lnrpc/routerrpc/router.proto index e96c50a3ac..de168c18fe 100644 --- a/lnrpc/routerrpc/router.proto +++ b/lnrpc/routerrpc/router.proto @@ -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. diff --git a/lnrpc/routerrpc/router.swagger.json b/lnrpc/routerrpc/router.swagger.json index 51e48ac101..cba171b0b8 100644 --- a/lnrpc/routerrpc/router.swagger.json +++ b/lnrpc/routerrpc/router.swagger.json @@ -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", diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go index 7d73681094..eafa787247 100644 --- a/lnrpc/routerrpc/router_backend.go +++ b/lnrpc/routerrpc/router_backend.go @@ -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 diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index 9499fa25a3..785abba0e0 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -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