From 0c88a9c27f5fecddb246a99d3a52a09b7542fd86 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 25 Aug 2023 15:08:38 +0200 Subject: [PATCH 1/2] soroban-rpc: getLedgerEntries: set maximum number of keys to query for --- cmd/soroban-rpc/internal/methods/get_ledger_entries.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/soroban-rpc/internal/methods/get_ledger_entries.go b/cmd/soroban-rpc/internal/methods/get_ledger_entries.go index 045fafb39..b9e33838e 100644 --- a/cmd/soroban-rpc/internal/methods/get_ledger_entries.go +++ b/cmd/soroban-rpc/internal/methods/get_ledger_entries.go @@ -33,9 +33,19 @@ type GetLedgerEntriesResponse struct { LatestLedger int64 `json:"latestLedger,string"` } +const ( + getLedgerEntriesMaxKeys = 200 +) + // NewGetLedgerEntriesHandler returns a JSON RPC handler to retrieve the specified ledger entries from Stellar Core. func NewGetLedgerEntriesHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader) jrpc2.Handler { return handler.New(func(ctx context.Context, request GetLedgerEntriesRequest) (GetLedgerEntriesResponse, error) { + if len(request.Keys) > getLedgerEntriesMaxKeys { + return GetLedgerEntriesResponse{}, &jrpc2.Error{ + Code: jrpc2.InvalidParams, + Message: fmt.Sprintf("key count (%d) exceeds maximum supported (%d)", len(request.Keys), getLedgerEntriesMaxKeys), + } + } var ledgerKeys []xdr.LedgerKey for i, requestKey := range request.Keys { var ledgerKey xdr.LedgerKey From 0cf4d214b9649a01b48345692548a3a96a375fbc Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 25 Aug 2023 16:18:33 +0200 Subject: [PATCH 2/2] Minor tweak --- cmd/soroban-rpc/internal/methods/get_ledger_entries.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_ledger_entries.go b/cmd/soroban-rpc/internal/methods/get_ledger_entries.go index b9e33838e..f4d14d223 100644 --- a/cmd/soroban-rpc/internal/methods/get_ledger_entries.go +++ b/cmd/soroban-rpc/internal/methods/get_ledger_entries.go @@ -33,9 +33,7 @@ type GetLedgerEntriesResponse struct { LatestLedger int64 `json:"latestLedger,string"` } -const ( - getLedgerEntriesMaxKeys = 200 -) +const getLedgerEntriesMaxKeys = 200 // NewGetLedgerEntriesHandler returns a JSON RPC handler to retrieve the specified ledger entries from Stellar Core. func NewGetLedgerEntriesHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader) jrpc2.Handler {