From c62da24dce53f942b16fdb0984449a3aa9c16f24 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 9 May 2023 09:57:42 +0200 Subject: [PATCH] cmd/utils: report the blocknumber when block import fails (#27213) 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. --- cmd/utils/cmd.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index e1bafc53c3..c9e02eb68c 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -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