{"record":{"id":"5afc09e0bbd5632b","repo":"hyperledger/fabric","slug":"the-next-block-is-expected-to-be-d-but-got-d","errorCode":null,"errorMessage":"The next block is expected to be %d but got %d","messagePattern":"The next block is expected to be (.+?) but got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/ledgerutil/verify/verify.go","lineNumber":116,"sourceCode":"\t\t}\n\n\t\tvar previousHash []byte\n\t\tfor i := firstBlockNumber; i < info.GetHeight(); i++ {\n\t\t\t// Retrieve the next block\n\t\t\tresult, err := iterator.Next()\n\t\t\tif err != nil {\n\t\t\t\treturn false, err\n\t\t\t}\n\t\t\tif result == nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tblock, ok := result.(*common.Block)\n\t\t\tif !ok {\n\t\t\t\treturn false, errors.Errorf(\"Cannot decode the block %d\", i)\n\t\t\t}\n\n\t\t\tif block.Header.Number != i {\n\t\t\t\treturn false, errors.Errorf(\"The next block is expected to be %d but got %d\", i, block.Header.Number)\n\t\t\t}\n\n\t\t\t// Perform checks for this block\n\t\t\tcheckResult, err := checkBlock(block, previousHash)\n\t\t\tif err != nil {\n\t\t\t\treturn false, err\n\t\t\t}\n\n\t\t\t// If any error is found, flag as so, and vice versa\n\t\t\tif !checkResult.Valid {\n\t\t\t\tledgerErrorFound = true\n\t\t\t\tblockResult.erroneousBlocks += 1\n\n\t\t\t\t// Record the error details in the JSON\n\t\t\t\terr = blockResult.writer.AddEntry(checkResult)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn false, err\n\t\t\t\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/ledgerutil/verify/verify.go#L98-L134","documentation":"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.","triggerScenarios":"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.","commonSituations":"Ledger files deleted or reordered manually, restore from an inconsistent backup, or a partially copied ledgersData directory from another peer.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Compare top-level block number against chain height before verifying\nheight := queryChainHeight(channel)\nlastBlock := readLastBlockNumber(fsPath)\nif lastBlock > height { log.Warnf(\"store ahead of chain: %d > %d\", lastBlock, height) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["ledger","blockchain","fabric"],"backgroundTag":"ledger-data-corruption","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}