Fix setting of bootstrap nodes (#744)

Fix dropped bootstrap nodes setting and rename of cluster config and separation of nodes
This commit is contained in:
Frank Mueller 2018-03-20 15:05:21 +01:00 committed by Dmitry Shulyak
parent 804fe949f7
commit dc4a0a98ed
8 changed files with 111 additions and 103 deletions

View File

@ -4,10 +4,6 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"bignumber.js": {
"version": "github:status-im/bignumber.js#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"dev": true
},
"crypto-js": {
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
@ -35,6 +31,12 @@
"utf8": "2.1.2",
"xhr2": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"xmlhttprequest": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz"
},
"dependencies": {
"bignumber.js": {
"version": "github:status-im/bignumber.js#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"dev": true
}
}
},
"xhr2": {

View File

@ -221,17 +221,16 @@ func makeNodeConfig() (*params.NodeConfig, error) {
nodeConfig.SwarmConfig.Enabled = *swarmEnabled
if *standalone {
nodeConfig.BootClusterConfig.Enabled = false
nodeConfig.BootClusterConfig.BootNodes = nil
nodeConfig.ClusterConfig.Enabled = false
nodeConfig.ClusterConfig.BootNodes = nil
}
nodeConfig.Discovery = *discovery
// Even if standalone is true and discovery is disabled,
// it's possible to use bootnodes in NodeManager.PopulateStaticPeers().
// TODO(adam): research if we need NodeManager.PopulateStaticPeers() at all.
// it's possible to use bootnodes.
if *bootnodes != "" {
nodeConfig.BootClusterConfig.BootNodes = strings.Split(*bootnodes, ",")
nodeConfig.ClusterConfig.BootNodes = strings.Split(*bootnodes, ",")
}
if *whisperEnabled {

View File

@ -177,39 +177,39 @@ func (m *NodeManager) populateStaticPeers() error {
if err := m.isNodeAvailable(); err != nil {
return err
}
if !m.config.BootClusterConfig.Enabled {
log.Info("Boot cluster is disabled")
if !m.config.ClusterConfig.Enabled {
log.Info("Static peers are disabled")
return nil
}
for _, enode := range m.config.BootClusterConfig.BootNodes {
for _, enode := range m.config.ClusterConfig.StaticNodes {
err := m.addPeer(enode)
if err != nil {
log.Warn("Boot node addition failed", "error", err)
log.Warn("Static peer addition failed", "error", err)
continue
}
log.Info("Boot node added", "enode", enode)
log.Info("Static peer added", "enode", enode)
}
return nil
}
func (m *NodeManager) removeStaticPeers() error {
if !m.config.BootClusterConfig.Enabled {
log.Info("static peers are disabled")
if !m.config.ClusterConfig.Enabled {
log.Info("Static peers are disabled")
return nil
}
server := m.node.Server()
if server == nil {
return ErrNoRunningNode
}
for _, enode := range m.config.BootClusterConfig.BootNodes {
for _, enode := range m.config.ClusterConfig.StaticNodes {
err := m.removePeer(enode)
if err != nil {
log.Warn("static peer deletion failed", "error", err)
log.Warn("Static peer deletion failed", "error", err)
return err
}
log.Info("static peer deleted", "enode", enode)
log.Info("Static peer deleted", "enode", enode)
}
return nil
}

View File

@ -115,8 +115,11 @@ func defaultEmbeddedNodeConfig(config *params.NodeConfig) *node.Config {
nc.HTTPPort = config.HTTPPort
}
if config.BootClusterConfig.Enabled {
nc.P2P.StaticNodes = makeBootstrapNodes(config.BootClusterConfig.BootNodes)
if config.ClusterConfig.Enabled {
// TODO(themue) Should static nodes always be set? Had been done via
// PopulateStaticPeers() before.
nc.P2P.StaticNodes = parseNodes(config.ClusterConfig.StaticNodes)
nc.P2P.BootstrapNodes = parseNodes(config.ClusterConfig.BootNodes)
}
return nc
@ -216,12 +219,11 @@ func makeWSHost(config *params.NodeConfig) string {
return config.WSHost
}
// makeBootstrapNodes returns default (hence bootstrap) list of peers
func makeBootstrapNodes(enodes []string) []*discover.Node {
var bootstrapNodes []*discover.Node
for _, enode := range enodes {
bootstrapNodes = append(bootstrapNodes, discover.MustParseNode(enode))
// parseNodes creates list of discover.Node out of enode strings.
func parseNodes(enodes []string) []*discover.Node {
nodes := make([]*discover.Node, len(enodes))
for i, enode := range enodes {
nodes[i] = discover.MustParseNode(enode)
}
return bootstrapNodes
return nodes
}

View File

@ -155,23 +155,26 @@ func (c *SwarmConfig) String() string {
}
// ----------
// BootClusterConfig
// ClusterConfig
// ----------
// BootClusterConfig holds configuration for supporting cluster peers, which is a temporary
// ClusterConfig holds configuration for supporting cluster peers, which is a temporary
// means for mobile devices to get connected to Ethereum network (UDP-based discovery
// may not be available, so we need means to discover the network manually).
type BootClusterConfig struct {
type ClusterConfig struct {
// Enabled flag specifies whether feature is enabled
Enabled bool
// StaticNodes lists the static nodes taken from compiled or passed cluster.json
StaticNodes []string
// BootNodes list of cluster peer nodes for a given network (Ropsten, Rinkeby, Homestead),
// for a given mode (production vs development)
BootNodes []string
}
// String dumps config object as nicely indented JSON
func (c *BootClusterConfig) String() string {
func (c *ClusterConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
return string(data)
}
@ -284,8 +287,8 @@ type NodeConfig struct {
// empty the statical configuration data will be taken.
ClusterConfigFile string `json:"ClusterConfigFile"`
// BootClusterConfig extra configuration for supporting cluster peers.
BootClusterConfig *BootClusterConfig `json:"BootClusterConfig," validate:"structonly"`
// ClusterConfig extra configuration for supporting cluster peers.
ClusterConfig *ClusterConfig `json:"ClusterConfig," validate:"structonly"`
// LightEthConfig extra configuration for LES
LightEthConfig *LightEthConfig `json:"LightEthConfig," validate:"structonly"`
@ -319,8 +322,9 @@ func NewNodeConfig(dataDir string, clstrCfgFile string, networkID uint64, devMod
LogLevel: LogLevel,
LogToStderr: LogToStderr,
ClusterConfigFile: clstrCfgFile,
BootClusterConfig: &BootClusterConfig{
ClusterConfig: &ClusterConfig{
Enabled: true,
StaticNodes: []string{},
BootNodes: []string{},
},
LightEthConfig: &LightEthConfig{
@ -403,8 +407,8 @@ func (c *NodeConfig) Validate() error {
return err
}
if c.BootClusterConfig.Enabled {
if err := validate.Struct(c.BootClusterConfig); err != nil {
if c.ClusterConfig.Enabled {
if err := validate.Struct(c.ClusterConfig); err != nil {
return err
}
}
@ -544,7 +548,7 @@ func (c *NodeConfig) updateUpstreamConfig() error {
// This is necessary until we have LES protocol support CHT sync, and better node
// discovery on mobile devices)
func (c *NodeConfig) updateClusterConfig() error {
if !c.BootClusterConfig.Enabled {
if !c.ClusterConfig.Enabled {
return nil
}
@ -555,7 +559,7 @@ func (c *NodeConfig) updateClusterConfig() error {
type subClusterData struct {
Number int `json:"number"`
Hash string `json:"hash"`
BootNodes []string `json:"bootnodes"`
StaticNodes []string `json:"staticnodes"`
}
type clusterData struct {
NetworkID int `json:"networkID"`
@ -588,9 +592,9 @@ func (c *NodeConfig) updateClusterConfig() error {
for _, cluster := range clusters {
if cluster.NetworkID == int(c.NetworkID) {
c.BootClusterConfig.BootNodes = cluster.Prod.BootNodes
c.ClusterConfig.StaticNodes = cluster.Prod.StaticNodes
if c.DevMode {
c.BootClusterConfig.BootNodes = cluster.Dev.BootNodes
c.ClusterConfig.StaticNodes = cluster.Dev.StaticNodes
}
break
}

View File

@ -21,13 +21,13 @@ var clusterConfigData = []byte(`[
{
"networkID": 3,
"prod": {
"bootnodes": [
"staticnodes": [
"enode://7ab298cedc4185a894d21d8a4615262ec6bdce66c9b6783878258e0d5b31013d30c9038932432f70e5b2b6a5cd323bf820554fcb22fbc7b45367889522e9c449@10.1.1.1:30303",
"enode://f59e8701f18c79c5cbc7618dc7bb928d44dc2f5405c7d693dad97da2d8585975942ec6fd36d3fe608bfdc7270a34a4dd00f38cfe96b2baa24f7cd0ac28d382a1@10.1.1.2:30303"
]
},
"dev": {
"bootnodes": [
"staticnodes": [
"enode://7ab298cedc4185a894d21d8a4615262ec6bdce66c9b6783878258e0d5b31013d30c9038932432f70e5b2b6a5cd323bf820554fcb22fbc7b45367889522e9c449@10.1.1.1:30303",
"enode://f59e8701f18c79c5cbc7618dc7bb928d44dc2f5405c7d693dad97da2d8585975942ec6fd36d3fe608bfdc7270a34a4dd00f38cfe96b2baa24f7cd0ac28d382a1@10.1.1.2:30303"
]
@ -233,21 +233,22 @@ var loadConfigTestCases = []struct {
},
},
{
`default boot nodes (Ropsten Dev)`,
`default static nodes (Ropsten Dev)`,
`{
"NetworkId": 3,
"DataDir": "$TMPDIR"
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot nodes are expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "static nodes are expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
t.Logf("LEN SN %d", len(enodes))
require.Len(t, enodes, 2)
},
},
{
`illegal cluster config file`,
`illegal cluster configuration file`,
`{
"NetworkId": 3,
"DataDir": "$TMPDIR",
@ -258,7 +259,7 @@ var loadConfigTestCases = []struct {
},
},
{
`valid cluster config file`,
`valid cluster configuration file`,
`{
"NetworkId": 3,
"DataDir": "$TMPDIR",
@ -266,14 +267,14 @@ var loadConfigTestCases = []struct {
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled after loading file")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be enabled after loading file")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.True(t, len(enodes) == 2)
},
},
{
`default boot cluster (Ropsten Prod)`,
`default cluster configuration (Ropsten Prod)`,
`{
"NetworkId": 3,
"DataDir": "$TMPDIR",
@ -281,42 +282,42 @@ var loadConfigTestCases = []struct {
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.Len(t, enodes, 2)
},
},
{
`disabled boot cluster`,
`disabled cluster configuration`,
`{
"NetworkId": 311,
"DataDir": "$TMPDIR",
"BootClusterConfig": {
"ClusterConfig": {
"Enabled": false
}
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.False(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be disabled")
require.False(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be disabled")
},
},
{
`select boot cluster (Rinkeby Dev)`,
`select cluster configuration (Rinkeby Dev)`,
`{
"NetworkId": 4,
"DataDir": "$TMPDIR"
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.True(t, len(enodes) >= 3)
},
},
{
`select boot cluster (Rinkeby Prod)`,
`select cluster configuration (Rinkeby Prod)`,
`{
"NetworkId": 4,
"DataDir": "$TMPDIR",
@ -324,28 +325,28 @@ var loadConfigTestCases = []struct {
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.True(t, len(enodes) >= 3)
},
},
{
`select boot cluster (Mainnet dev)`,
`select cluster configuration (Mainnet dev)`,
`{
"NetworkId": 1,
"DataDir": "$TMPDIR"
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster configuration is expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.True(t, len(enodes) >= 2)
},
},
{
`select boot cluster (Mainnet Prod)`,
`select cluster configuration (Mainnet Prod)`,
`{
"NetworkId": 1,
"DataDir": "$TMPDIR",
@ -353,9 +354,9 @@ var loadConfigTestCases = []struct {
}`,
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.BootClusterConfig.Enabled, "boot cluster is expected to be enabled by default")
require.True(t, nodeConfig.ClusterConfig.Enabled, "cluster confguration is expected to be enabled by default")
enodes := nodeConfig.BootClusterConfig.BootNodes
enodes := nodeConfig.ClusterConfig.StaticNodes
require.True(t, len(enodes) >= 2)
},
},
@ -368,7 +369,7 @@ var loadConfigTestCases = []struct {
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.True(t, nodeConfig.DevMode)
require.True(t, nodeConfig.BootClusterConfig.Enabled)
require.True(t, nodeConfig.ClusterConfig.Enabled)
},
},
{
@ -381,7 +382,7 @@ var loadConfigTestCases = []struct {
func(t *testing.T, dataDir string, nodeConfig *params.NodeConfig, err error) {
require.NoError(t, err)
require.False(t, nodeConfig.DevMode)
require.True(t, nodeConfig.BootClusterConfig.Enabled)
require.True(t, nodeConfig.ClusterConfig.Enabled)
},
},
{

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,13 @@
{
"networkID": 3,
"prod": {
"bootnodes": [
"staticnodes": [
"enode://dffef3874011709b12d1e540d83ddb19a9db8614ad9151d05bcf813585e45cbebba5aaea223fe315786c401d8cecb1ad2de9f179680c536ea30311fb21fa934b@188.166.100.178:30303",
"enode://03f3661686d30509d621dbe5ee2e3082923f25e94fd41a2dd8dd34bb12a0c4e8fbde52247c6c55e86dc209a8e7c4a5ae56058c65f7b01734d3ab73818b44e2a3@188.166.33.47:30303"
]
},
"dev": {
"bootnodes": [
"staticnodes": [
"enode://dffef3874011709b12d1e540d83ddb19a9db8614ad9151d05bcf813585e45cbebba5aaea223fe315786c401d8cecb1ad2de9f179680c536ea30311fb21fa934b@188.166.100.178:30303",
"enode://03f3661686d30509d621dbe5ee2e3082923f25e94fd41a2dd8dd34bb12a0c4e8fbde52247c6c55e86dc209a8e7c4a5ae56058c65f7b01734d3ab73818b44e2a3@188.166.33.47:30303"
]
@ -17,14 +17,14 @@
{
"networkID": 4,
"prod": {
"bootnodes": [
"staticnodes": [
"enode://fda3f6273a0f2da4ac5858d1f52e5afaf9def281121be3d37558c67d4d9ca26c6ad7a0520b2cd7454120fb770e86d5760487c9924b2166e65485f606e56d60fc@51.15.69.144:30303",
"enode://ba41aa829287a0a9076d9bffed97c8ce2e491b99873288c9e886f16fd575306ac6c656db4fbf814f5a9021aec004ffa9c0ae8650f92fd10c12eeb7c364593eb3@51.15.69.147:30303",
"enode://28ecf5272b560ca951f4cd7f1eb8bd62da5853b026b46db432c4b01797f5b0114819a090a72acd7f32685365ecd8e00450074fa0673039aefe10f3fb666e0f3f@51.15.76.249:30303"
]
},
"dev": {
"bootnodes": [
"staticnodes": [
"enode://7512c8f6e7ffdcc723cf77e602a1de9d8cc2e8ad35db309464819122cd773857131aee390fec33894db13da730c8432bb248eed64039e3810e156e979b2847cb@51.15.78.243:30303",
"enode://1cc27a5a41130a5c8b90db5b2273dc28f7b56f3edfc0dcc57b665d451274b26541e8de49ea7a074281906a82209b9600239c981163b6ff85c3038a8e2bc5d8b8@51.15.68.93:30303",
"enode://798d17064141b8f88df718028a8272b943d1cb8e696b3dab56519c70b77b1d3469b56b6f4ce3788457646808f5c7299e9116626f2281f30b959527b969a71e4f@51.15.75.244:30303"
@ -34,7 +34,7 @@
{
"networkID": 1,
"prod": {
"bootnodes": [
"staticnodes": [
"enode://71bb01b58165e3262aea2d3b06dbf9abb8d5512d96e5000e7e41ab2138b47be685935d3eb119fc25e1413db00d8db231fd9d59555a1cd75229821559b6a4eb51@51.15.85.243:30303",
"enode://7afd119c549a7ab02b3f7bd77ef3490b6d660d5c49d0734a0c8bb23195ced4ace0bf5cde673cd5cfd07dd8d759277f3d8408eb73dc3c217bbe00f0027d06eee9@51.15.85.243:30305",
"enode://da8af0869e4e8047f21c1ac016b94a7b7d8e935dddd28d4272f88a1ceaee7c15e7deec9b6fd195ed3bc43748893111ebf2b2479ff44a8025ab8d598f3c97b589@51.15.85.243:30307",
@ -45,7 +45,7 @@
]
},
"dev": {
"bootnodes": [
"staticnodes": [
"enode://71bb01b58165e3262aea2d3b06dbf9abb8d5512d96e5000e7e41ab2138b47be685935d3eb119fc25e1413db00d8db231fd9d59555a1cd75229821559b6a4eb51@51.15.85.243:30303",
"enode://7afd119c549a7ab02b3f7bd77ef3490b6d660d5c49d0734a0c8bb23195ced4ace0bf5cde673cd5cfd07dd8d759277f3d8408eb73dc3c217bbe00f0027d06eee9@51.15.85.243:30305",
"enode://da8af0869e4e8047f21c1ac016b94a7b7d8e935dddd28d4272f88a1ceaee7c15e7deec9b6fd195ed3bc43748893111ebf2b2479ff44a8025ab8d598f3c97b589@51.15.85.243:30307",