diff --git a/core/resharding.go b/core/resharding.go index 248542627..723aee79a 100644 --- a/core/resharding.go +++ b/core/resharding.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) + } } } diff --git a/node/node_handler.go b/node/node_handler.go index 83a17d2f9..d211ac82b 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -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 diff --git a/node/node_syncing.go b/node/node_syncing.go index 4abac8a36..a6aa70f85 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -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() diff --git a/p2p/host/hostv2/hostv2.go b/p2p/host/hostv2/hostv2.go index 193e2d2ff..eb7fa66d2 100644 --- a/p2p/host/hostv2/hostv2.go +++ b/p2p/host/hostv2/hostv2.go @@ -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 diff --git a/p2p/host/hostv2/hostv2_test.go b/p2p/host/hostv2/hostv2_test.go index 01018a14e..b98203dfa 100644 --- a/p2p/host/hostv2/hostv2_test.go +++ b/p2p/host/hostv2/hostv2_test.go @@ -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") + } + }) }