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 2025-01-14 19:17:24 +05:30
parent 4b16c2902e
commit b577ad4661
No known key found for this signature in database
GPG Key ID: EAE292198F6C5B98
5 changed files with 20 additions and 14 deletions

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
// 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

View File

@ -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;

View File

@ -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",

View File

@ -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

View File

@ -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