Merge pull request #673 from alajko/setBeacon

Seperate the notion of shardId=0 from a beacon node
pull/678/head
alajko 6 years ago committed by GitHub
commit d0ddf70f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cmd/harmony/main.go
  2. 8
      internal/configs/node/config.go
  3. 8
      internal/configs/node/config_test.go

@ -218,6 +218,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen
if *isGenesis { if *isGenesis {
// TODO: need change config file and use switch instead of complicated "if else" condition // TODO: need change config file and use switch instead of complicated "if else" condition
if nodeConfig.ShardID == 0 { // Beacon chain if nodeConfig.ShardID == 0 { // Beacon chain
nodeConfig.SetIsBeacon(true)
if nodeConfig.StringRole == "leader" { if nodeConfig.StringRole == "leader" {
currentNode.NodeConfig.SetRole(nodeconfig.BeaconLeader) currentNode.NodeConfig.SetRole(nodeconfig.BeaconLeader)
currentNode.NodeConfig.SetIsLeader(true) currentNode.NodeConfig.SetIsLeader(true)

@ -66,6 +66,7 @@ type ConfigType struct {
client p2p.GroupID // the client group ID of the shard client p2p.GroupID // the client group ID of the shard
isClient bool // whether this node is a client node, such as wallet/txgen isClient bool // whether this node is a client node, such as wallet/txgen
isLeader bool // whether this node is a leader or not 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 ShardID uint32 // ShardID of this node
role Role // Role of the node role Role // Role of the node
@ -146,6 +147,11 @@ func (conf *ConfigType) SetIsLeader(b bool) {
conf.isLeader = b conf.isLeader = b
} }
// SetIsBeacon sets the isBeacon configuration
func (conf *ConfigType) SetIsBeacon(b bool) {
conf.isBeacon = b
}
// SetShardID set the ShardID // SetShardID set the ShardID
func (conf *ConfigType) SetShardID(s uint32) { func (conf *ConfigType) SetShardID(s uint32) {
conf.ShardID = s conf.ShardID = s
@ -178,7 +184,7 @@ func (conf *ConfigType) IsClient() bool {
// IsBeacon returns the isBeacon configuration // IsBeacon returns the isBeacon configuration
func (conf *ConfigType) IsBeacon() bool { func (conf *ConfigType) IsBeacon() bool {
return conf.ShardID == 0 return conf.isBeacon
} }
// IsLeader returns the isLeader configuration // IsLeader returns the isLeader configuration

@ -45,8 +45,14 @@ func TestNodeConfigMultiple(t *testing.T) {
t.Errorf("expecting nil, got: %v", f) 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 { 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") d.SetShardGroupID("abcd")

Loading…
Cancel
Save