From 40e128cedab1374d1678eaede4d2ecad290f0c27 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 23 Jun 2019 04:52:32 +0000 Subject: [PATCH 1/4] [misc] disable DRand public key update Signed-off-by: Leo Chen --- node/node_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_handler.go b/node/node_handler.go index 33eecf3c3..de262eedf 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -819,7 +819,7 @@ func (node *Node) transitionIntoNextEpoch(shardState types.ShardState) { publicKeys = append(publicKeys, key) } node.Consensus.UpdatePublicKeys(publicKeys) - node.DRand.UpdatePublicKeys(publicKeys) + // node.DRand.UpdatePublicKeys(publicKeys) if node.Blockchain().ShardID() == myShardID { getLogger().Info("staying in the same shard") From 5d107f53fbd6a3c9f92d6c7e4d13879f0a523111 Mon Sep 17 00:00:00 2001 From: Chao Ma Date: Mon, 24 Jun 2019 22:59:48 -0700 Subject: [PATCH 2/4] fix concurrent map access crash in node sync --- node/node_syncing.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/node/node_syncing.go b/node/node_syncing.go index ffca638e4..c5e62f8e0 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -197,26 +197,22 @@ func (node *Node) SendNewBlockToUnsync() { continue } + node.stateMutex.Lock() for peerID, config := range node.peerRegistrationRecord { elapseTime := time.Now().UnixNano() - config.timestamp if elapseTime > broadcastTimeout { utils.GetLogInstance().Warn("[SYNC] SendNewBlockToUnsync to peer timeout", "peerID", peerID) - // send last time and delete - config.client.PushNewBlock(node.GetSyncID(), blockHash, true) - node.stateMutex.Lock() node.peerRegistrationRecord[peerID].client.Close() delete(node.peerRegistrationRecord, peerID) - node.stateMutex.Unlock() continue } response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false) if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC { - node.stateMutex.Lock() node.peerRegistrationRecord[peerID].client.Close() delete(node.peerRegistrationRecord, peerID) - node.stateMutex.Unlock() } } + node.stateMutex.Unlock() } } @@ -290,6 +286,8 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (* peerID := string(request.PeerHash[:]) ip := request.Ip port := request.Port + node.stateMutex.Lock() + defer node.stateMutex.Unlock() if _, ok := node.peerRegistrationRecord[peerID]; ok { response.Type = downloader_pb.DownloaderResponse_FAIL utils.GetLogInstance().Warn("[SYNC] peerRegistration record already exists", "ip", ip, "port", port) @@ -307,9 +305,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (* return response, nil } config := &syncConfig{timestamp: time.Now().UnixNano(), client: client} - node.stateMutex.Lock() node.peerRegistrationRecord[peerID] = config - node.stateMutex.Unlock() utils.GetLogInstance().Debug("[SYNC] register peerID success", "ip", ip, "port", port) response.Type = downloader_pb.DownloaderResponse_SUCCESS } From fb560f9c04fe6f0ee1ba2bdf7a9f771d942dab99 Mon Sep 17 00:00:00 2001 From: chao Date: Tue, 25 Jun 2019 12:35:40 -0700 Subject: [PATCH 3/4] * add sleep time to avoid non-stop new block proposing in for loop * add leader role override flag in cmd --- cmd/harmony/main.go | 5 +++-- node/node_newblock.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 9aa839c09..bf7218a94 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -104,7 +104,8 @@ var ( // blockPeriod indicates the how long the leader waits to propose a new block. blockPeriod = flag.Int("block_period", 8, "how long in second the leader waits to propose a new block.") // isNewNode indicates this node is a new node - isNewNode = flag.Bool("is_newnode", false, "true means this node is a new node") + isNewNode = flag.Bool("is_newnode", false, "true means this node is a new node") + leaderOverride = flag.Bool("leader_override", false, "true means override the default leader role and acts as validator") // shardID indicates the shard ID of this node shardID = flag.Int("shard_id", -1, "the shard ID of this node") enableMemProfiling = flag.Bool("enableMemProfiling", false, "Enable memsize logging.") @@ -271,7 +272,7 @@ func createGlobalConfig() *nodeconfig.ConfigType { nodeConfig.SelfPeer = p2p.Peer{IP: *ip, Port: *port, ConsensusPubKey: nodeConfig.ConsensusPubKey} - if accountIndex < core.GenesisShardNum && !*isExplorer { // The first node in a shard is the leader at genesis + if accountIndex < core.GenesisShardNum && !*isExplorer && !*leaderOverride { // The first node in a shard is the leader at genesis nodeConfig.Leader = nodeConfig.SelfPeer nodeConfig.StringRole = "leader" } else { diff --git a/node/node_newblock.go b/node/node_newblock.go index fd19ac031..9b4c29b26 100644 --- a/node/node_newblock.go +++ b/node/node_newblock.go @@ -54,8 +54,8 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch } case <-readySignal: for { + time.Sleep(PeriodicBlock) if time.Now().Before(deadline) { - time.Sleep(PeriodicBlock) continue } From 77430a34d9df4343ebedbd78590fee17c3a2c8a0 Mon Sep 17 00:00:00 2001 From: chao Date: Tue, 25 Jun 2019 15:42:28 -0700 Subject: [PATCH 4/4] change default timeout in consensus protocol --- consensus/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/config.go b/consensus/config.go index 614154d7a..f5acd8d21 100644 --- a/consensus/config.go +++ b/consensus/config.go @@ -7,10 +7,10 @@ const ( // The duration of viewChangeTimeout; when a view change is initialized with v+1 // timeout will be equal to viewChangeDuration; if view change failed and start v+2 // timeout will be 2*viewChangeDuration; timeout of view change v+n is n*viewChangeDuration - viewChangeDuration time.Duration = 300 * time.Second + viewChangeDuration time.Duration = 60 * time.Second // timeout duration for announce/prepare/commit - phaseDuration time.Duration = 300 * time.Second + phaseDuration time.Duration = 120 * time.Second bootstrapDuration time.Duration = 300 * time.Second maxLogSize uint32 = 1000 // threshold between received consensus message blockNum and my blockNum