From 24519aed01334e496582a45ec91ef6e801d07d08 Mon Sep 17 00:00:00 2001 From: Franklin Date: Sun, 18 Nov 2018 11:15:46 +0800 Subject: [PATCH 1/2] core: return error if repair block failed --- core/blockchain.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index d173b2de294d..ee1c0702b5f4 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -445,7 +445,11 @@ func (bc *BlockChain) repair(head **types.Block) error { return nil } // Otherwise rewind one block and recheck state availability there - (*head) = bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1) + block := bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1) + if block == nil { + return fmt.Errorf("failed to repair block, can not get block at height %d", (*head).NumberU64()) + } + (*head) = block } } From ea9bc8a8a4f3221cdba6d8bcf7e3c0e2da862307 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 21 Nov 2018 19:38:45 +0800 Subject: [PATCH 2/2] make error a bit shorter --- core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index ee1c0702b5f4..dd31b9b3a459 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -447,7 +447,7 @@ func (bc *BlockChain) repair(head **types.Block) error { // Otherwise rewind one block and recheck state availability there block := bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1) if block == nil { - return fmt.Errorf("failed to repair block, can not get block at height %d", (*head).NumberU64()) + return fmt.Errorf("missing block %d [%x]", (*head).NumberU64()-1, (*head).ParentHash()) } (*head) = block }