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 <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-08-29 12:32:00 +03:00
parent b4dff7b040
commit 97a57de82d
3 changed files with 8 additions and 4 deletions

View file

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

View file

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

View file

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