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 <nishant.bansal.282003@gmail.com>
This commit is contained in:
Nishant Bansal committed 2025-01-15 19:45:44 +05:30
1 parent 4b16c2902e
commit b577ad4661
5 files changed
+20 -14

No files matched your search

+5 -4
View File
@@ -427,10 +427,11 @@ type SendPaymentRequest struct {
// that case it is required to set the amt field as well. If no payment request // 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. // 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"` 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 // An optional limit, expressed in seconds, on the time to wait before
// fulfill the payment. This is expressed in seconds. If we cannot make a // attempting the first HTLC. Once HTLCs are in flight, the payment will
// successful payment within this time frame, an error will be returned. // not be aborted until the HTLCs are either settled or failed. If the field
// This field must be non-zero. // 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"` 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. // 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 // If this field is left to the default value of 0, only zero-fee routes will
+5 -4
View File
@@ -227,10 +227,11 @@ message SendPaymentRequest {
string payment_request = 5; string payment_request = 5;
/* /*
An upper limit on the amount of time we should spend when attempting to An optional limit, expressed in seconds, on the time to wait before
fulfill the payment. This is expressed in seconds. If we cannot make a attempting the first HTLC. Once HTLCs are in flight, the payment will
successful payment within this time frame, an error will be returned. not be aborted until the HTLCs are either settled or failed. If the field
This field must be non-zero. is not set or is explicitly set to zero, the default value of 60 seconds
will be applied.
*/ */
int32 timeout_seconds = 6; int32 timeout_seconds = 6;
+1 -1
View File
@@ -1894,7 +1894,7 @@
"timeout_seconds": { "timeout_seconds": {
"type": "integer", "type": "integer",
"format": "int32", "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": { "fee_limit_sat": {
"type": "string", "type": "string",
-5
View File
@@ -878,11 +878,6 @@ func (r *RouterBackend) extractIntentFromSendRequest(
return nil, err 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) customRecords := record.CustomSet(rpcPayReq.DestCustomRecords)
if err := customRecords.Validate(); err != nil { if err := customRecords.Validate(); err != nil {
return nil, err return nil, err
+9
View File
@@ -40,6 +40,10 @@ const (
// routeFeeLimitSat is the maximum routing fee that we allow to occur // routeFeeLimitSat is the maximum routing fee that we allow to occur
// when estimating a routing fee. // when estimating a routing fee.
routeFeeLimitSat = 100_000_000 routeFeeLimitSat = 100_000_000
// DefaultPaymentTimeout is the default value of time we should spend
// when attempting to fulfill the payment.
DefaultPaymentTimeout int32 = 60
) )
var ( var (
@@ -344,6 +348,11 @@ func (r *ServerShell) CreateSubServer(configRegistry lnrpc.SubServerConfigDispat
func (s *Server) SendPaymentV2(req *SendPaymentRequest, func (s *Server) SendPaymentV2(req *SendPaymentRequest,
stream Router_SendPaymentV2Server) error { stream Router_SendPaymentV2Server) error {
// Set payment request attempt timeout.
if req.TimeoutSeconds == 0 {
req.TimeoutSeconds = DefaultPaymentTimeout
}
payment, err := s.cfg.RouterBackend.extractIntentFromSendRequest(req) payment, err := s.cfg.RouterBackend.extractIntentFromSendRequest(req)
if err != nil { if err != nil {
return err return err