[#1846] neofs-node: Make morph.cache_ttl equal to block time by default

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-06 18:30:55 +03:00 committed by fyrchik
parent e54b52ec03
commit ca8dc872b2
5 changed files with 19 additions and 7 deletions

View file

@ -28,7 +28,9 @@ const (
// PriorityDefault is a default endpoint priority for the morph client.
PriorityDefault = 1
CacheTTLDefault = 30 * time.Second
// CacheTTLDefault is a default value for cached values TTL.
// It is 0, because actual default depends on block time.
CacheTTLDefault = time.Duration(0)
)
// RPCEndpoint returns list of the values of "rpc_endpoint" config parameter

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"time"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
@ -89,7 +90,14 @@ func initMorphComponents(c *cfg) {
c.cfgMorph.cacheTTL = morphconfig.CacheTTL(c.appCfg)
if c.cfgMorph.cacheTTL <= 0 {
if c.cfgMorph.cacheTTL == 0 {
msPerBlock, err := c.cfgMorph.client.MsPerBlock()
fatalOnErr(err)
c.cfgMorph.cacheTTL = time.Duration(msPerBlock) * time.Millisecond
c.log.Debug("morph.cache_ttl fetched from network", zap.Duration("value", c.cfgMorph.cacheTTL))
}
if c.cfgMorph.cacheTTL < 0 {
netmapSource = wrap
} else {
// use RPC node as source of netmap (with caching)