Configure eth.staging fleet (#1111)

Provide a way to run a status node with a different fleet.
This commit is contained in:
Adam Babik 2018-07-25 16:03:35 +02:00 committed by GitHub
parent eeca435064
commit 408ba5a7e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 91 additions and 33 deletions

View File

@ -68,7 +68,7 @@ func TestStatusFlag(t *testing.T) {
for i, s := range scenarios {
msg := fmt.Sprintf("scenario %d", i)
c, err := params.NewNodeConfig("", "", 0)
c, err := params.NewNodeConfig("", "", params.FleetBeta, 0)
require.Nil(t, err, msg)
c.IPCEnabled = s.ipcEnabled

View File

@ -62,6 +62,7 @@ var (
version = flag.Bool("version", false, "Print version")
listenAddr = flag.String("listenaddr", ":30303", "IP address and port of this node (e.g. 127.0.0.1:30303)")
fleet = flag.String("fleet", params.FleetBeta, "Name of the fleet like 'eth.staging' (default to 'eth.beta')")
standalone = flag.Bool("standalone", true, "Don't actively connect to peers, wait for incoming connections")
bootnodes = flag.String("bootnodes", "", "A list of bootnodes separated by comma")
discoveryFlag = flag.Bool("discovery", false, "Enable discovery protocol")
@ -94,7 +95,7 @@ var (
// All general log messages in this package should be routed through this logger.
var logger = log.New("package", "status-go/cmd/statusd")
func main() {
func init() {
flag.Var(&searchTopics, "topic.search", "Topic that will be searched in discovery v5, e.g (mailserver=1,1)")
flag.Var(&registerTopics, "topic.register", "Topic that will be registered using discovery v5.")
flag.Var(&rendezvousNodes, "rendezvous-node", "Rendezvous server.")
@ -106,6 +107,13 @@ func main() {
printUsage()
os.Exit(1)
}
}
func main() {
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
if err := logutils.OverrideRootLog(logEnabled(), *logLevel, *logFile, colors); err != nil {
stdlog.Fatalf("Error initializing logger: %s", err)
}
config, err := makeNodeConfig()
if err != nil {
@ -119,15 +127,6 @@ func main() {
return
}
colors := !(*logWithoutColors)
if colors {
colors = terminal.IsTerminal(int(os.Stdin.Fd()))
}
if err := logutils.OverrideRootLog(config.LogEnabled, config.LogLevel, config.LogFile, colors); err != nil {
stdlog.Fatalf("Error initializing logger: %s", err)
}
backend := api.NewStatusBackend()
err = backend.StartNode(config)
if err != nil {
@ -206,9 +205,13 @@ func startCollectingNodeMetrics(interruptCh <-chan struct{}, statusNode *node.St
<-interruptCh
}
func logEnabled() bool {
return *logLevel != "" || *logFile != ""
}
// makeNodeConfig parses incoming CLI options and returns node configuration object
func makeNodeConfig() (*params.NodeConfig, error) {
nodeConfig, err := params.NewNodeConfig(*dataDir, *clusterConfigFile, uint64(*networkID))
nodeConfig, err := params.NewNodeConfig(*dataDir, *clusterConfigFile, *fleet, uint64(*networkID))
if err != nil {
return nil, err
}
@ -228,9 +231,7 @@ func makeNodeConfig() (*params.NodeConfig, error) {
nodeConfig.LogFile = *logFile
}
if *logLevel != "" || *logFile != "" {
nodeConfig.LogEnabled = true
}
nodeConfig.LogEnabled = logEnabled()
nodeConfig.RPCEnabled = *httpEnabled
nodeConfig.WhisperConfig.Enabled = *whisperEnabled
@ -260,8 +261,6 @@ func makeNodeConfig() (*params.NodeConfig, error) {
nodeConfig.RequireTopics = map[discv5.Topic]params.Limits(searchTopics)
nodeConfig.RegisterTopics = []discv5.Topic(registerTopics)
nodeConfig.WhisperConfig.EnableNTPSync = *ntpSyncEnabled
// Even if standalone is true and discovery is disabled,
// it's possible to use bootnodes.
if *bootnodes != "" {

View File

@ -12,11 +12,13 @@ import (
// whisperConfig creates node configuration object from flags
func whisperConfig(nodeConfig *params.NodeConfig) (*params.NodeConfig, error) {
whisperConfig := nodeConfig.WhisperConfig
whisperConfig.Enabled = true
whisperConfig.EnableMailServer = *enableMailServer
whisperConfig.LightClient = *lightClient
whisperConfig.MinimumPoW = *minPow
whisperConfig.TTL = *ttl
whisperConfig.EnableNTPSync = *ntpSyncEnabled
if whisperConfig.EnableMailServer {
if *passwordFile == "" {

View File

@ -24,7 +24,7 @@ var logger = log.New("package", "status-go/lib")
//GenerateConfig for status node
//export GenerateConfig
func GenerateConfig(datadir *C.char, networkID C.int) *C.char {
config, err := params.NewNodeConfig(C.GoString(datadir), "", uint64(networkID))
config, err := params.NewNodeConfig(C.GoString(datadir), "", params.FleetBeta, uint64(networkID))
if err != nil {
return makeJSONResponse(err)
}

View File

@ -1,5 +1,13 @@
package params
import "errors"
// Define available fleets.
const (
FleetBeta = "eth.beta"
FleetStaging = "eth.staging"
)
type cluster struct {
NetworkID int `json:"networkID"`
StaticNodes []string `json:"staticnodes"`
@ -7,7 +15,7 @@ type cluster struct {
}
var ropstenCluster = cluster{
NetworkID: 3,
NetworkID: RopstenNetworkID,
BootNodes: []string{
"enode://436cc6f674928fdc9a9f7990f2944002b685d1c37f025c1be425185b5b1f0900feaf1ccc2a6130268f9901be4a7d252f37302c8335a2c1a62736e9232691cc3a@174.138.105.243:30404", // boot-01.do-ams3.eth.beta
"enode://5395aab7833f1ecb671b59bf0521cf20224fe8162fc3d2675de4ee4d5636a75ec32d13268fc184df8d1ddfa803943906882da62a4df42d4fccf6d17808156a87@206.189.243.57:30404", // boot-02.do-ams3.eth.beta
@ -21,7 +29,7 @@ var ropstenCluster = cluster{
}
var rinkebyCluster = cluster{
NetworkID: 4,
NetworkID: RinkebyNetworkID,
BootNodes: []string{
"enode://1b843c7697f6fc42a1f606fb3cfaac54e025f06789dc20ad9278be3388967cf21e3a1b1e4be51faecd66c2c3adef12e942b4fcdeb8727657abe60636efb6224f@206.189.6.46:30404",
"enode://b29100c8468e3e6604817174a15e4d71627458b0dcdbeea169ab2eb4ab2bbc6f24adbb175826726cec69db8fdba6c0dd60b3da598e530ede562180d300728659@206.189.6.48:30404",
@ -35,7 +43,7 @@ var rinkebyCluster = cluster{
}
var mainnetCluster = cluster{
NetworkID: 1,
NetworkID: MainNetworkID,
BootNodes: []string{
"enode://436cc6f674928fdc9a9f7990f2944002b685d1c37f025c1be425185b5b1f0900feaf1ccc2a6130268f9901be4a7d252f37302c8335a2c1a62736e9232691cc3a@174.138.105.243:30404", // boot-01.do-ams3.eth.beta
"enode://5395aab7833f1ecb671b59bf0521cf20224fe8162fc3d2675de4ee4d5636a75ec32d13268fc184df8d1ddfa803943906882da62a4df42d4fccf6d17808156a87@206.189.243.57:30404", // boot-02.do-ams3.eth.beta
@ -48,4 +56,33 @@ var mainnetCluster = cluster{
},
}
var defaultClusters = []cluster{ropstenCluster, rinkebyCluster, mainnetCluster}
var betaCluster = []cluster{ropstenCluster, rinkebyCluster, mainnetCluster}
var stagingCluster = []cluster{
{
NetworkID: MainNetworkID,
BootNodes: []string{
"enode://10a78c17929a7019ef4aa2249d7302f76ae8a06f40b2dc88b7b31ebff4a623fbb44b4a627acba296c1ced3775d91fbe18463c15097a6a36fdb2c804ff3fc5b35@35.238.97.234:30404", // boot-01.gc-us-central1-a.eth.staging
"enode://f79fb3919f72ca560ad0434dcc387abfe41e0666201ebdada8ede0462454a13deb05cda15f287d2c4bd85da81f0eb25d0a486bbbc8df427b971ac51533bd00fe@174.138.107.239:30404", // boot-01.do-ams3.eth.staging
},
},
{
NetworkID: RopstenNetworkID,
BootNodes: []string{
"enode://10a78c17929a7019ef4aa2249d7302f76ae8a06f40b2dc88b7b31ebff4a623fbb44b4a627acba296c1ced3775d91fbe18463c15097a6a36fdb2c804ff3fc5b35@35.238.97.234:30404", // boot-01.gc-us-central1-a.eth.staging
"enode://f79fb3919f72ca560ad0434dcc387abfe41e0666201ebdada8ede0462454a13deb05cda15f287d2c4bd85da81f0eb25d0a486bbbc8df427b971ac51533bd00fe@174.138.107.239:30404", // boot-01.do-ams3.eth.staging
},
},
}
// clusterForFleet returns a cluster for a given fleet.
func clusterForFleet(fleet string) ([]cluster, error) {
switch fleet {
case FleetStaging:
return stagingCluster, nil
case FleetBeta:
return betaCluster, nil
default:
return nil, errors.New("fleet could not be found")
}
}

View File

@ -190,6 +190,9 @@ type ClusterConfig struct {
// Enabled flag specifies whether feature is enabled
Enabled bool
// Fleet is a type of selected fleet.
Fleet string
// StaticNodes lists the static nodes taken from compiled or passed cluster.json
StaticNodes []string
@ -350,7 +353,7 @@ type NodeConfig struct {
}
// NewNodeConfig creates new node configuration object
func NewNodeConfig(dataDir string, clstrCfgFile string, networkID uint64) (*NodeConfig, error) {
func NewNodeConfig(dataDir, clstrCfgFile, fleet string, networkID uint64) (*NodeConfig, error) {
nodeConfig := &NodeConfig{
NetworkID: networkID,
DataDir: dataDir,
@ -371,6 +374,7 @@ func NewNodeConfig(dataDir string, clstrCfgFile string, networkID uint64) (*Node
ClusterConfigFile: clstrCfgFile,
ClusterConfig: &ClusterConfig{
Enabled: true,
Fleet: fleet,
StaticNodes: []string{},
BootNodes: []string{},
},
@ -415,7 +419,7 @@ func LoadNodeConfig(configJSON string) (*NodeConfig, error) {
}
func loadNodeConfig(configJSON string) (*NodeConfig, error) {
nodeConfig, err := NewNodeConfig("", "", 0)
nodeConfig, err := NewNodeConfig("", "", FleetBeta, 0)
if err != nil {
return nil, err
}
@ -598,7 +602,16 @@ func (c *NodeConfig) updateClusterConfig() error {
return nil
}
var clusters []cluster
c.log.Debug(
"update cluster config",
"configFile", c.ClusterConfigFile,
"fleet", c.ClusterConfig.Fleet)
var (
clusters []cluster
err error
)
if c.ClusterConfigFile != "" {
// Load cluster configuration from external file.
configFile, err := ioutil.ReadFile(c.ClusterConfigFile)
@ -610,15 +623,22 @@ func (c *NodeConfig) updateClusterConfig() error {
return fmt.Errorf("failed to unmarshal cluster configuration file: %s", err)
}
} else {
clusters = defaultClusters
clusters, err = clusterForFleet(c.ClusterConfig.Fleet)
if err != nil {
return fmt.Errorf("getting fleet '%s' failed: %v", c.ClusterConfig.Fleet, err)
}
}
for _, cluster := range clusters {
if cluster.NetworkID == int(c.NetworkID) {
// allow to override bootnodes only if they were not defined earlier
if len(c.ClusterConfig.BootNodes) == 0 {
c.ClusterConfig.BootNodes = cluster.BootNodes
}
// allow to override static nodes only if they were not defined earlier
if len(c.ClusterConfig.StaticNodes) == 0 {
c.ClusterConfig.StaticNodes = cluster.StaticNodes
}
// no point in running discovery if we don't have bootnodes.
// but in case if we do have nodes and NoDiscovery=true we will preserve that value
if len(cluster.BootNodes) == 0 {

View File

@ -407,7 +407,7 @@ func TestConfigWriteRead(t *testing.T) {
require.Nil(t, err)
defer os.RemoveAll(tmpDir) // nolint: errcheck
nodeConfig, err := params.NewNodeConfig(tmpDir, "", params.RopstenNetworkID)
nodeConfig, err := params.NewNodeConfig(tmpDir, "", params.FleetBeta, params.RopstenNetworkID)
require.Nil(t, err, "cannot create new config object")
err = nodeConfig.Save()

View File

@ -143,11 +143,11 @@ func (s *DebugAPISuite) addPeerToCurrentNode(dir string) {
// newNode creates, configures and starts a new peer.
func (s *DebugAPISuite) newPeer(name, dir string) *node.StatusNode {
// network id is irrelevant
cfg, err := params.NewNodeConfig(dir, "", 777)
cfg, err := params.NewNodeConfig(dir, "", params.FleetBeta, 777)
s.Require().NoError(err)
cfg.LightEthConfig.Enabled = false
cfg.Name = name
cfg.NetworkID = uint64(GetNetworkID())
s.Require().NoError(err)
n := node.New()
s.Require().NoError(n.Start(cfg))

View File

@ -32,10 +32,10 @@ func (s *WhisperExtensionSuite) SetupTest() {
dir, err := ioutil.TempDir("", "test-shhext-")
s.NoError(err)
// network id is irrelevant
cfg, err := params.NewNodeConfig(dir, "", 777)
cfg, err := params.NewNodeConfig(dir, "", params.FleetBeta, 777)
s.Require().NoError(err)
cfg.LightEthConfig.Enabled = false
cfg.Name = fmt.Sprintf("test-shhext-%d", i)
s.Require().NoError(err)
s.nodes[i] = node.New()
s.Require().NoError(s.nodes[i].Start(cfg))
}

View File

@ -59,7 +59,7 @@ func (s *TxQueueTestSuite) SetupTest() {
rpcClient, _ := rpc.NewClient(s.client, params.UpstreamRPCConfig{})
// expected by simulated backend
chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64()
nodeConfig, err := params.NewNodeConfig("/tmp", "", chainID)
nodeConfig, err := params.NewNodeConfig("/tmp", "", params.FleetBeta, chainID)
s.Require().NoError(err)
s.nodeConfig = nodeConfig