Browse Source

core: return error if repair block failed (#18126)

* core: return error if repair block failed

* make error a bit shorter
mr_franklin 7 năm trước cách đây
mục cha
commit
2a113f6d72
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      core/blockchain.go

+ 5 - 1
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("missing block %d [%x]", (*head).NumberU64()-1, (*head).ParentHash())
+		}
+		(*head) = block
 	}
 }