Skip to content

Commit

Permalink
cmd/utils: report the blocknumber when block import fails (ethereum#2…
Browse files Browse the repository at this point in the history
…7213)

When block import fails, the error displays the number of the first block past the import batch, not the number of the failing block. This change fixes this problem by identifying which blocks fails and reporting its number.
  • Loading branch information
gballet authored May 9, 2023
1 parent c798507 commit c62da24
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,14 @@ func ImportChain(chain *core.BlockChain, fn string) error {
log.Info("Skipping batch as all blocks present", "batch", batch, "first", blocks[0].Hash(), "last", blocks[i-1].Hash())
continue
}
if _, err := chain.InsertChain(missing); err != nil {
return fmt.Errorf("invalid block %d: %v", n, err)
if failindex, err := chain.InsertChain(missing); err != nil {
var failnumber uint64
if failindex > 0 && failindex < len(missing) {
failnumber = missing[failindex].NumberU64()
} else {
failnumber = missing[0].NumberU64()
}
return fmt.Errorf("invalid block %d: %v", failnumber, err)
}
}
return nil
Expand Down

0 comments on commit c62da24

Please sign in to comment.