Skip to content

Commit 335a9b3

Browse files
committed
lnd: reduce max limit when querying for payments
1 parent a9c30da commit 335a9b3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

payments/db/query.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package paymentsdb
22

3+
const (
4+
// DefaultMaxPayments is the default maximum number of payments returned
5+
// in the payments query pagination.
6+
DefaultMaxPayments = 100
7+
)
8+
39
// Query represents a query to the payments database starting or ending
410
// at a certain offset index. The number of retrieved records can be limited.
511
type Query struct {

rpcserver.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7523,10 +7523,15 @@ func (r *rpcServer) ListPayments(ctx context.Context,
75237523
CreationDateEnd: int64(req.CreationDateEnd),
75247524
}
75257525

7526-
// If the maximum number of payments wasn't specified, then we'll
7527-
// default to return the maximal number of payments representable.
7526+
// If the maximum number of payments wasn't specified, we default to
7527+
// a reasonable number to prevent resource exhaustion. All of the
7528+
// payments are fetched into memory. Moreover we don't want our daemon
7529+
// to remain stable and do other stuff rather than serving payments.
7530+
//
7531+
// TODO(ziggie): Choose a more specific default value when results of
7532+
// performance testing are available.
75287533
if req.MaxPayments == 0 {
7529-
query.MaxPayments = math.MaxUint64
7534+
query.MaxPayments = paymentsdb.DefaultMaxPayments
75307535
}
75317536

75327537
paymentsQuerySlice, err := r.server.paymentsDB.QueryPayments(

0 commit comments

Comments
 (0)