Skip to content

Commit 2ad8a8d

Browse files
committed
node: rename morph config section to fschain
Rename the `morph` section in the code, config and examples to `fschain`. Maintain compatibility for the transition and warn if `morph` is used. Migrate data for deprecated DB key to new. Refs #3021. Signed-off-by: Andrey Butusov <[email protected]>
1 parent 4e34161 commit 2ad8a8d

File tree

10 files changed

+169
-82
lines changed

10 files changed

+169
-82
lines changed

cmd/neofs-node/config.go

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine"
2424
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
2525
fstreeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor/fstree"
26+
fschainconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/fschain"
2627
loggerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/logger"
27-
morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph"
2828
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
2929
objectconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/object"
3030
policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer"
@@ -110,7 +110,7 @@ type applicationConfiguration struct {
110110
objectBatchSize uint32
111111
}
112112

113-
morph struct {
113+
fsChain struct {
114114
endpoints []string
115115
dialTimeout time.Duration
116116
cacheTTL time.Duration
@@ -166,13 +166,13 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error {
166166
a.engine.isIgnoreUninitedShards = engineconfig.IgnoreUninitedShards(c)
167167
a.engine.objectPutRetryDeadline = engineconfig.ObjectPutRetryDeadline(c)
168168

169-
// Morph
169+
// FS chain
170170

171-
a.morph.endpoints = morphconfig.Endpoints(c)
172-
a.morph.dialTimeout = morphconfig.DialTimeout(c)
173-
a.morph.cacheTTL = morphconfig.CacheTTL(c)
174-
a.morph.reconnectionRetriesNumber = morphconfig.ReconnectionRetriesNumber(c)
175-
a.morph.reconnectionRetriesDelay = morphconfig.ReconnectionRetriesDelay(c)
171+
a.fsChain.endpoints = fschainconfig.Endpoints(c)
172+
a.fsChain.dialTimeout = fschainconfig.DialTimeout(c)
173+
a.fsChain.cacheTTL = fschainconfig.CacheTTL(c)
174+
a.fsChain.reconnectionRetriesNumber = fschainconfig.ReconnectionRetriesNumber(c)
175+
a.fsChain.reconnectionRetriesDelay = fschainconfig.ReconnectionRetriesDelay(c)
176176

177177
// Contracts
178178

@@ -522,7 +522,10 @@ type cfgReputation struct {
522522
localTrustCtrl *trustcontroller.Controller
523523
}
524524

525-
var persistateFSChainLastBlockKey = []byte("fs_chain_last_processed_block")
525+
var (
526+
persistateFSChainLastBlockKey = []byte("fs_chain_last_processed_block")
527+
persistateDeprecatedSidechainLastBlockKey = []byte("side_chain_last_processed_block")
528+
)
526529

527530
func initCfg(appCfg *config.Config) *cfg {
528531
c := &cfg{}
@@ -649,6 +652,12 @@ func initCfg(appCfg *config.Config) *cfg {
649652

650653
c.veryLastClosers = make(map[string]func())
651654

655+
// warning if there is morph section
656+
657+
if c.cfgReader.Value("morph") != nil {
658+
c.log.Warn("config section 'morph' is deprecated, use 'fschain'")
659+
}
660+
652661
c.onShutdown(c.clientCache.CloseAll) // clean up connections
653662
c.onShutdown(c.bgClientCache.CloseAll) // clean up connections
654663
c.onShutdown(c.putClientCache.CloseAll) // clean up connections
@@ -660,22 +669,37 @@ func initCfg(appCfg *config.Config) *cfg {
660669
func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStorage) basics {
661670
b := basics{}
662671

663-
addresses := c.applicationConfiguration.morph.endpoints
672+
addresses := c.applicationConfiguration.fsChain.endpoints
664673

674+
fromDeprectedSidechanBlock, err := stateStorage.UInt32(persistateDeprecatedSidechainLastBlockKey)
675+
if err != nil {
676+
fromDeprectedSidechanBlock = 0
677+
}
665678
fromFSChainBlock, err := stateStorage.UInt32(persistateFSChainLastBlockKey)
666679
if err != nil {
667680
fromFSChainBlock = 0
668681
c.log.Warn("can't get last processed FS chain block number", zap.Error(err))
669682
}
670683

684+
// migration for deprecated DB key
685+
if fromFSChainBlock == 0 && fromDeprectedSidechanBlock != fromFSChainBlock {
686+
fromFSChainBlock = fromDeprectedSidechanBlock
687+
err = stateStorage.SetUInt32(persistateFSChainLastBlockKey, fromFSChainBlock)
688+
if err != nil {
689+
c.log.Warn("can't update persistent state",
690+
zap.String("chain", "FS"),
691+
zap.Uint32("block_index", fromFSChainBlock))
692+
}
693+
}
694+
671695
cli, err := client.New(key,
672696
client.WithContext(c.internals.ctx),
673-
client.WithDialTimeout(c.applicationConfiguration.morph.dialTimeout),
697+
client.WithDialTimeout(c.applicationConfiguration.fsChain.dialTimeout),
674698
client.WithLogger(c.log),
675699
client.WithAutoFSChainScope(),
676700
client.WithEndpoints(addresses),
677-
client.WithReconnectionRetries(c.applicationConfiguration.morph.reconnectionRetriesNumber),
678-
client.WithReconnectionsDelay(c.applicationConfiguration.morph.reconnectionRetriesDelay),
701+
client.WithReconnectionRetries(c.applicationConfiguration.fsChain.reconnectionRetriesNumber),
702+
client.WithReconnectionsDelay(c.applicationConfiguration.fsChain.reconnectionRetriesDelay),
679703
client.WithConnSwitchCallback(func() {
680704
err = c.restartMorph()
681705
if err != nil {
@@ -709,12 +733,12 @@ func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStor
709733
nmWrap, err := nmClient.NewFromMorph(cli, b.netmapSH, 0)
710734
fatalOnErr(err)
711735

712-
ttl := c.applicationConfiguration.morph.cacheTTL
736+
ttl := c.applicationConfiguration.fsChain.cacheTTL
713737
if ttl == 0 {
714738
msPerBlock, err := cli.MsPerBlock()
715739
fatalOnErr(err)
716740
ttl = time.Duration(msPerBlock) * time.Millisecond
717-
c.log.Debug("morph.cache_ttl fetched from network", zap.Duration("value", ttl))
741+
c.log.Debug("fschain.cache_ttl fetched from network", zap.Duration("value", ttl))
718742
}
719743

720744
var netmapSource netmapCore.Source
@@ -918,7 +942,7 @@ func (c *cfg) configWatcher(ctx context.Context) {
918942

919943
// Morph
920944

921-
c.cli.Reload(client.WithEndpoints(c.morph.endpoints))
945+
c.cli.Reload(client.WithEndpoints(c.fsChain.endpoints))
922946

923947
// Node
924948

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package morphconfig
1+
package fschainconfig
22

33
import (
44
"fmt"
@@ -8,9 +8,10 @@ import (
88
)
99

1010
const (
11-
subsection = "morph"
11+
subsection = "fschain"
12+
deprecatedMorphSubsection = "morph"
1213

13-
// DialTimeoutDefault is a default dial timeout of morph chain client connection.
14+
// DialTimeoutDefault is a default dial timeout of FS chain client connection.
1415
DialTimeoutDefault = time.Minute
1516

1617
// CacheTTLDefault is a default value for cached values TTL.
@@ -24,65 +25,90 @@ const (
2425
)
2526

2627
// Endpoints returns list of the values of "endpoints" config parameter
27-
// from "morph" section.
28+
// from "fschain" section (primary) or from "morph" section.
2829
//
2930
// Throws panic if list is empty.
3031
func Endpoints(c *config.Config) []string {
3132
endpoints := config.StringSliceSafe(c.Sub(subsection), "endpoints")
32-
if len(endpoints) == 0 {
33-
panic(fmt.Errorf("no morph chain RPC endpoints, see `morph.endpoints` section"))
33+
morphEndpoints := config.StringSliceSafe(c.Sub(deprecatedMorphSubsection), "endpoints")
34+
35+
if len(endpoints) == 0 && len(morphEndpoints) == 0 {
36+
panic(fmt.Errorf("no FS chain RPC endpoints, see `fschain.endpoints` section"))
37+
}
38+
if len(endpoints) > 0 {
39+
return endpoints
3440
}
35-
return endpoints
41+
return morphEndpoints
3642
}
3743

3844
// DialTimeout returns the value of "dial_timeout" config parameter
39-
// from "morph" section.
45+
// from "fschain" section (primary) or from "morph" section.
4046
//
4147
// Returns DialTimeoutDefault if the value is not positive duration.
4248
func DialTimeout(c *config.Config) time.Duration {
4349
v := config.DurationSafe(c.Sub(subsection), "dial_timeout")
50+
morphV := config.DurationSafe(c.Sub(deprecatedMorphSubsection), "dial_timeout")
51+
4452
if v > 0 {
4553
return v
4654
}
55+
if morphV > 0 {
56+
return morphV
57+
}
4758

4859
return DialTimeoutDefault
4960
}
5061

5162
// CacheTTL returns the value of "cache_ttl" config parameter
52-
// from "morph" section.
63+
// from "fschain" section (primary) or from "morph" section.
5364
//
5465
// Returns CacheTTLDefault if value is zero or invalid. Supports negative durations.
5566
func CacheTTL(c *config.Config) time.Duration {
5667
res := config.DurationSafe(c.Sub(subsection), "cache_ttl")
68+
morphRes := config.DurationSafe(c.Sub(deprecatedMorphSubsection), "cache_ttl")
69+
5770
if res != 0 {
5871
return res
5972
}
73+
if morphRes != 0 {
74+
return morphRes
75+
}
6076

6177
return CacheTTLDefault
6278
}
6379

6480
// ReconnectionRetriesNumber returns the value of "reconnections_number" config
65-
// parameter from "morph" section.
81+
// parameter from "fschain" section (primary) or from "morph" section.
6682
//
6783
// Returns 0 if value is not specified.
6884
func ReconnectionRetriesNumber(c *config.Config) int {
6985
res := config.Int(c.Sub(subsection), "reconnections_number")
86+
morphRes := config.Int(c.Sub(deprecatedMorphSubsection), "reconnections_number")
87+
7088
if res != 0 {
7189
return int(res)
7290
}
91+
if morphRes != 0 {
92+
return int(morphRes)
93+
}
7394

7495
return ReconnectionRetriesNumberDefault
7596
}
7697

7798
// ReconnectionRetriesDelay returns the value of "reconnections_delay" config
78-
// parameter from "morph" section.
99+
// parameter from "fschain" section (primary) or from "morph" section.
79100
//
80101
// Returns 0 if value is not specified.
81102
func ReconnectionRetriesDelay(c *config.Config) time.Duration {
82103
res := config.DurationSafe(c.Sub(subsection), "reconnections_delay")
104+
morphRes := config.DurationSafe(c.Sub(deprecatedMorphSubsection), "reconnections_delay")
105+
83106
if res != 0 {
84107
return res
85108
}
109+
if morphRes != 0 {
110+
return morphRes
111+
}
86112

87113
return ReconnectionRetriesDelayDefault
88114
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package fschainconfig_test
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
"time"
8+
9+
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
10+
fschainconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/fschain"
11+
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestFSChainSection(t *testing.T) {
16+
t.Run("defaults", func(t *testing.T) {
17+
empty := configtest.EmptyConfig()
18+
19+
require.Panics(t, func() { fschainconfig.Endpoints(empty) })
20+
require.Equal(t, fschainconfig.DialTimeoutDefault, fschainconfig.DialTimeout(empty))
21+
require.Equal(t, fschainconfig.CacheTTLDefault, fschainconfig.CacheTTL(empty))
22+
require.Equal(t, 5, fschainconfig.ReconnectionRetriesNumber(empty))
23+
require.Equal(t, 5*time.Second, fschainconfig.ReconnectionRetriesDelay(empty))
24+
})
25+
26+
const path = "../../../../config/example/node"
27+
28+
rpcs := []string{"wss://rpc1.morph.fs.neo.org:40341/ws", "wss://rpc2.morph.fs.neo.org:40341/ws"}
29+
30+
var fileConfigTest = func(c *config.Config) {
31+
require.Equal(t, rpcs, fschainconfig.Endpoints(c))
32+
require.Equal(t, 30*time.Second, fschainconfig.DialTimeout(c))
33+
require.Equal(t, 15*time.Second, fschainconfig.CacheTTL(c))
34+
require.Equal(t, 6, fschainconfig.ReconnectionRetriesNumber(c))
35+
require.Equal(t, 6*time.Second, fschainconfig.ReconnectionRetriesDelay(c))
36+
}
37+
38+
configtest.ForEachFileType(path, fileConfigTest)
39+
40+
t.Run("ENV", func(t *testing.T) {
41+
configtest.ForEnvFileType(path, fileConfigTest)
42+
})
43+
44+
t.Run("compatibility with morph section", func(t *testing.T) {
45+
data := []byte(`
46+
morph:
47+
dial_timeout: 30s
48+
cache_ttl: 15s
49+
reconnections_number: 6
50+
reconnections_delay: 6s
51+
endpoints:
52+
- wss://rpc1.morph.fs.neo.org:40341/ws
53+
- wss://rpc2.morph.fs.neo.org:40341/ws
54+
`)
55+
56+
morphPath := filepath.Join(t.TempDir(), "morph.yaml")
57+
require.NoError(t, os.WriteFile(morphPath, data, 0o640))
58+
59+
var p config.Prm
60+
61+
os.Clearenv()
62+
63+
c := config.New(p,
64+
config.WithConfigFile(morphPath),
65+
config.WithValidate(false),
66+
)
67+
68+
fileConfigTest(c)
69+
})
70+
}

cmd/neofs-node/config/internal/validate/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ type valideConfig struct {
8787
Endpoints []string `mapstructure:"endpoints"`
8888
} `mapstructure:"morph"`
8989

90+
FSChain struct {
91+
DialTimeout time.Duration `mapstructure:"dial_timeout"`
92+
CacheTTL time.Duration `mapstructure:"cache_ttl"`
93+
ReconnectionsNumber int `mapstructure:"reconnections_number"`
94+
ReconnectionsDelay time.Duration `mapstructure:"reconnections_delay"`
95+
Endpoints []string `mapstructure:"endpoints"`
96+
} `mapstructure:"fschain"`
97+
9098
APIClient struct {
9199
DialTimeout time.Duration `mapstructure:"dial_timeout"`
92100
StreamTimeout time.Duration `mapstructure:"stream_timeout"`

cmd/neofs-node/config/morph/config_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

config/example/node.env

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ NEOFS_CONTRACTS_NETMAP=0cce9e948dca43a6b592efe59ddb4ecb89bdd9ca
5858
NEOFS_CONTRACTS_REPUTATION=441995f631c1da2b133462b71859494a5cd45e90
5959
NEOFS_CONTRACTS_PROXY=ad7c6b55b737b696e5c82c85445040964a03e97f
6060

61-
# Morph chain section
62-
NEOFS_MORPH_DIAL_TIMEOUT=30s
63-
NEOFS_MORPH_CACHE_TTL=15s
64-
NEOFS_MORPH_RECONNECTIONS_NUMBER=6
65-
NEOFS_MORPH_RECONNECTIONS_DELAY=6s
66-
NEOFS_MORPH_ENDPOINTS="wss://rpc1.morph.fs.neo.org:40341/ws wss://rpc2.morph.fs.neo.org:40341/ws"
61+
# FS chain section
62+
NEOFS_FSCHAIN_DIAL_TIMEOUT=30s
63+
NEOFS_FSCHAIN_CACHE_TTL=15s
64+
NEOFS_FSCHAIN_RECONNECTIONS_NUMBER=6
65+
NEOFS_FSCHAIN_RECONNECTIONS_DELAY=6s
66+
NEOFS_FSCHAIN_ENDPOINTS="wss://rpc1.morph.fs.neo.org:40341/ws wss://rpc2.morph.fs.neo.org:40341/ws"
6767

6868
# API Client section
6969
NEOFS_APICLIENT_DIAL_TIMEOUT=15s

0 commit comments

Comments
 (0)