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

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

Loading…
Cancel
Save