From 97a57de82d4b5d0bcbf8d91754982faeed80ecaf Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 29 Aug 2023 12:32:00 +0300 Subject: [PATCH] rpcsrv: set MaxIteratorResultItems to default if not specified Do not use RPC configuration constructor for this, some external services may skip this part. Signed-off-by: Anna Shaleva --- pkg/config/config.go | 4 ++-- pkg/services/rpcsrv/server.go | 4 ++++ pkg/services/rpcsrv/server_test.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index ede5b4102..ed701d8ac 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,7 +17,8 @@ const ( // UserAgentFormat is a formatted string used to generate user agent string. UserAgentFormat = UserAgentWrapper + UserAgentPrefix + "%s" + UserAgentWrapper // DefaultMaxIteratorResultItems is the default upper bound of traversed - // iterator items per JSON-RPC response. + // iterator items per JSON-RPC response. It covers both session-based and + // naive iterators. DefaultMaxIteratorResultItems = 100 // DefaultMaxFindStorageResultItems is the default maximum number of resulting // contract storage items that can be retrieved by `findstorge` JSON-RPC handler. @@ -74,7 +75,6 @@ func LoadFile(configPath string) (Config, error) { PingTimeout: 90 * time.Second, }, RPC: RPC{ - MaxIteratorResultItems: DefaultMaxIteratorResultItems, MaxFindResultItems: 100, MaxFindStorageResultItems: DefaultMaxFindStorageResultItems, MaxNEP11Tokens: 100, diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index a8bd13c45..9c588c3de 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -295,6 +295,10 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server, log.Info("SessionPoolSize is not set or wrong, setting default value", zap.Int("SessionPoolSize", defaultSessionPoolSize)) } } + if conf.MaxIteratorResultItems <= 0 { + conf.MaxIteratorResultItems = config.DefaultMaxIteratorResultItems + log.Info("MaxIteratorResultItems is not set or wrong, setting default value", zap.Int("MaxIteratorResultItems", config.DefaultMaxIteratorResultItems)) + } if conf.MaxWebSocketClients == 0 { conf.MaxWebSocketClients = defaultMaxWebSocketClients log.Info("MaxWebSocketClients is not set or wrong, setting default value", zap.Int("MaxWebSocketClients", defaultMaxWebSocketClients)) diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index b85640d25..81c542e5c 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -2973,9 +2973,9 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] }) t.Run("count is out of range", func(t *testing.T) { sID, iID := prepareIteratorSession(t) - rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "traverseiterator", "params": ["%s", "%s", %d]}"`, sID.String(), iID.String(), rpcSrv.config.MaxIteratorResultItems+1) + rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "traverseiterator", "params": ["%s", "%s", %d]}"`, sID.String(), iID.String(), config.DefaultMaxIteratorResultItems+1) body := doRPCCall(rpc, httpSrv.URL, t) - checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, fmt.Sprintf("iterator items count is out of range (%d at max)", rpcSrv.config.MaxIteratorResultItems)) + checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, fmt.Sprintf("iterator items count is out of range (%d at max)", config.DefaultMaxIteratorResultItems)) }) t.Run("unknown session", func(t *testing.T) { _, iID := prepareIteratorSession(t)