From 162dbea99a7f66dd014bedad6dc315a656a04d48 Mon Sep 17 00:00:00 2001 From: ak Date: Mon, 1 Apr 2019 14:39:44 -0700 Subject: [PATCH] Seperate the notion of shardId zero from a beacon node --- cmd/harmony/main.go | 1 + internal/configs/node/config.go | 8 +++++++- internal/configs/node/config_test.go | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 72a31bed7..18164808c 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -218,6 +218,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen if *isGenesis { // TODO: need change config file and use switch instead of complicated "if else" condition if nodeConfig.ShardID == 0 { // Beacon chain + nodeConfig.SetIsBeacon(true) if nodeConfig.StringRole == "leader" { currentNode.NodeConfig.SetRole(nodeconfig.BeaconLeader) currentNode.NodeConfig.SetIsLeader(true) diff --git a/internal/configs/node/config.go b/internal/configs/node/config.go index ddcba4153..ec7da09e1 100644 --- a/internal/configs/node/config.go +++ b/internal/configs/node/config.go @@ -66,6 +66,7 @@ type ConfigType struct { client p2p.GroupID // the client group ID of the shard isClient bool // whether this node is a client node, such as wallet/txgen isLeader bool // whether this node is a leader or not + isBeacon bool // whether this node is beacon node doing consensus or not ShardID uint32 // ShardID of this node role Role // Role of the node @@ -146,6 +147,11 @@ func (conf *ConfigType) SetIsLeader(b bool) { conf.isLeader = b } +// SetIsBeacon sets the isBeacon configuration +func (conf *ConfigType) SetIsBeacon(b bool) { + conf.isBeacon = b +} + // SetShardID set the ShardID func (conf *ConfigType) SetShardID(s uint32) { conf.ShardID = s @@ -178,7 +184,7 @@ func (conf *ConfigType) IsClient() bool { // IsBeacon returns the isBeacon configuration func (conf *ConfigType) IsBeacon() bool { - return conf.ShardID == 0 + return conf.isBeacon } // IsLeader returns the isLeader configuration diff --git a/internal/configs/node/config_test.go b/internal/configs/node/config_test.go index f8c03be02..058822ca3 100644 --- a/internal/configs/node/config_test.go +++ b/internal/configs/node/config_test.go @@ -45,8 +45,14 @@ func TestNodeConfigMultiple(t *testing.T) { t.Errorf("expecting nil, got: %v", f) } + if c.IsBeacon() != false { + t.Errorf("expecting the node to not be beacon yet, got: %v", c.IsBeacon()) + } + + c.SetIsBeacon(true) + if c.IsBeacon() != true { - t.Errorf("expecting true, got: %v", c.IsBeacon()) + t.Errorf("expecting the node to be beacon, got: %v", c.IsBeacon()) } d.SetShardGroupID("abcd")