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

  1. Compare block file contents/names under ledgersData against the expected sequence and locate the gap
  2. Restore the ledger from a consistent peer backup or snapshot
  3. Use peer node reset (or rebuild) and re-download the chain from orderers
  4. 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

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


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/5afc09e0bbd5632b. Report an issue: GitHub.