From 44c2c003786c0c365266334797e938221638ee62 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Thu, 13 Sep 2018 17:26:45 -0700 Subject: [PATCH] fix the bugs in multicaset --- node/node_handler.go | 4 ++-- p2p/peer.go | 8 +++++--- utils/distribution_config.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/node/node_handler.go b/node/node_handler.go index 41d105191..ce36151e2 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -27,7 +27,7 @@ const ( ) func (node *Node) MaybeBroadcastAsValidator(content []byte) { - if node.SelfPeer.ValidatorID > 0 && node.SelfPeer.ValidatorID < p2p.MAX_BROADCAST { + if node.SelfPeer.ValidatorID > 0 && node.SelfPeer.ValidatorID <= p2p.MAX_BROADCAST { go p2p.BroadcastMessageFromValidator(node.SelfPeer, node.Consensus.GetValidatorPeers(), content) } } @@ -43,7 +43,7 @@ func (node *Node) NodeHandler(conn net.Conn) { node.log.Error("Read p2p data failed", "err", err, "node", node) return } - // node.MaybeBroadcastAsValidator(content) + node.MaybeBroadcastAsValidator(content) consensusObj := node.Consensus diff --git a/p2p/peer.go b/p2p/peer.go index 7c9941ee7..ecc913ad0 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -53,7 +53,7 @@ func BroadcastMessage(peers []Peer, msg []byte) { }() } wg.Wait() - log.Info("Broadcasting Down", "time spent", time.Now().Sub(start).Seconds()) + log.Info("Broadcasting Done", "time spent", time.Now().Sub(start).Seconds()) } func SelectMyPeers(peers []Peer, min int, max int) []Peer { @@ -69,14 +69,16 @@ func SelectMyPeers(peers []Peer, min int, max int) []Peer { // BroadcastMessage sends the message to a list of peers from a leader. func BroadcastMessageFromLeader(peers []Peer, msg []byte) { // TODO(minhdoan): Enable back for multicast. - // peers = SelectMyPeers(peers, 0, MAX_BROADCAST-1) + peers = SelectMyPeers(peers, 1, MAX_BROADCAST) BroadcastMessage(peers, msg) + log.Info("Done sending from leader") } // 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+1)*MAX_BROADCAST, (selfPeer.ValidatorID+2)*MAX_BROADCAST-1) + peers = SelectMyPeers(peers, selfPeer.ValidatorID*MAX_BROADCAST+1, (selfPeer.ValidatorID+1)*MAX_BROADCAST) BroadcastMessage(peers, msg) + log.Info("Done sending from validator") } // ConstructP2pMessage constructs the p2p message as [messageType, contentSize, content] diff --git a/utils/distribution_config.go b/utils/distribution_config.go index a9a97506b..962a365ed 100644 --- a/utils/distribution_config.go +++ b/utils/distribution_config.go @@ -88,8 +88,8 @@ func (config *DistributionConfig) ReadConfigFile(filename string) error { shardID, _ := strconv.Atoi(p[3]) validatorID := -1 if p[2] == "validator" { - validatorID = validatorMap[shardID] validatorMap[shardID]++ + validatorID = validatorMap[shardID] } entry := ConfigEntry{p[0], p[1], p[2], p[3], validatorID} result = append(result, entry)