forked from TrueCloudLab/frostfs-node
[#1713] node: Add Neo RPC switch interval to the config
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
0631b38da1
commit
9a0824766c
9 changed files with 34 additions and 12 deletions
|
@ -22,6 +22,9 @@ const (
|
||||||
// CacheTTLDefault is a default value for cached values TTL.
|
// CacheTTLDefault is a default value for cached values TTL.
|
||||||
// It is 0, because actual default depends on block time.
|
// It is 0, because actual default depends on block time.
|
||||||
CacheTTLDefault = time.Duration(0)
|
CacheTTLDefault = time.Duration(0)
|
||||||
|
|
||||||
|
// SwitchIntervalDefault is a default Neo RPCs switch interval.
|
||||||
|
SwitchIntervalDefault = 2 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// RPCEndpoint returns list of the values of "rpc_endpoint" config parameter
|
// RPCEndpoint returns list of the values of "rpc_endpoint" config parameter
|
||||||
|
@ -81,3 +84,16 @@ func CacheTTL(c *config.Config) time.Duration {
|
||||||
|
|
||||||
return CacheTTLDefault
|
return CacheTTLDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SwitchInterval returns the value of "switch_interval" config parameter
|
||||||
|
// from "morph" section.
|
||||||
|
//
|
||||||
|
// Returns SwitchIntervalDefault if value is not positive duration.
|
||||||
|
func SwitchInterval(c *config.Config) time.Duration {
|
||||||
|
res := config.DurationSafe(c.Sub(subsection), "switch_interval")
|
||||||
|
if res != 0 {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
return SwitchIntervalDefault
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ func TestMorphSection(t *testing.T) {
|
||||||
require.Panics(t, func() { morphconfig.RPCEndpoint(empty) })
|
require.Panics(t, func() { morphconfig.RPCEndpoint(empty) })
|
||||||
require.Equal(t, morphconfig.DialTimeoutDefault, morphconfig.DialTimeout(empty))
|
require.Equal(t, morphconfig.DialTimeoutDefault, morphconfig.DialTimeout(empty))
|
||||||
require.Equal(t, morphconfig.CacheTTLDefault, morphconfig.CacheTTL(empty))
|
require.Equal(t, morphconfig.CacheTTLDefault, morphconfig.CacheTTL(empty))
|
||||||
|
require.Equal(t, morphconfig.SwitchIntervalDefault, morphconfig.SwitchInterval(empty))
|
||||||
})
|
})
|
||||||
|
|
||||||
const path = "../../../../config/example/node"
|
const path = "../../../../config/example/node"
|
||||||
|
@ -33,6 +34,7 @@ func TestMorphSection(t *testing.T) {
|
||||||
require.Equal(t, rpcs, morphconfig.RPCEndpoint(c))
|
require.Equal(t, rpcs, morphconfig.RPCEndpoint(c))
|
||||||
require.Equal(t, 30*time.Second, morphconfig.DialTimeout(c))
|
require.Equal(t, 30*time.Second, morphconfig.DialTimeout(c))
|
||||||
require.Equal(t, 15*time.Second, morphconfig.CacheTTL(c))
|
require.Equal(t, 15*time.Second, morphconfig.CacheTTL(c))
|
||||||
|
require.Equal(t, 3*time.Minute, morphconfig.SwitchInterval(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
configtest.ForEachFileType(path, fileConfigTest)
|
configtest.ForEachFileType(path, fileConfigTest)
|
||||||
|
|
|
@ -51,6 +51,7 @@ func initMorphComponents(c *cfg) {
|
||||||
client.WithConnLostCallback(func() {
|
client.WithConnLostCallback(func() {
|
||||||
c.internalErr <- errors.New("morph connection has been lost")
|
c.internalErr <- errors.New("morph connection has been lost")
|
||||||
}),
|
}),
|
||||||
|
client.WithSwitchInterval(morphconfig.SwitchInterval(c.appCfg)),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Info("failed to create neo RPC client",
|
c.log.Info("failed to create neo RPC client",
|
||||||
|
|
|
@ -62,6 +62,7 @@ NEOFS_CONTRACTS_PROXY=ad7c6b55b737b696e5c82c85445040964a03e97f
|
||||||
# Morph chain section
|
# Morph chain section
|
||||||
NEOFS_MORPH_DIAL_TIMEOUT=30s
|
NEOFS_MORPH_DIAL_TIMEOUT=30s
|
||||||
NEOFS_MORPH_CACHE_TTL=15s
|
NEOFS_MORPH_CACHE_TTL=15s
|
||||||
|
NEOFS_MORPH_SWITCH_INTERVAL=3m
|
||||||
NEOFS_MORPH_RPC_ENDPOINT_0_ADDRESS="wss://rpc1.morph.fs.neo.org:40341/ws"
|
NEOFS_MORPH_RPC_ENDPOINT_0_ADDRESS="wss://rpc1.morph.fs.neo.org:40341/ws"
|
||||||
NEOFS_MORPH_RPC_ENDPOINT_0_PRIORITY=0
|
NEOFS_MORPH_RPC_ENDPOINT_0_PRIORITY=0
|
||||||
NEOFS_MORPH_RPC_ENDPOINT_1_ADDRESS="wss://rpc2.morph.fs.neo.org:40341/ws"
|
NEOFS_MORPH_RPC_ENDPOINT_1_ADDRESS="wss://rpc2.morph.fs.neo.org:40341/ws"
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
"morph": {
|
"morph": {
|
||||||
"dial_timeout": "30s",
|
"dial_timeout": "30s",
|
||||||
"cache_ttl": "15s",
|
"cache_ttl": "15s",
|
||||||
|
"switch_interval": "3m",
|
||||||
"rpc_endpoint": [
|
"rpc_endpoint": [
|
||||||
{
|
{
|
||||||
"address": "wss://rpc1.morph.fs.neo.org:40341/ws",
|
"address": "wss://rpc1.morph.fs.neo.org:40341/ws",
|
||||||
|
|
|
@ -84,6 +84,7 @@ morph:
|
||||||
cache_ttl: 15s # Sidechain cache TTL value (min interval between similar calls). Negative value disables caching.
|
cache_ttl: 15s # Sidechain cache TTL value (min interval between similar calls). Negative value disables caching.
|
||||||
# Default value: block time. It is recommended to have this value less or equal to block time.
|
# Default value: block time. It is recommended to have this value less or equal to block time.
|
||||||
# Cached entities: containers, container lists, eACL tables.
|
# Cached entities: containers, container lists, eACL tables.
|
||||||
|
switch_interval: 3m # interval b/w RPC switch attempts if the node is connected not to the highest priority node
|
||||||
rpc_endpoint: # side chain NEO RPC endpoints; are shuffled and used one by one until the first success
|
rpc_endpoint: # side chain NEO RPC endpoints; are shuffled and used one by one until the first success
|
||||||
- address: wss://rpc1.morph.fs.neo.org:40341/ws
|
- address: wss://rpc1.morph.fs.neo.org:40341/ws
|
||||||
priority: 0
|
priority: 0
|
||||||
|
|
|
@ -137,13 +137,15 @@ morph:
|
||||||
priority: 1
|
priority: 1
|
||||||
- address: wss://rpc2.morph.fs.neo.org:40341/ws
|
- address: wss://rpc2.morph.fs.neo.org:40341/ws
|
||||||
priority: 2
|
priority: 2
|
||||||
|
switch_interval: 2m
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Type | Default value | Description |
|
| Parameter | Type | Default value | Description |
|
||||||
|----------------|-----------------------------------------------------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------|-----------------------------------------------------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `dial_timeout` | `duration` | `5s` | Timeout for dialing connections to N3 RPCs. |
|
| `dial_timeout` | `duration` | `5s` | Timeout for dialing connections to N3 RPCs. |
|
||||||
| `cache_ttl` | `duration` | Morph block time | Sidechain cache TTL value (min interval between similar calls).<br/>Negative value disables caching.<br/>Cached entities: containers, container lists, eACL tables. |
|
| `cache_ttl` | `duration` | Morph block time | Sidechain cache TTL value (min interval between similar calls).<br/>Negative value disables caching.<br/>Cached entities: containers, container lists, eACL tables. |
|
||||||
| `rpc_endpoint` | list of [endpoint descriptions](#rpc_endpoint-subsection) | | Array of endpoint descriptions. |
|
| `rpc_endpoint` | list of [endpoint descriptions](#rpc_endpoint-subsection) | | Array of endpoint descriptions. |
|
||||||
|
| `switch_interval` | `duration` | `2m` | Time interval between the attempts to connect to the highest priority RPC node if the connection is not established yet. |
|
||||||
|
|
||||||
## `rpc_endpoint` subsection
|
## `rpc_endpoint` subsection
|
||||||
| Parameter | Type | Default value | Description |
|
| Parameter | Type | Default value | Description |
|
||||||
|
|
|
@ -51,7 +51,6 @@ type cfg struct {
|
||||||
const (
|
const (
|
||||||
defaultDialTimeout = 5 * time.Second
|
defaultDialTimeout = 5 * time.Second
|
||||||
defaultWaitInterval = 500 * time.Millisecond
|
defaultWaitInterval = 500 * time.Millisecond
|
||||||
defaultSwitchInterval = 2 * time.Minute
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultConfig() *cfg {
|
func defaultConfig() *cfg {
|
||||||
|
@ -63,7 +62,6 @@ func defaultConfig() *cfg {
|
||||||
signer: &transaction.Signer{
|
signer: &transaction.Signer{
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.Global,
|
||||||
},
|
},
|
||||||
switchInterval: defaultSwitchInterval,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (c *Client) switchRPC() bool {
|
||||||
c.rpcActor = act
|
c.rpcActor = act
|
||||||
c.gasToken = gas
|
c.gasToken = gas
|
||||||
|
|
||||||
if !c.switchIsActive.Load() &&
|
if c.cfg.switchInterval != 0 && !c.switchIsActive.Load() &&
|
||||||
c.endpoints.list[c.endpoints.curr].Priority != c.endpoints.list[0].Priority {
|
c.endpoints.list[c.endpoints.curr].Priority != c.endpoints.list[0].Priority {
|
||||||
c.switchIsActive.Store(true)
|
c.switchIsActive.Store(true)
|
||||||
go c.switchToMostPrioritized()
|
go c.switchToMostPrioritized()
|
||||||
|
|
Loading…
Reference in a new issue