From b577ad46616112893ef8ee7a665f7b54d5d7910f Mon Sep 17 00:00:00 2001 From: Nishant Bansal Date: Tue, 14 Jan 2025 19:17:24 +0530 Subject: [PATCH] routerrpc: default timeout_seconds to 60 in SendPaymentV2 If timeout_seconds is not set or is 0, the default value of 60 seconds will be used. Signed-off-by: Nishant Bansal --- lnrpc/routerrpc/router.pb.go | 9 +++++---- lnrpc/routerrpc/router.proto | 9 +++++---- lnrpc/routerrpc/router.swagger.json | 2 +- lnrpc/routerrpc/router_backend.go | 5 ----- lnrpc/routerrpc/router_server.go | 9 +++++++++ 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lnrpc/routerrpc/router.pb.go b/lnrpc/routerrpc/router.pb.go index 6f29c035e..2ff6c8a1a 100644 --- a/lnrpc/routerrpc/router.pb.go +++ b/lnrpc/routerrpc/router.pb.go @@ -427,10 +427,11 @@ type SendPaymentRequest struct { // that case it is required to set the amt field as well. If no payment request // is specified, the following fields are required: dest, amt and payment_hash. PaymentRequest string `protobuf:"bytes,5,opt,name=payment_request,json=paymentRequest,proto3" json:"payment_request,omitempty"` - // 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 limit, expressed in seconds, on the time to wait before + // attempting the first HTLC. Once HTLCs are in flight, the payment will + // not be aborted until the HTLCs are either settled or failed. If the field + // is not set or is explicitly set to zero, the default value of 60 seconds + // will be applied. TimeoutSeconds int32 `protobuf:"varint,6,opt,name=timeout_seconds,json=timeoutSeconds,proto3" json:"timeout_seconds,omitempty"` // The maximum number of satoshis that will be paid as a fee of the payment. // If this field is left to the default value of 0, only zero-fee routes will diff --git a/lnrpc/routerrpc/router.proto b/lnrpc/routerrpc/router.proto index e96c50a3a..2c2622a3c 100644 --- a/lnrpc/routerrpc/router.proto +++ b/lnrpc/routerrpc/router.proto @@ -227,10 +227,11 @@ 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 limit, expressed in seconds, on the time to wait before + attempting the first HTLC. Once HTLCs are in flight, the payment will + not be aborted until the HTLCs are either settled or failed. If the field + is not set or is explicitly set to zero, the default value of 60 seconds + will be applied. */ int32 timeout_seconds = 6; diff --git a/lnrpc/routerrpc/router.swagger.json b/lnrpc/routerrpc/router.swagger.json index 51e48ac10..74a3d4467 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 limit, expressed in seconds, on the time to wait before\nattempting the first HTLC. Once HTLCs are in flight, the payment will\nnot be aborted until the HTLCs are either settled or failed. If the field\nis not set or is explicitly set to zero, the default value of 60 seconds\nwill be applied." }, "fee_limit_sat": { "type": "string", diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go index 7d7368109..eafa78724 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 c7077a94b..a0da36f26 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 int32 = 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