hyperledger/fabric · critical
The next block is expected to be %d but got %d
Error message
The next block is expected to be %d but got %d
What it means
Blocks read from the store must be strictly sequential. After decoding block i, VerifyLedger checks that its header number equals i; a mismatch means the chain is broken or the store returns blocks out of order.
Source
Thrown at internal/ledgerutil/verify/verify.go:116
}
var previousHash []byte
for i := firstBlockNumber; i < info.GetHeight(); i++ {
// Retrieve the next block
result, err := iterator.Next()
if err != nil {
return false, err
}
if result == nil {
break
}
block, ok := result.(*common.Block)
if !ok {
return false, errors.Errorf("Cannot decode the block %d", i)
}
if block.Header.Number != i {
return false, errors.Errorf("The next block is expected to be %d but got %d", i, block.Header.Number)
}
// Perform checks for this block
checkResult, err := checkBlock(block, previousHash)
if err != nil {
return false, err
}
// If any error is found, flag as so, and vice versa
if !checkResult.Valid {
ledgerErrorFound = true
blockResult.erroneousBlocks += 1
// Record the error details in the JSON
err = blockResult.writer.AddEntry(checkResult)
if err != nil {
return false, err
}View on GitHub (pinned to 2736b63f8f)
Solutions
- Compare block file contents/names under ledgersData against the expected sequence and locate the gap
- Restore the ledger from a consistent peer backup or snapshot
- Use peer node reset (or rebuild) and re-download the chain from orderers
- Audit any scripts that move or prune block files
Defensive patterns
Strategy: validation
Validate before calling
// Compare top-level block number against chain height before verifying
height := queryChainHeight(channel)
lastBlock := readLastBlockNumber(fsPath)
if lastBlock > height { log.Warnf("store ahead of chain: %d > %d", lastBlock, height) } Prevention
- Only restore ledgersData from atomic, peer-stopped backups
- Avoid scripts that rename or prune individual block files
- Keep peers in sync; investigate persistent gaps immediately
- Run verify-ledger after any manual data-dir operation
When it happens
Trigger: checkBlock iteration advances the iterator but the returned block's Header.Number does not match the expected sequential index i — typically caused by missing or misordered block files in the block store.
Common situations: Ledger files deleted or reordered manually, restore from an inconsistent backup, or a partially copied ledgersData directory from another peer.
Related errors
- unexpected end of blockfile
- error opening block file %s
- error seeking block file [%s] to startOffset [%d]
- Could not seek block file [%s] to startOffset [%d]. New posi
- error getting block file stat
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/5afc09e0bbd5632b.
Report an issue: GitHub.