only send pong message from leader

Signed-off-by: Leo Chen <leo@harmony.one>
pull/405/head
Leo Chen 6 years ago
parent 526e31214c
commit f3b0432e2d
  1. 4
      cmd/harmony.go
  2. 41
      node/node_handler.go

@ -134,7 +134,7 @@ func main() {
utils.BootNodes = bootNodeAddrs
}
var shardID string
var shardID = "0"
var peers []p2p.Peer
var leader p2p.Peer
var selfPeer p2p.Peer
@ -196,6 +196,7 @@ func main() {
} else {
if *isLeader {
role = "leader"
leader = selfPeer
} else {
role = "validator"
}
@ -219,6 +220,7 @@ func main() {
host.AddPeer(&leader)
// Consensus object.
// TODO: consensus object shouldn't start here
consensus := consensus.New(host, shardID, peers, leader)
consensus.MinPeers = *minPeers

@ -261,25 +261,28 @@ func (node *Node) pingMessageHandler(msgPayload []byte) int {
// Add to Node's peer list anyway
node.AddPeers([]*p2p.Peer{peer})
peers := node.Consensus.GetValidatorPeers()
pong := proto_discovery.NewPongMessage(peers, node.Consensus.PublicKeys)
buffer := pong.ConstructPongMessage()
// Send a Pong message directly to the sender
// This is necessary because the sender will need to get a ValidatorID
// Just broadcast won't work, some validators won't receive the latest
// PublicKeys as we rely on a valid ValidatorID to do broadcast.
// This is very buggy, but we will move to libp2p, hope the problem will
// be resolved then.
// However, I disable it for now as we are sending redundant PONG messages
// to all validators. This may not be needed. But it maybe add back.
// p2p.SendMessage(*peer, buffer)
// Broadcast the message to all validators, as publicKeys is updated
// FIXME: HAR-89 use a separate nodefind/neighbor message
host.BroadcastMessageFromLeader(node.GetHost(), peers, buffer, node.Consensus.OfflinePeers)
return len(peers)
if node.Consensus.IsLeader {
peers := node.Consensus.GetValidatorPeers()
pong := proto_discovery.NewPongMessage(peers, node.Consensus.PublicKeys)
buffer := pong.ConstructPongMessage()
// Send a Pong message directly to the sender
// This is necessary because the sender will need to get a ValidatorID
// Just broadcast won't work, some validators won't receive the latest
// PublicKeys as we rely on a valid ValidatorID to do broadcast.
// This is very buggy, but we will move to libp2p, hope the problem will
// be resolved then.
// However, I disable it for now as we are sending redundant PONG messages
// to all validators. This may not be needed. But it maybe add back.
// p2p.SendMessage(*peer, buffer)
// Broadcast the message to all validators, as publicKeys is updated
// FIXME: HAR-89 use a separate nodefind/neighbor message
host.BroadcastMessageFromLeader(node.GetHost(), peers, buffer, node.Consensus.OfflinePeers)
utils.GetLogInstance().Info("PingMsgHandler send pong message")
}
return 1
}
func (node *Node) pongMessageHandler(msgPayload []byte) int {

Loading…
Cancel
Save