polish the logic of avoiding doing some unnessary work when # of peers is 0

pull/73/head
Minh Doan 6 years ago
parent 67b160901b
commit 9e1b9129e5
  1. 9
      p2p/peer.go

@ -37,6 +37,9 @@ func SendMessage(peer Peer, msg []byte) {
// BroadcastMessage sends the message to a list of peers
func BroadcastMessage(peers []Peer, msg []byte) {
if len(peers) == 0 {
return
}
// Construct broadcast p2p message
content := ConstructP2pMessage(byte(17), msg)
@ -77,10 +80,8 @@ func BroadcastMessageFromLeader(peers []Peer, msg []byte) {
// BroadcastMessage sends the message to a list of peers from a validator.
func BroadcastMessageFromValidator(selfPeer Peer, peers []Peer, msg []byte) {
peers = SelectMyPeers(peers, selfPeer.ValidatorID*MAX_BROADCAST+1, (selfPeer.ValidatorID+1)*MAX_BROADCAST)
if len(peers) > 0 {
BroadcastMessage(peers, msg)
log.Info("Done sending from validator")
}
BroadcastMessage(peers, msg)
log.Info("Done sending from validator")
}
// ConstructP2pMessage constructs the p2p message as [messageType, contentSize, content]

Loading…
Cancel
Save