[#496] cmd/node: Add mainchain section to config
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
cf5e371590
commit
4ef968aa06
5 changed files with 90 additions and 0 deletions
35
cmd/neofs-node/config/mainchain/config.go
Normal file
35
cmd/neofs-node/config/mainchain/config.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package mainchainconfig
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
)
|
||||
|
||||
const (
|
||||
subsection = "mainchain"
|
||||
|
||||
// DialTimeoutDefault is a default dial timeout of main chain client connection.
|
||||
DialTimeoutDefault = 5 * time.Second
|
||||
)
|
||||
|
||||
// RPCEndpoint returns list of values of "rpc_endpoint" config parameter
|
||||
// from "mainchain" section.
|
||||
//
|
||||
// Returns empty list if value is not a non-empty string array.
|
||||
func RPCEndpoint(c *config.Config) []string {
|
||||
return config.StringSliceSafe(c.Sub(subsection), "rpc_endpoint")
|
||||
}
|
||||
|
||||
// DialTimeout returns value of "dial_timeout" config parameter
|
||||
// from "mainchain" section.
|
||||
//
|
||||
// Returns DialTimeoutDefault if value is not positive duration.
|
||||
func DialTimeout(c *config.Config) time.Duration {
|
||||
v := config.DurationSafe(c.Sub(subsection), "dial_timeout")
|
||||
if v != 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
return DialTimeoutDefault
|
||||
}
|
38
cmd/neofs-node/config/mainchain/config_test.go
Normal file
38
cmd/neofs-node/config/mainchain/config_test.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package mainchainconfig_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
mainchainconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/mainchain"
|
||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMainchainSection(t *testing.T) {
|
||||
t.Run("defaults", func(t *testing.T) {
|
||||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.Empty(t, mainchainconfig.RPCEndpoint(empty))
|
||||
require.Equal(t, mainchainconfig.DialTimeoutDefault, mainchainconfig.DialTimeout(empty))
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
||||
var rpcs = []string{
|
||||
"https://rpc1.n3.nspcc.ru:30341",
|
||||
"https://rpc2.n3.nspcc.ru:30341",
|
||||
}
|
||||
|
||||
var fileConfigTest = func(c *config.Config) {
|
||||
require.Equal(t, rpcs, mainchainconfig.RPCEndpoint(c))
|
||||
require.Equal(t, 30*time.Second, mainchainconfig.DialTimeout(c))
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
||||
t.Run("ENV", func(t *testing.T) {
|
||||
configtest.ForEnvFileType(path, fileConfigTest)
|
||||
})
|
||||
}
|
|
@ -34,6 +34,10 @@ NEOFS_MORPH_DIAL_TIMEOUT=30s
|
|||
NEOFS_MORPH_RPC_ENDPOINT=https://rpc1.morph.fs.neo.org:40341 https://rpc2.morph.fs.neo.org:40341
|
||||
NEOFS_MORPH_NOTIFICATION_ENDPOINT=wss://rpc1.morph.fs.neo.org:40341/ws wss://rpc2.morph.fs.neo.org:40341/ws
|
||||
|
||||
# Main chain section (optional)
|
||||
NEOFS_MAINCHAIN_DIAL_TIMEOUT=30s
|
||||
NEOFS_MAINCHAIN_RPC_ENDPOINT=https://rpc1.n3.nspcc.ru:30341 https://rpc2.n3.nspcc.ru:30341
|
||||
|
||||
# Storage engine section
|
||||
NEOFS_STORAGE_SHARD_NUM=2
|
||||
## 0 shard
|
||||
|
|
|
@ -51,6 +51,13 @@
|
|||
"wss://rpc2.morph.fs.neo.org:40341/ws"
|
||||
]
|
||||
},
|
||||
"mainchain": {
|
||||
"dial_timeout": "30s",
|
||||
"rpc_endpoint": [
|
||||
"https://rpc1.n3.nspcc.ru:30341",
|
||||
"https://rpc2.n3.nspcc.ru:30341"
|
||||
]
|
||||
},
|
||||
"storage": {
|
||||
"shard_num": 2,
|
||||
"shard": {
|
||||
|
|
|
@ -45,6 +45,12 @@ morph:
|
|||
- wss://rpc1.morph.fs.neo.org:40341/ws
|
||||
- wss://rpc2.morph.fs.neo.org:40341/ws
|
||||
|
||||
mainchain:
|
||||
dial_timeout: 30s
|
||||
rpc_endpoint:
|
||||
- https://rpc1.n3.nspcc.ru:30341
|
||||
- https://rpc2.n3.nspcc.ru:30341
|
||||
|
||||
storage:
|
||||
shard_num: 2
|
||||
shard:
|
||||
|
|
Loading…
Reference in a new issue