{"record":{"id":"e047497c08d0b7c6","repo":"hyperledger/fabric","slug":"no-such-block-number-d-in-index","errorCode":null,"errorMessage":"no such block number [%d] in index","messagePattern":"no such block number \\[(.+?)\\] in index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"common/ledger/blkstorage/blockindex.go","lineNumber":181,"sourceCode":"\t\treturn nil, errors.Errorf(\"no such block hash [%x] in index\", blockHash)\n\t}\n\tblkLoc := &fileLocPointer{}\n\tif err := blkLoc.unmarshal(b); err != nil {\n\t\treturn nil, err\n\t}\n\treturn blkLoc, nil\n}\n\nfunc (index *blockIndex) getBlockLocByBlockNum(blockNum uint64) (*fileLocPointer, error) {\n\tif !index.isAttributeIndexed(IndexableAttrBlockNum) {\n\t\treturn nil, errors.New(\"block numbers not maintained in index\")\n\t}\n\tb, err := index.db.Get(constructBlockNumKey(blockNum))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif b == nil {\n\t\treturn nil, errors.Errorf(\"no such block number [%d] in index\", blockNum)\n\t}\n\tblkLoc := &fileLocPointer{}\n\tif err := blkLoc.unmarshal(b); err != nil {\n\t\treturn nil, err\n\t}\n\treturn blkLoc, nil\n}\n\nfunc (index *blockIndex) getTxLoc(txID string) (*fileLocPointer, error) {\n\tv, _, err := index.getTxIDVal(txID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttxFLP := &fileLocPointer{}\n\tif err = txFLP.unmarshal(v.TxLocation); err != nil {\n\t\treturn nil, err\n\t}\n\treturn txFLP, nil","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockindex.go#L163-L199","documentation":"Returned by blockIndex.getBlockLocByBlockNum when a block-number index lookup succeeds at the levelDB layer but returns no value — the requested block number is simply not present in the index (e.g. beyond the ledger height or pruned).","triggerScenarios":"By-number retrieval or index range deletion targeting a block number not in the index: future number, wrong ledger, or missing index entry.","commonSituations":"Polling for uncommitted blocks, snapshot/truncation-related index gaps, channel mismatch.","solutions":["Validate blockNum against ledger height before calling","Retry with backoff when polling for pending commits","Rebuild index if entries below height are missing","Confirm correct channel"],"exampleFix":"// before\nblk, err := store.RetrieveBlockByNumber(n)\n// after\nif n >= info.Height { return nil }\nblk, err := store.RetrieveBlockByNumber(n)","handlingStrategy":"retry","validationCode":"func blockInRange(ledger lgr.PeerLedger, num uint64) (bool, error) {\n    bc, err := ledger.GetBlockchainInfo()\n    if err != nil { return false, err }\n    return num < bc.Height, nil\n}","typeGuard":"func canFetchByNumber(num, height uint64) bool { return num < height }","tryCatchPattern":"var blk *common.Block\nvar err error\nfor i := 0; i < maxRetries; i++ {\n    blk, err = store.RetrieveBlockByNumber(n)\n    if err == nil || !strings.Contains(err.Error(), \"no such block number\") { break }\n    time.Sleep(pollInterval) // block may not be committed yet\n}","preventionTips":["Always check GetBlockchainInfo().Height before by-number fetch","Remember block numbers are 0-based: max valid number is Height-1","Use bounded retry/backoff when polling for pending blocks","Confirm channel correctness when numbers come from external sources"],"tags":["hyperledger-fabric","blockchain","ledger-index","not-found"],"backgroundTag":"block-not-found","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"}