From c6e1d826cbbfa82bc82ebe8dd832015c17be7bde Mon Sep 17 00:00:00 2001 From: andy-shi88 Date: Fri, 20 Mar 2020 11:59:45 +0800 Subject: [PATCH] handle nil value --- core/service/blockMainService.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/service/blockMainService.go b/core/service/blockMainService.go index 5eb455c5f..55d9ab5a9 100644 --- a/core/service/blockMainService.go +++ b/core/service/blockMainService.go @@ -589,6 +589,12 @@ func (bs *BlockService) PushBlock(previousBlock, block *model.Block, broadcast, // get blocksmith index blocksmithsMap := bs.BlocksmithStrategy.GetSortedBlocksmithsMap(previousBlock) blocksmithIndex = blocksmithsMap[string(block.BlocksmithPublicKey)] + if blocksmithIndex == nil { + if rollbackErr := bs.QueryExecutor.RollbackTx(); rollbackErr != nil { + bs.Logger.Error(rollbackErr.Error()) + } + return blocker.NewBlocker(blocker.BlockErr, "BlocksmithNotInSmithingList") + } // handle if is first index if *blocksmithIndex > 0 { // check if current block is in pushable window @@ -1453,7 +1459,9 @@ func (bs *BlockService) WillSmith( blocksmithsMap := bs.BlocksmithStrategy.GetSortedBlocksmithsMap(lastBlock) blocksmithIndex, ok := blocksmithsMap[string(blocksmith.NodePublicKey)] if !ok { - return blockchainProcessorLastBlockID, err + return blockchainProcessorLastBlockID, blocker.NewBlocker( + blocker.BlockErr, "BlocksmithNotInSmithingList", + ) } blockPool := bs.BlockPoolService.GetBlock(*blocksmithIndex) if blockPool != nil {