From a9ebca5d53f98217af9ebf7266dca55d2b60770d Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 18 Mar 2019 23:37:02 +0000 Subject: [PATCH 1/2] [harmony] set IsLeader/IsBeacon flag in nodeconfig Signed-off-by: Leo Chen --- cmd/harmony/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index b4f7609fa..64b677737 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -207,10 +207,13 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen if *isBeacon { if nodeConfig.StringRole == "leader" { currentNode.NodeConfig.SetRole(nodeconfig.BeaconLeader) + currentNode.NodeConfig.SetIsLeader(true) } else { currentNode.NodeConfig.SetRole(nodeconfig.BeaconValidator) + currentNode.NodeConfig.SetIsLeader(false) } currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon) + currentNode.NodeConfig.SetIsBeacon(true) } else { currentNode.AddBeaconChainDatabase(nodeConfig.BeaconDB) @@ -218,10 +221,13 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen currentNode.NodeConfig.SetRole(nodeconfig.NewNode) } else if nodeConfig.StringRole == "leader" { currentNode.NodeConfig.SetRole(nodeconfig.ShardLeader) + currentNode.NodeConfig.SetIsLeader(true) } else { currentNode.NodeConfig.SetRole(nodeconfig.ShardValidator) + currentNode.NodeConfig.SetIsLeader(false) } currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDUnknown) + currentNode.NodeConfig.SetIsBeacon(false) } // Add randomness protocol From e53d4780e9fda361ea1a956b23dd7a566e81c5ea Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 18 Mar 2019 23:03:55 +0000 Subject: [PATCH 2/2] [pingpong] skip addPeer for ping message handler Validator will receive peer info from pong message sent by the leader, no need for validator to handle ping message to add peer's pubkeys Signed-off-by: Leo Chen --- node/node_handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node/node_handler.go b/node/node_handler.go index d1fde694f..674c12692 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -388,9 +388,10 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int { return 0 } - // Add to Node's peer list anyway - utils.GetLogInstance().Info("Add Peer to Node", "Node", node.Consensus.GetNodeID(), "Pear", peer) - node.AddPeers([]*p2p.Peer{peer}) + if node.NodeConfig.IsLeader() { + utils.GetLogInstance().Info("Add Peer to Node", "Node", node.Consensus.GetNodeID(), "Pear", peer) + node.AddPeers([]*p2p.Peer{peer}) + } return 1 }