From 7a1c1638e4c3b091c1163f26d68921c837178962 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 6 Apr 2021 17:08:04 +0300 Subject: [PATCH] oracle: specify neofs timeout as timeout, set default if 0 There has to be some sane default and we'd like configuration to be consistent with other timeout values. --- pkg/config/oracle_config.go | 4 ++-- pkg/services/oracle/oracle.go | 3 +++ pkg/services/oracle/request.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/config/oracle_config.go b/pkg/config/oracle_config.go index 479abd0ba..a12454f70 100644 --- a/pkg/config/oracle_config.go +++ b/pkg/config/oracle_config.go @@ -18,6 +18,6 @@ type OracleConfiguration struct { // NeoFSConfiguration is a config for the NeoFS service. type NeoFSConfiguration struct { - Nodes []string `yaml:"Nodes"` - Timeout int `yaml:"Timeout"` + Nodes []string `yaml:"Nodes"` + Timeout time.Duration `yaml:"Timeout"` } diff --git a/pkg/services/oracle/oracle.go b/pkg/services/oracle/oracle.go index 8cfb3b424..94f5084f1 100644 --- a/pkg/services/oracle/oracle.go +++ b/pkg/services/oracle/oracle.go @@ -108,6 +108,9 @@ func NewOracle(cfg Config) (*Oracle, error) { if o.MainCfg.RequestTimeout == 0 { o.MainCfg.RequestTimeout = defaultRequestTimeout } + if o.MainCfg.NeoFS.Timeout == 0 { + o.MainCfg.NeoFS.Timeout = defaultRequestTimeout + } if o.MainCfg.MaxConcurrentRequests == 0 { o.MainCfg.MaxConcurrentRequests = defaultMaxConcurrentRequests } diff --git a/pkg/services/oracle/request.go b/pkg/services/oracle/request.go index 9a354b330..e61f47ba6 100644 --- a/pkg/services/oracle/request.go +++ b/pkg/services/oracle/request.go @@ -140,7 +140,7 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error { resp.Code = transaction.Error } case neofs.URIScheme: - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(o.MainCfg.NeoFS.Timeout)*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), o.MainCfg.NeoFS.Timeout) defer cancel() index := (int(req.ID) + incTx.attempts) % len(o.MainCfg.NeoFS.Nodes) res, err := neofs.Get(ctx, priv, u, o.MainCfg.NeoFS.Nodes[index])