From f02ff769d3a6e5c1117a25c93535dca5c2a76e0c Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 24 Feb 2019 09:02:32 +0000 Subject: [PATCH] only enable randomness service on leader consensus readched on AWS deployment Signed-off-by: Leo Chen --- cmd/harmony.go | 2 +- drand/drand.go | 8 ++------ node/service_setup.go | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmd/harmony.go b/cmd/harmony.go index 47f91ce52..b6f962b72 100644 --- a/cmd/harmony.go +++ b/cmd/harmony.go @@ -279,7 +279,7 @@ func main() { // Add randomness protocol // TODO: enable drand only for beacon chain // TODO: put this in a better place other than main. - dRand := drand.New(host, shardID, peers, leader, currentNode.ConfirmedBlockChannel) + dRand := drand.New(host, shardID, peers, leader, currentNode.ConfirmedBlockChannel, *isLeader) currentNode.Consensus.RegisterPRndChannel(dRand.PRndChannel) currentNode.Consensus.RegisterRndChannel(dRand.RndChannel) currentNode.DRand = dRand diff --git a/drand/drand.go b/drand/drand.go index 6302cf3b6..e2402cb5d 100644 --- a/drand/drand.go +++ b/drand/drand.go @@ -67,7 +67,7 @@ type DRand struct { } // New creates a new dRand object -func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confirmedBlockChannel chan *types.Block) *DRand { +func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confirmedBlockChannel chan *types.Block, isLeader bool) *DRand { dRand := DRand{} dRand.host = host @@ -79,11 +79,7 @@ func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confi dRand.RndChannel = make(chan [64]byte) selfPeer := host.GetSelfPeer() - if leader.Port == selfPeer.Port && leader.IP == selfPeer.IP { - dRand.IsLeader = true - } else { - dRand.IsLeader = false - } + dRand.IsLeader = isLeader dRand.leader = leader for _, peer := range peers { diff --git a/node/service_setup.go b/node/service_setup.go index 66ff4f69a..3a98f370e 100644 --- a/node/service_setup.go +++ b/node/service_setup.go @@ -71,8 +71,6 @@ func (node *Node) setupForBeaconValidator() { node.serviceManager.RegisterService(service.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer)) // Register networkinfo service. node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, p2p.GroupIDBeacon, chanPeer)) - // Register randomness service - node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand)) } func (node *Node) setupForNewNode() {