From 47ffc1f3e81b685ea199042b279ff9c54e78b047 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 5 Jul 2022 19:29:18 +0300 Subject: [PATCH] rpc: restrict default SessionExpirationTime --- docs/node-configuration.md | 6 +++--- pkg/config/config.go | 4 ---- pkg/rpc/server/server.go | 11 ++++++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/node-configuration.md b/docs/node-configuration.md index c50d583ec..10a8e9db9 100644 --- a/docs/node-configuration.md +++ b/docs/node-configuration.md @@ -137,7 +137,7 @@ RPC: MaxNEP11Tokens: 100 Port: 10332 SessionEnabled: false - SessionExpirationTime: 60 + SessionExpirationTime: 15 SessionBackedByMPT: false StartWhenSynchronized: false TLSConfig: @@ -177,8 +177,8 @@ where: enable `SessionBackedByMPT`, see `SessionBackedByMPT` documentation for more details. - `SessionExpirationTime` is a lifetime of iterator session in seconds. It is set - to `60` seconds by default and is relevant only if `SessionEnabled` is set to - `true`. + to `SecondsPerBlock` seconds by default and is relevant only if `SessionEnabled` + is set to `true`. - `SessionBackedByMPT` is a flag forcing JSON-RPC server into using MPT-backed storage for delayed iterator traversal. If `true`, then iterator resources got after `invoke*` calls will be released immediately. Further iterator traversing diff --git a/pkg/config/config.go b/pkg/config/config.go index 0e5ba81c4..be64e5a5f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -19,9 +19,6 @@ const ( // DefaultMaxIteratorResultItems is the default upper bound of traversed // iterator items per JSON-RPC response. DefaultMaxIteratorResultItems = 100 - // DefaultSessionExpirationTime is the default session expiration time in - // seconds for iterator RPC-server session. - DefaultSessionExpirationTime = 60 ) // Version is the version of the node, set at the build time. @@ -65,7 +62,6 @@ func LoadFile(configPath string) (Config, error) { MaxIteratorResultItems: DefaultMaxIteratorResultItems, MaxFindResultItems: 100, MaxNEP11Tokens: 100, - SessionExpirationTime: DefaultSessionExpirationTime, }, }, } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 32612c347..19fbf666c 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -202,13 +202,18 @@ func New(chain blockchainer.Blockchainer, conf rpc.Config, coreServer *network.S if orc != nil { orc.SetBroadcaster(broadcaster.New(orc.MainCfg, log)) } + protoCfg := chain.GetConfig() + if conf.SessionEnabled && conf.SessionExpirationTime <= 0 { + conf.SessionExpirationTime = protoCfg.SecondsPerBlock + log.Info("SessionExpirationTime is not set or wrong, setting default value", zap.Int("SessionExpirationTime", protoCfg.SecondsPerBlock)) + } return Server{ Server: httpServer, chain: chain, config: conf, - wsReadLimit: int64(chain.GetConfig().MaxBlockSize*4)/3 + 1024, // Enough for Base64-encoded content of `submitblock` and `submitp2pnotaryrequest`. - network: chain.GetConfig().Magic, - stateRootEnabled: chain.GetConfig().StateRootInHeader, + wsReadLimit: int64(protoCfg.MaxBlockSize*4)/3 + 1024, // Enough for Base64-encoded content of `submitblock` and `submitp2pnotaryrequest`. + network: protoCfg.Magic, + stateRootEnabled: protoCfg.StateRootInHeader, coreServer: coreServer, log: log, oracle: orc,