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

pull/763/head
Rongjian Lan 6 years ago
commit 7187846cb2
  1. 6
      core/resharding.go
  2. 8
      node/node_handler.go
  3. 1
      node/node_syncing.go
  4. 3
      p2p/host/hostv2/hostv2.go
  5. 7
      p2p/host/hostv2/hostv2_test.go

@ -58,7 +58,11 @@ func (ss *ShardingState) assignNewNodes(newNodeList []types.NodeID) {
if numActiveShards > 0 {
id = i % numActiveShards
}
ss.shardState[id].NodeList = append(ss.shardState[id].NodeList, nid)
if id < len(ss.shardState) {
ss.shardState[id].NodeList = append(ss.shardState[id].NodeList, nid)
} else {
utils.GetLogInstance().Error("assignNewNodes", "index out of range", len(ss.shardState), "id", id)
}
}
}

@ -126,10 +126,8 @@ func (node *Node) messageHandler(content []byte, sender string) {
case proto.Consensus:
msgPayload, _ := proto.GetConsensusMessagePayload(content)
if consensusObj.IsLeader {
utils.GetLogInstance().Info("NET: Leader received consensus message")
consensusObj.ProcessMessageLeader(msgPayload)
} else {
utils.GetLogInstance().Info("NET: Validator received consensus message")
consensusObj.ProcessMessageValidator(msgPayload)
// TODO(minhdoan): add logic to check if the current blockchain is not sync with other consensus
// we should switch to other state rather than DoingConsensus.
@ -138,10 +136,8 @@ func (node *Node) messageHandler(content []byte, sender string) {
msgPayload, _ := proto.GetDRandMessagePayload(content)
if node.DRand != nil {
if node.DRand.IsLeader {
utils.GetLogInstance().Info("NET: DRand Leader received message")
node.DRand.ProcessMessageLeader(msgPayload)
} else {
utils.GetLogInstance().Info("NET: DRand Validator received message")
node.DRand.ProcessMessageValidator(msgPayload)
}
}
@ -309,7 +305,6 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) bool {
// 1. add the new block to blockchain
// 2. [leader] send new block to the client
func (node *Node) PostConsensusProcessing(newBlock *types.Block) {
utils.GetLogInstance().Info("PostConsensusProcessing")
if node.Consensus.IsLeader {
node.BroadcastNewBlock(newBlock)
} else {
@ -413,7 +408,6 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int {
// SendPongMessage is the a goroutine to periodcally send pong message to all peers
func (node *Node) SendPongMessage() {
utils.GetLogInstance().Info("Starting Pong routing")
tick := time.NewTicker(2 * time.Second)
tick2 := time.NewTicker(120 * time.Second)
@ -583,8 +577,6 @@ func (node *Node) epochShardStateMessageHandler(msgPayload []byte) int {
}
func (node *Node) processEpochShardState(epochShardState *types.EpochShardState) {
utils.GetLogInstance().Error("[Processing new shard state]")
shardState := epochShardState.ShardState
epoch := epochShardState.Epoch

@ -185,7 +185,6 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (*
response := &downloader_pb.DownloaderResponse{}
switch request.Type {
case downloader_pb.DownloaderRequest_HEADER:
utils.GetLogInstance().Debug("[SYNC] CalculateResponse DownloaderRequest_HEADER", "request.BlockHash", request.BlockHash)
var startHeaderHash []byte
if request.BlockHash == nil {
tmp := node.blockchain.Genesis().Hash()

@ -87,6 +87,9 @@ func (r *GroupReceiverImpl) Close() error {
func (r *GroupReceiverImpl) Receive(ctx context.Context) (
msg []byte, sender libp2p_peer.ID, err error,
) {
if r.sub == nil {
return nil, libp2p_peer.ID(""), fmt.Errorf("GroupReceiver has been closed")
}
m, err := r.sub.Next(ctx)
if err == nil {
msg = m.Data

@ -128,4 +128,11 @@ func TestHostV2_GroupReceiver(t *testing.T) {
t.Error("expected an error; got none")
}
})
t.Run("Closed", func(t *testing.T) {
var emptyReceiver GroupReceiverImpl
_, _, err := emptyReceiver.Receive(context.Background())
if err == nil {
t.Errorf("Receive() from nil/closed receiver did not return error")
}
})
}

Loading…
Cancel
Save