Merge branch 'master' of github.com:harmony-one/harmony into explorer_node

pull/1159/head
Rongjian Lan 5 years ago
commit be7d352e59
  1. 3
      cmd/harmony/main.go
  2. 4
      consensus/config.go
  3. 2
      node/node_handler.go
  4. 2
      node/node_newblock.go
  5. 12
      node/node_syncing.go

@ -105,6 +105,7 @@ var (
blockPeriod = flag.Int("block_period", 8, "how long in second 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 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 indicates the shard ID of this node
shardID = flag.Int("shard_id", -1, "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.") 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} 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.Leader = nodeConfig.SelfPeer
nodeConfig.StringRole = "leader" nodeConfig.StringRole = "leader"
} else { } else {

@ -7,10 +7,10 @@ const (
// The duration of viewChangeTimeout; when a view change is initialized with v+1 // 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 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 // 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 // timeout duration for announce/prepare/commit
phaseDuration time.Duration = 300 * time.Second phaseDuration time.Duration = 120 * time.Second
bootstrapDuration time.Duration = 300 * time.Second bootstrapDuration time.Duration = 300 * time.Second
maxLogSize uint32 = 1000 maxLogSize uint32 = 1000
// threshold between received consensus message blockNum and my blockNum // threshold between received consensus message blockNum and my blockNum

@ -813,7 +813,7 @@ func (node *Node) transitionIntoNextEpoch(shardState types.ShardState) {
publicKeys = append(publicKeys, key) publicKeys = append(publicKeys, key)
} }
node.Consensus.UpdatePublicKeys(publicKeys) node.Consensus.UpdatePublicKeys(publicKeys)
node.DRand.UpdatePublicKeys(publicKeys) // node.DRand.UpdatePublicKeys(publicKeys)
if node.Blockchain().ShardID() == myShardID { if node.Blockchain().ShardID() == myShardID {
getLogger().Info("staying in the same shard") getLogger().Info("staying in the same shard")

@ -54,8 +54,8 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
} }
case <-readySignal: case <-readySignal:
for { for {
if time.Now().Before(deadline) {
time.Sleep(PeriodicBlock) time.Sleep(PeriodicBlock)
if time.Now().Before(deadline) {
continue continue
} }

@ -197,26 +197,22 @@ func (node *Node) SendNewBlockToUnsync() {
continue continue
} }
node.stateMutex.Lock()
for peerID, config := range node.peerRegistrationRecord { for peerID, config := range node.peerRegistrationRecord {
elapseTime := time.Now().UnixNano() - config.timestamp elapseTime := time.Now().UnixNano() - config.timestamp
if elapseTime > broadcastTimeout { if elapseTime > broadcastTimeout {
utils.GetLogInstance().Warn("[SYNC] SendNewBlockToUnsync to peer timeout", "peerID", peerID) 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() node.peerRegistrationRecord[peerID].client.Close()
delete(node.peerRegistrationRecord, peerID) delete(node.peerRegistrationRecord, peerID)
node.stateMutex.Unlock()
continue continue
} }
response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false) response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false)
if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC { if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC {
node.stateMutex.Lock()
node.peerRegistrationRecord[peerID].client.Close() node.peerRegistrationRecord[peerID].client.Close()
delete(node.peerRegistrationRecord, peerID) 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[:]) peerID := string(request.PeerHash[:])
ip := request.Ip ip := request.Ip
port := request.Port port := request.Port
node.stateMutex.Lock()
defer node.stateMutex.Unlock()
if _, ok := node.peerRegistrationRecord[peerID]; ok { if _, ok := node.peerRegistrationRecord[peerID]; ok {
response.Type = downloader_pb.DownloaderResponse_FAIL response.Type = downloader_pb.DownloaderResponse_FAIL
utils.GetLogInstance().Warn("[SYNC] peerRegistration record already exists", "ip", ip, "port", port) 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 return response, nil
} }
config := &syncConfig{timestamp: time.Now().UnixNano(), client: client} config := &syncConfig{timestamp: time.Now().UnixNano(), client: client}
node.stateMutex.Lock()
node.peerRegistrationRecord[peerID] = config node.peerRegistrationRecord[peerID] = config
node.stateMutex.Unlock()
utils.GetLogInstance().Debug("[SYNC] register peerID success", "ip", ip, "port", port) utils.GetLogInstance().Debug("[SYNC] register peerID success", "ip", ip, "port", port)
response.Type = downloader_pb.DownloaderResponse_SUCCESS response.Type = downloader_pb.DownloaderResponse_SUCCESS
} }

Loading…
Cancel
Save