mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
config: drop deprecated address/port configurations
Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
a59afa8ea3
commit
de69560c7d
13 changed files with 8 additions and 281 deletions
18
ROADMAP.md
18
ROADMAP.md
|
@ -26,24 +26,6 @@ APIs/commands/configurations will be removed and here is a list of scheduled
|
||||||
breaking changes. Consider changing your code/scripts/configurations if you're
|
breaking changes. Consider changing your code/scripts/configurations if you're
|
||||||
using anything mentioned here.
|
using anything mentioned here.
|
||||||
|
|
||||||
## Services/node address and port configuration
|
|
||||||
|
|
||||||
Version 0.100.0 of NeoGo introduces a multiple binding addresses capability to
|
|
||||||
the node's services (RPC server, TLS RPC configuration, Prometheus, Pprof) and
|
|
||||||
the node itself. It allows to specify several listen addresses/ports using an
|
|
||||||
array of "address:port" pairs in the service's `Addresses` config section and
|
|
||||||
array of "address:port:announcedPort" tuples in the `ApplicationConfiguration`'s
|
|
||||||
`Addresses` node config section. Deprecated `Address` and `Port` sections of
|
|
||||||
`RPC`, `Prometheus`, `Pprof` subsections of the `ApplicationConfiguration`
|
|
||||||
as far as the one of RPC server's `TLSConfig` are still available, but will be
|
|
||||||
removed, so please convert your node configuration file to use new `P2P`-level
|
|
||||||
`Addresses` section for the node services. Deprecated `Address`, `NodePort` and
|
|
||||||
`AnnouncedPort` sections of `ApplicationConfiguration` will also be removed
|
|
||||||
eventually, so please update your node configuration file to use `Addresses`
|
|
||||||
section for the P2P addresses configuration.
|
|
||||||
|
|
||||||
Removal of these config sections is scheduled for May-June 2023 (~0.103.0 release).
|
|
||||||
|
|
||||||
## P2P application settings configuration
|
## P2P application settings configuration
|
||||||
|
|
||||||
Version 0.100.0 of NeoGo marks the following P2P application settings as
|
Version 0.100.0 of NeoGo marks the following P2P application settings as
|
||||||
|
|
|
@ -136,7 +136,6 @@ func initBCWithMetrics(cfg config.Config, log *zap.Logger) (*core.Blockchain, *m
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, cli.NewExitError(err, 1)
|
return nil, nil, nil, cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
configureAddresses(&cfg.ApplicationConfiguration)
|
|
||||||
prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus, log)
|
prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus, log)
|
||||||
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log)
|
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log)
|
||||||
|
|
||||||
|
@ -547,7 +546,6 @@ Main:
|
||||||
break // Continue working.
|
break // Continue working.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configureAddresses(&cfgnew.ApplicationConfiguration)
|
|
||||||
switch sig {
|
switch sig {
|
||||||
case sighup:
|
case sighup:
|
||||||
if newLogLevel != zapcore.InvalidLevel {
|
if newLogLevel != zapcore.InvalidLevel {
|
||||||
|
@ -648,24 +646,6 @@ Main:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// configureAddresses sets up addresses for RPC, Prometheus and Pprof depending from the provided config.
|
|
||||||
// In case RPC or Prometheus or Pprof Address provided each of them will use it.
|
|
||||||
// In case global Address (of the node) provided and RPC/Prometheus/Pprof don't have configured addresses they will
|
|
||||||
// use global one. So Node and RPC and Prometheus and Pprof will run on one address.
|
|
||||||
func configureAddresses(cfg *config.ApplicationConfiguration) {
|
|
||||||
if cfg.Address != nil && *cfg.Address != "" { //nolint:staticcheck // SA1019: cfg.Address is deprecated
|
|
||||||
if cfg.RPC.Address == nil || *cfg.RPC.Address == "" { //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
cfg.RPC.Address = cfg.Address //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
}
|
|
||||||
if cfg.Prometheus.Address == nil || *cfg.Prometheus.Address == "" { //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
cfg.Prometheus.Address = cfg.Address //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
}
|
|
||||||
if cfg.Pprof.Address == nil || *cfg.Pprof.Address == "" { //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
cfg.Pprof.Address = cfg.Address //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initBlockChain initializes BlockChain with preselected DB.
|
// initBlockChain initializes BlockChain with preselected DB.
|
||||||
func initBlockChain(cfg config.Config, log *zap.Logger) (*core.Blockchain, storage.Store, error) {
|
func initBlockChain(cfg config.Config, log *zap.Logger) (*core.Blockchain, storage.Store, error) {
|
||||||
store, err := storage.NewStore(cfg.ApplicationConfiguration.DBConfiguration)
|
store, err := storage.NewStore(cfg.ApplicationConfiguration.DBConfiguration)
|
||||||
|
|
|
@ -324,64 +324,6 @@ func TestRestoreDB(t *testing.T) {
|
||||||
require.NoError(t, restoreDB(ctx))
|
require.NoError(t, restoreDB(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestConfigureAddresses checks deprecated code compatibility, it should be removed
|
|
||||||
// along with deprecated `Address` field removal.
|
|
||||||
func TestConfigureAddresses(t *testing.T) {
|
|
||||||
defaultAddress := "http://localhost:10333"
|
|
||||||
customAddress := "http://localhost:10334"
|
|
||||||
|
|
||||||
t.Run("default addresses", func(t *testing.T) {
|
|
||||||
cfg := &config.ApplicationConfiguration{
|
|
||||||
Address: &defaultAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
}
|
|
||||||
configureAddresses(cfg)
|
|
||||||
require.Equal(t, defaultAddress, *cfg.RPC.Address) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
require.Equal(t, defaultAddress, *cfg.Prometheus.Address) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
require.Equal(t, defaultAddress, *cfg.Pprof.Address) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("custom RPC address", func(t *testing.T) {
|
|
||||||
cfg := &config.ApplicationConfiguration{
|
|
||||||
Address: &defaultAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
RPC: config.RPC{
|
|
||||||
BasicService: config.BasicService{
|
|
||||||
Address: &customAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
configureAddresses(cfg)
|
|
||||||
require.Equal(t, *cfg.RPC.Address, customAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Prometheus.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Pprof.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("custom Pprof address", func(t *testing.T) {
|
|
||||||
cfg := &config.ApplicationConfiguration{
|
|
||||||
Address: &defaultAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
Pprof: config.BasicService{
|
|
||||||
Address: &customAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
},
|
|
||||||
}
|
|
||||||
configureAddresses(cfg)
|
|
||||||
require.Equal(t, *cfg.RPC.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Prometheus.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Pprof.Address, customAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("custom Prometheus address", func(t *testing.T) {
|
|
||||||
cfg := &config.ApplicationConfiguration{
|
|
||||||
Address: &defaultAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
Prometheus: config.BasicService{
|
|
||||||
Address: &customAddress, //nolint:staticcheck // SA1019: Address is deprecated
|
|
||||||
},
|
|
||||||
}
|
|
||||||
configureAddresses(cfg)
|
|
||||||
require.Equal(t, *cfg.RPC.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Prometheus.Address, customAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
|
|
||||||
require.Equal(t, *cfg.Pprof.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInitBlockChain(t *testing.T) {
|
func TestInitBlockChain(t *testing.T) {
|
||||||
t.Run("bad storage", func(t *testing.T) {
|
t.Run("bad storage", func(t *testing.T) {
|
||||||
_, _, err := initBlockChain(config.Config{}, nil)
|
_, _, err := initBlockChain(config.Config{}, nil)
|
||||||
|
|
|
@ -16,8 +16,6 @@ node-related settings described in the table below.
|
||||||
|
|
||||||
| Section | Type | Default value | Description |
|
| Section | Type | Default value | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| Address | `string` | `0.0.0.0` | Node address that P2P protocol handler binds to. Warning: this field is deprecated, please, use `Addresses` instead. |
|
|
||||||
| AnnouncedPort | `uint16` | Same as `NodePort` | Node port which should be used to announce node's port on P2P layer, it can differ from the `NodePort` the node is bound to (for example, if your node is behind NAT). Warning: this field is deprecated, please, use `Addresses` instead. |
|
|
||||||
| AttemptConnPeers | `int` | `20` | Number of connection to try to establish when the connection count drops below the `MinPeers` value. Warning: this field is deprecated and moved to `P2P` section. |
|
| AttemptConnPeers | `int` | `20` | Number of connection to try to establish when the connection count drops below the `MinPeers` value. Warning: this field is deprecated and moved to `P2P` section. |
|
||||||
| BroadcastFactor | `int` | `0` | Multiplier that is used to determine the number of optimal gossip fan-out peer number for broadcasted messages (0-100). By default it's zero, node uses the most optimized value depending on the estimated network size (`2.5×log(size)`), so the node may have 20 peers and calculate that it needs to broadcast messages to just 10 of them. With BroadcastFactor set to 100 it will always send messages to all peers, any value in-between 0 and 100 is used for weighted calculation, for example if it's 30 then 13 neighbors will be used in the previous case. Warning: this field is deprecated and moved to `P2P` section. |
|
| BroadcastFactor | `int` | `0` | Multiplier that is used to determine the number of optimal gossip fan-out peer number for broadcasted messages (0-100). By default it's zero, node uses the most optimized value depending on the estimated network size (`2.5×log(size)`), so the node may have 20 peers and calculate that it needs to broadcast messages to just 10 of them. With BroadcastFactor set to 100 it will always send messages to all peers, any value in-between 0 and 100 is used for weighted calculation, for example if it's 30 then 13 neighbors will be used in the previous case. Warning: this field is deprecated and moved to `P2P` section. |
|
||||||
| DBConfiguration | [DB Configuration](#DB-Configuration) | | Describes configuration for database. See the [DB Configuration](#DB-Configuration) section for details. |
|
| DBConfiguration | [DB Configuration](#DB-Configuration) | | Describes configuration for database. See the [DB Configuration](#DB-Configuration) section for details. |
|
||||||
|
@ -29,7 +27,6 @@ node-related settings described in the table below.
|
||||||
| LogPath | `string` | "", so only console logging | File path where to store node logs. |
|
| LogPath | `string` | "", so only console logging | File path where to store node logs. |
|
||||||
| MaxPeers | `int` | `100` | Maximum numbers of peers that can be connected to the server. Warning: this field is deprecated and moved to `P2P` section. |
|
| MaxPeers | `int` | `100` | Maximum numbers of peers that can be connected to the server. Warning: this field is deprecated and moved to `P2P` section. |
|
||||||
| MinPeers | `int` | `5` | Minimum number of peers for normal operation; when the node has less than this number of peers it tries to connect with some new ones. Warning: this field is deprecated and moved to `P2P` section. |
|
| MinPeers | `int` | `5` | Minimum number of peers for normal operation; when the node has less than this number of peers it tries to connect with some new ones. Warning: this field is deprecated and moved to `P2P` section. |
|
||||||
| NodePort | `uint16` | `0`, which is any free port | The actual node port it is bound to. Warning: this field is deprecated, please, use `Addresses` instead. |
|
|
||||||
| Oracle | [Oracle Configuration](#Oracle-Configuration) | | Oracle module configuration. See the [Oracle Configuration](#Oracle-Configuration) section for details. |
|
| Oracle | [Oracle Configuration](#Oracle-Configuration) | | Oracle module configuration. See the [Oracle Configuration](#Oracle-Configuration) section for details. |
|
||||||
| P2P | [P2P Configuration](#P2P-Configuration) | | Configuration values for P2P network interaction. See the [P2P Configuration](#P2P-Configuration) section for details. |
|
| P2P | [P2P Configuration](#P2P-Configuration) | | Configuration values for P2P network interaction. See the [P2P Configuration](#P2P-Configuration) section for details. |
|
||||||
| P2PNotary | [P2P Notary Configuration](#P2P-Notary-Configuration) | | P2P Notary module configuration. See the [P2P Notary Configuration](#P2P-Notary-Configuration) section for details. |
|
| P2PNotary | [P2P Notary Configuration](#P2P-Notary-Configuration) | | P2P Notary module configuration. See the [P2P Notary Configuration](#P2P-Notary-Configuration) section for details. |
|
||||||
|
@ -182,10 +179,6 @@ Prometheus:
|
||||||
```
|
```
|
||||||
where:
|
where:
|
||||||
- `Enabled` denotes whether the service is enabled.
|
- `Enabled` denotes whether the service is enabled.
|
||||||
- `Address` is a service address to be running at. Warning: this field is deprecated,
|
|
||||||
please, use `Addresses` instead.
|
|
||||||
- `Port` is a service port to be bound to. Warning: this field is deprecated, please,
|
|
||||||
use `Addresses` instead.
|
|
||||||
- `Addresses` is a list of service addresses to be running at and listen to in
|
- `Addresses` is a list of service addresses to be running at and listen to in
|
||||||
the form of "host:port".
|
the form of "host:port".
|
||||||
|
|
||||||
|
@ -219,8 +212,6 @@ RPC:
|
||||||
```
|
```
|
||||||
where:
|
where:
|
||||||
- `Enabled` denotes whether an RPC server should be started.
|
- `Enabled` denotes whether an RPC server should be started.
|
||||||
- `Address` is an RPC server address to be running at. Warning: this field is
|
|
||||||
deprecated, please, use `Addresses` instead.
|
|
||||||
- `Addresses` is a list of RPC server addresses to be running at and listen to in
|
- `Addresses` is a list of RPC server addresses to be running at and listen to in
|
||||||
the form of "host:port".
|
the form of "host:port".
|
||||||
- `EnableCORSWorkaround` turns on a set of origin-related behaviors that make
|
- `EnableCORSWorkaround` turns on a set of origin-related behaviors that make
|
||||||
|
@ -248,8 +239,6 @@ where:
|
||||||
number (64 by default). Attempts to establish additional connections will
|
number (64 by default). Attempts to establish additional connections will
|
||||||
lead to websocket handshake failures. Use "-1" to disable websocket
|
lead to websocket handshake failures. Use "-1" to disable websocket
|
||||||
connections (0 will lead to using the default value).
|
connections (0 will lead to using the default value).
|
||||||
- `Port` is an RPC server port it should be bound to. Warning: this field is
|
|
||||||
deprecated, please, use `Addresses` instead.
|
|
||||||
- `SessionEnabled` denotes whether session-based iterator JSON-RPC API is enabled.
|
- `SessionEnabled` denotes whether session-based iterator JSON-RPC API is enabled.
|
||||||
If true, then all iterators got from `invoke*` calls will be stored as sessions
|
If true, then all iterators got from `invoke*` calls will be stored as sessions
|
||||||
on the server side available for further traverse. `traverseiterator` and
|
on the server side available for further traverse. `traverseiterator` and
|
||||||
|
|
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -14,10 +13,6 @@ import (
|
||||||
type ApplicationConfiguration struct {
|
type ApplicationConfiguration struct {
|
||||||
Ledger `yaml:",inline"`
|
Ledger `yaml:",inline"`
|
||||||
|
|
||||||
// Deprecated: please, use Addresses field of P2P section instead, this field will be removed in future versions.
|
|
||||||
Address *string `yaml:"Address,omitempty"`
|
|
||||||
// Deprecated: please, use Addresses field of P2P section instead, this field will be removed in future versions.
|
|
||||||
AnnouncedNodePort *uint16 `yaml:"AnnouncedPort,omitempty"`
|
|
||||||
// Deprecated: this option is moved to the P2P section.
|
// Deprecated: this option is moved to the P2P section.
|
||||||
AttemptConnPeers int `yaml:"AttemptConnPeers"`
|
AttemptConnPeers int `yaml:"AttemptConnPeers"`
|
||||||
// BroadcastFactor is the factor (0-100) controlling gossip fan-out number optimization.
|
// BroadcastFactor is the factor (0-100) controlling gossip fan-out number optimization.
|
||||||
|
@ -33,8 +28,6 @@ type ApplicationConfiguration struct {
|
||||||
MaxPeers int `yaml:"MaxPeers"`
|
MaxPeers int `yaml:"MaxPeers"`
|
||||||
// Deprecated: this option is moved to the P2P section.
|
// Deprecated: this option is moved to the P2P section.
|
||||||
MinPeers int `yaml:"MinPeers"`
|
MinPeers int `yaml:"MinPeers"`
|
||||||
// Deprecated: please, use Addresses field of P2P section instead, this field will be removed in future versions.
|
|
||||||
NodePort *uint16 `yaml:"NodePort,omitempty"`
|
|
||||||
P2P P2P `yaml:"P2P"`
|
P2P P2P `yaml:"P2P"`
|
||||||
// Deprecated: this option is moved to the P2P section.
|
// Deprecated: this option is moved to the P2P section.
|
||||||
PingInterval int64 `yaml:"PingInterval"`
|
PingInterval int64 `yaml:"PingInterval"`
|
||||||
|
@ -75,9 +68,7 @@ func (a *ApplicationConfiguration) EqualsButServices(o *ApplicationConfiguration
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if a.Address != o.Address || //nolint:staticcheck // SA1019: a.Address is deprecated
|
if a.AttemptConnPeers != o.AttemptConnPeers || //nolint:staticcheck // SA1019: a.AttemptConnPeers is deprecated
|
||||||
a.AnnouncedNodePort != o.AnnouncedNodePort || //nolint:staticcheck // SA1019: a.AnnouncedNodePort is deprecated
|
|
||||||
a.AttemptConnPeers != o.AttemptConnPeers || //nolint:staticcheck // SA1019: a.AttemptConnPeers is deprecated
|
|
||||||
a.P2P.AttemptConnPeers != o.P2P.AttemptConnPeers ||
|
a.P2P.AttemptConnPeers != o.P2P.AttemptConnPeers ||
|
||||||
a.BroadcastFactor != o.BroadcastFactor || //nolint:staticcheck // SA1019: a.BroadcastFactor is deprecated
|
a.BroadcastFactor != o.BroadcastFactor || //nolint:staticcheck // SA1019: a.BroadcastFactor is deprecated
|
||||||
a.P2P.BroadcastFactor != o.P2P.BroadcastFactor ||
|
a.P2P.BroadcastFactor != o.P2P.BroadcastFactor ||
|
||||||
|
@ -91,7 +82,6 @@ func (a *ApplicationConfiguration) EqualsButServices(o *ApplicationConfiguration
|
||||||
a.P2P.MaxPeers != o.P2P.MaxPeers ||
|
a.P2P.MaxPeers != o.P2P.MaxPeers ||
|
||||||
a.MinPeers != o.MinPeers || //nolint:staticcheck // SA1019: a.MinPeers is deprecated
|
a.MinPeers != o.MinPeers || //nolint:staticcheck // SA1019: a.MinPeers is deprecated
|
||||||
a.P2P.MinPeers != o.P2P.MinPeers ||
|
a.P2P.MinPeers != o.P2P.MinPeers ||
|
||||||
a.NodePort != o.NodePort || //nolint:staticcheck // SA1019: a.NodePort is deprecated
|
|
||||||
a.PingInterval != o.PingInterval || //nolint:staticcheck // SA1019: a.PingInterval is deprecated
|
a.PingInterval != o.PingInterval || //nolint:staticcheck // SA1019: a.PingInterval is deprecated
|
||||||
a.P2P.PingInterval != o.P2P.PingInterval ||
|
a.P2P.PingInterval != o.P2P.PingInterval ||
|
||||||
a.PingTimeout != o.PingTimeout || //nolint:staticcheck // SA1019: a.PingTimeout is deprecated
|
a.PingTimeout != o.PingTimeout || //nolint:staticcheck // SA1019: a.PingTimeout is deprecated
|
||||||
|
@ -112,27 +102,9 @@ type AnnounceableAddress struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddresses parses returns the list of AnnounceableAddress containing information
|
// GetAddresses parses returns the list of AnnounceableAddress containing information
|
||||||
// gathered from both deprecated Address / NodePort / AnnouncedNodePort and newly
|
// gathered from Addresses.
|
||||||
// created Addresses fields.
|
|
||||||
func (a *ApplicationConfiguration) GetAddresses() ([]AnnounceableAddress, error) {
|
func (a *ApplicationConfiguration) GetAddresses() ([]AnnounceableAddress, error) {
|
||||||
addrs := make([]AnnounceableAddress, 0, len(a.P2P.Addresses)+1)
|
addrs := make([]AnnounceableAddress, 0, len(a.P2P.Addresses))
|
||||||
if a.Address != nil || a.NodePort != nil || a.AnnouncedNodePort != nil { //nolint:staticcheck // SA1019: a.Address is deprecated
|
|
||||||
var (
|
|
||||||
host string
|
|
||||||
nodePort uint16
|
|
||||||
)
|
|
||||||
if a.Address != nil { //nolint:staticcheck // SA1019: a.Address is deprecated
|
|
||||||
host = *a.Address //nolint:staticcheck // SA1019: a.Address is deprecated
|
|
||||||
}
|
|
||||||
if a.NodePort != nil { //nolint:staticcheck // SA1019: a.NodePort is deprecated
|
|
||||||
nodePort = *a.NodePort //nolint:staticcheck // SA1019: a.NodePort is deprecated
|
|
||||||
}
|
|
||||||
addr := AnnounceableAddress{Address: net.JoinHostPort(host, strconv.Itoa(int(nodePort)))}
|
|
||||||
if a.AnnouncedNodePort != nil { //nolint:staticcheck // SA1019: a.AnnouncedNodePort is deprecated
|
|
||||||
addr.AnnouncedPort = *a.AnnouncedNodePort //nolint:staticcheck // SA1019: a.AnnouncedNodePort is deprecated
|
|
||||||
}
|
|
||||||
addrs = append(addrs, addr)
|
|
||||||
}
|
|
||||||
for i, addrStr := range a.P2P.Addresses {
|
for i, addrStr := range a.P2P.Addresses {
|
||||||
if len(addrStr) == 0 {
|
if len(addrStr) == 0 {
|
||||||
return nil, fmt.Errorf("address #%d is empty", i)
|
return nil, fmt.Errorf("address #%d is empty", i)
|
||||||
|
|
|
@ -29,7 +29,6 @@ func TestGetAddresses(t *testing.T) {
|
||||||
}
|
}
|
||||||
addr1 := "1.2.3.4"
|
addr1 := "1.2.3.4"
|
||||||
addr2 := "5.6.7.8"
|
addr2 := "5.6.7.8"
|
||||||
addr3 := "4.3.2.1"
|
|
||||||
v6Plain0 := "3731:54:65fe:2::a7"
|
v6Plain0 := "3731:54:65fe:2::a7"
|
||||||
v6Plain1 := "3731:54:65fe:2::1"
|
v6Plain1 := "3731:54:65fe:2::1"
|
||||||
v6Plain2 := "3731:54:65fe::a:1"
|
v6Plain2 := "3731:54:65fe::a:1"
|
||||||
|
@ -37,58 +36,7 @@ func TestGetAddresses(t *testing.T) {
|
||||||
v6Plain4 := "3731:54:65fe:2::"
|
v6Plain4 := "3731:54:65fe:2::"
|
||||||
port1 := uint16(1)
|
port1 := uint16(1)
|
||||||
port2 := uint16(2)
|
port2 := uint16(2)
|
||||||
port3 := uint16(3)
|
|
||||||
cases := []testcase{
|
cases := []testcase{
|
||||||
// Compatibility with the old behaviour.
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{},
|
|
||||||
expected: []AnnounceableAddress{{Address: ":0"}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{Address: &addr1},
|
|
||||||
expected: []AnnounceableAddress{{Address: addr1 + ":0"}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{NodePort: &port1},
|
|
||||||
expected: []AnnounceableAddress{{Address: ":1"}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{AnnouncedNodePort: &port1},
|
|
||||||
expected: []AnnounceableAddress{{Address: ":0", AnnouncedPort: port1}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{Address: &addr1, NodePort: &port1},
|
|
||||||
expected: []AnnounceableAddress{{Address: addr1 + ":1"}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{Address: &addr1, AnnouncedNodePort: &port1},
|
|
||||||
expected: []AnnounceableAddress{{Address: addr1 + ":0", AnnouncedPort: port1}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{NodePort: &port1, AnnouncedNodePort: &port2},
|
|
||||||
expected: []AnnounceableAddress{{Address: ":1", AnnouncedPort: port2}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{NodePort: &port1, AnnouncedNodePort: &port2},
|
|
||||||
expected: []AnnounceableAddress{{Address: ":1", AnnouncedPort: port2}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{Address: &addr1, NodePort: &port1, AnnouncedNodePort: &port2},
|
|
||||||
expected: []AnnounceableAddress{{Address: addr1 + ":1", AnnouncedPort: port2}},
|
|
||||||
},
|
|
||||||
// Compatibility with new multi-addresses.
|
|
||||||
{
|
|
||||||
cfg: &ApplicationConfiguration{
|
|
||||||
Address: &addr1, NodePort: &port1, AnnouncedNodePort: &port2,
|
|
||||||
P2P: P2P{Addresses: []string{addr1, addr2 + ":3", addr3 + ":1:3"}},
|
|
||||||
},
|
|
||||||
expected: []AnnounceableAddress{
|
|
||||||
{Address: addr1 + ":1", AnnouncedPort: port2},
|
|
||||||
{Address: addr1},
|
|
||||||
{Address: addr2 + ":3"},
|
|
||||||
{Address: addr3 + ":1", AnnouncedPort: port3},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Multi-addresses checks.
|
// Multi-addresses checks.
|
||||||
{
|
{
|
||||||
cfg: &ApplicationConfiguration{
|
cfg: &ApplicationConfiguration{
|
||||||
|
|
|
@ -1,38 +1,9 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BasicService is used as a simple base for node services like Pprof, RPC or
|
// BasicService is used as a simple base for node services like Pprof, RPC or
|
||||||
// Prometheus monitoring.
|
// Prometheus monitoring.
|
||||||
type BasicService struct {
|
type BasicService struct {
|
||||||
Enabled bool `yaml:"Enabled"`
|
Enabled bool `yaml:"Enabled"`
|
||||||
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
|
||||||
Address *string `yaml:"Address,omitempty"`
|
|
||||||
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
|
||||||
Port *string `yaml:"Port,omitempty"`
|
|
||||||
// Addresses holds the list of bind addresses in the form of "address:port".
|
// Addresses holds the list of bind addresses in the form of "address:port".
|
||||||
Addresses []string `yaml:"Addresses"`
|
Addresses []string `yaml:"Addresses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddresses returns the set of unique (in terms of raw strings) pairs host:port
|
|
||||||
// for the given basic service.
|
|
||||||
func (s BasicService) GetAddresses() []string {
|
|
||||||
addrs := make([]string, len(s.Addresses), len(s.Addresses)+1)
|
|
||||||
copy(addrs, s.Addresses)
|
|
||||||
if s.Address != nil || s.Port != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
||||||
var (
|
|
||||||
addr string
|
|
||||||
port string
|
|
||||||
)
|
|
||||||
if s.Address != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
||||||
addr = *s.Address //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
||||||
}
|
|
||||||
if s.Port != nil { //nolint:staticcheck // SA1019: s.Port is deprecated
|
|
||||||
port = *s.Port //nolint:staticcheck // SA1019: s.Port is deprecated
|
|
||||||
}
|
|
||||||
addrs = append(addrs, net.JoinHostPort(addr, port))
|
|
||||||
}
|
|
||||||
return addrs
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestBasicService_GetAddresses(t *testing.T) {
|
|
||||||
addr := "1.2.3.4"
|
|
||||||
port := "1234"
|
|
||||||
s := BasicService{
|
|
||||||
Enabled: false,
|
|
||||||
Address: &addr,
|
|
||||||
Port: &port,
|
|
||||||
Addresses: []string{"1.2.3.4:1234", /* same as Address:Port */
|
|
||||||
"3.4.5.6:1234", "2.3.4.5", ":1235", "2.3.4.5:1234",
|
|
||||||
"3.4.5.6:1234" /* already in list */},
|
|
||||||
}
|
|
||||||
require.Equal(t, []string{
|
|
||||||
"1.2.3.4:1234",
|
|
||||||
"3.4.5.6:1234",
|
|
||||||
"2.3.4.5",
|
|
||||||
":1235",
|
|
||||||
"2.3.4.5:1234",
|
|
||||||
"3.4.5.6:1234",
|
|
||||||
"1.2.3.4:1234",
|
|
||||||
}, s.GetAddresses())
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestRPC_UnmarshalBasicService is aimed to check that BasicService config of
|
|
||||||
// RPC service can be properly unmarshalled. This test may be removed after
|
|
||||||
// Address and Port config fields removal.
|
|
||||||
func TestRPC_UnmarshalBasicService(t *testing.T) {
|
|
||||||
data := `
|
|
||||||
Enabled: true
|
|
||||||
Port: 10332
|
|
||||||
MaxGasInvoke: 15
|
|
||||||
`
|
|
||||||
cfg := &RPC{}
|
|
||||||
err := yaml.Unmarshal([]byte(data), &cfg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.True(t, cfg.Enabled)
|
|
||||||
require.Equal(t, "10332", *cfg.Port)
|
|
||||||
}
|
|
|
@ -24,7 +24,7 @@ func NewPprofService(cfg config.BasicService, log *zap.Logger) *Service {
|
||||||
handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||||
handler.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
handler.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||||
|
|
||||||
addrs := cfg.GetAddresses()
|
addrs := cfg.Addresses
|
||||||
srvs := make([]*http.Server, len(addrs))
|
srvs := make([]*http.Server, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
srvs[i] = &http.Server{
|
srvs[i] = &http.Server{
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewPrometheusService(cfg config.BasicService, log *zap.Logger) *Service {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := cfg.GetAddresses()
|
addrs := cfg.Addresses
|
||||||
srvs := make([]*http.Server, len(addrs))
|
srvs := make([]*http.Server, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
srvs[i] = &http.Server{
|
srvs[i] = &http.Server{
|
||||||
|
|
|
@ -21,11 +21,7 @@ func TestLocalClient(t *testing.T) {
|
||||||
// No addresses configured -> RPC server listens nothing (but it
|
// No addresses configured -> RPC server listens nothing (but it
|
||||||
// has MaxGasInvoke, sessions and other stuff).
|
// has MaxGasInvoke, sessions and other stuff).
|
||||||
cfg.ApplicationConfiguration.RPC.BasicService.Enabled = true
|
cfg.ApplicationConfiguration.RPC.BasicService.Enabled = true
|
||||||
cfg.ApplicationConfiguration.RPC.BasicService.Address = nil //nolint:staticcheck // SA1019: cfg.ApplicationConfiguration.RPC.BasicService.Address is deprecated
|
|
||||||
cfg.ApplicationConfiguration.RPC.BasicService.Port = nil //nolint:staticcheck // SA1019: cfg.ApplicationConfiguration.RPC.BasicService.Port is deprecated
|
|
||||||
cfg.ApplicationConfiguration.RPC.BasicService.Addresses = nil
|
cfg.ApplicationConfiguration.RPC.BasicService.Addresses = nil
|
||||||
cfg.ApplicationConfiguration.RPC.TLSConfig.Address = nil //nolint:staticcheck // SA1019: cfg.ApplicationConfiguration.RPC.TLSConfig.Address is deprecated
|
|
||||||
cfg.ApplicationConfiguration.RPC.TLSConfig.Port = nil //nolint:staticcheck // SA1019: cfg.ApplicationConfiguration.RPC.TLSConfig.Port is deprecated
|
|
||||||
cfg.ApplicationConfiguration.RPC.TLSConfig.Addresses = nil
|
cfg.ApplicationConfiguration.RPC.TLSConfig.Addresses = nil
|
||||||
})
|
})
|
||||||
// RPC server listens nothing (not exposed in any way), but it works for internal clients.
|
// RPC server listens nothing (not exposed in any way), but it works for internal clients.
|
||||||
|
|
|
@ -267,7 +267,7 @@ var rpcWsHandlers = map[string]func(*Server, params.Params, *subscriber) (any, *
|
||||||
// untyped nil or non-nil structure implementing OracleHandler interface.
|
// untyped nil or non-nil structure implementing OracleHandler interface.
|
||||||
func New(chain Ledger, conf config.RPC, coreServer *network.Server,
|
func New(chain Ledger, conf config.RPC, coreServer *network.Server,
|
||||||
orc OracleHandler, log *zap.Logger, errChan chan<- error) Server {
|
orc OracleHandler, log *zap.Logger, errChan chan<- error) Server {
|
||||||
addrs := conf.GetAddresses()
|
addrs := conf.Addresses
|
||||||
httpServers := make([]*http.Server, len(addrs))
|
httpServers := make([]*http.Server, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
httpServers[i] = &http.Server{
|
httpServers[i] = &http.Server{
|
||||||
|
@ -277,7 +277,7 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server,
|
||||||
|
|
||||||
var tlsServers []*http.Server
|
var tlsServers []*http.Server
|
||||||
if cfg := conf.TLSConfig; cfg.Enabled {
|
if cfg := conf.TLSConfig; cfg.Enabled {
|
||||||
addrs := cfg.GetAddresses()
|
addrs := cfg.Addresses
|
||||||
tlsServers = make([]*http.Server, len(addrs))
|
tlsServers = make([]*http.Server, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
tlsServers[i] = &http.Server{
|
tlsServers[i] = &http.Server{
|
||||||
|
|
Loading…
Reference in a new issue