{"record":{"id":"6ae021c17d7ab087","repo":"hyperledger/fabric","slug":"no-such-block-hash-x-in-index","errorCode":null,"errorMessage":"no such block hash [%x] in index","messagePattern":"no such block hash \\[%x\\] in index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/blockindex.go","lineNumber":163,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc (index *blockIndex) isAttributeIndexed(attribute IndexableAttr) bool {\n\t_, ok := index.indexItemsMap[attribute]\n\treturn ok\n}\n\nfunc (index *blockIndex) getBlockLocByHash(blockHash []byte) (*fileLocPointer, error) {\n\tif !index.isAttributeIndexed(IndexableAttrBlockHash) {\n\t\treturn nil, errors.New(\"block hashes not maintained in index\")\n\t}\n\tb, err := index.db.Get(constructBlockHashKey(blockHash))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif b == nil {\n\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)","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockindex.go#L145-L181","documentation":"Redundant duplicate slot kept intentionally: same error as errorIndex 280 — 'no such block hash [%x] in index' from blockIndex.getBlockLocByHash when the index DB has no entry for constructBlockHashKey(blockHash). It signals a lookup miss in the block index, not a DB failure.","triggerScenarios":"retrieveBlockByHash is called with a hash absent from the index: wrong channel, undecoded hex string passed as bytes, or the index lacks the hash entry (index not synced, rebuilt, or partially lost).","commonSituations":"Cross-channel hash lookups, string-vs-bytes hash handling mistakes, peers with index DBs wiped or recreated without reindexing, snapshots restored without the index.","solutions":["Confirm the hash belongs to this ledger by retrieving the block by number and comparing hashes","Decode hex to raw bytes before lookup","Re-sync/rebuild the block index if entries are missing","Check index configuration includes block-hash indexing"],"exampleFix":"// before\nblk, err := store.RetrieveBlockByHash([]byte(hexHash))\n// after\nraw, _ := hex.DecodeString(hexHash)\nblk, err := store.RetrieveBlockByHash(raw)","handlingStrategy":"validation","validationCode":"func blockHashIndexed(ledger lgr.PeerLedger, hash []byte) (bool, error) {\n    bc, err := ledger.GetBlockchainInfo()\n    if err != nil { return false, err }\n    blk, err := ledger.GetBlockByNumber(bc.Height - 1)\n    if err != nil { return false, err }\n    if len(blk.Data.Hash) == 0 { return false, errors.New(\"index may not maintain block hashes\") }\n    _ = hash // compare against known block hashes or verify via header before lookup\n    return true, nil\n}","typeGuard":"func is32ByteHash(b []byte) bool { return len(b) == 32 }","tryCatchPattern":"blk, err := store.RetrieveBlockByHash(hash)\nif err != nil {\n    if strings.Contains(err.Error(), \"no such block hash\") {\n        return nil, ErrBlockNotIndexed // handle as not-found, not fatal\n    }\n    return err\n}","preventionTips":["Decode hex hashes to raw bytes before calling RetrieveBlockByHash","Verify the hash belongs to the target channel's ledger first","Do not disable hash indexing in blockIndexConfig","After restoring snapshots or wiping index DBs, let the peer rebuild/sync the index before serving hash lookups"],"tags":["hyperledger-fabric","blockchain","leveldb","ledger-index"],"backgroundTag":"block-index-miss","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"}