rpc: restrict default SessionExpirationTime

This commit is contained in:
Anna Shaleva 2022-07-05 19:29:18 +03:00
parent b5d39a3ffd
commit 47ffc1f3e8
3 changed files with 11 additions and 10 deletions

View file

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

View file

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

View file

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