hyperledger/fabric · error
no such block hash [%x] in index
Error message
no such block hash [%x] in index
What it means
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.
Source
Thrown at common/ledger/blkstorage/blockindex.go:163
}
return nil
}
func (index *blockIndex) isAttributeIndexed(attribute IndexableAttr) bool {
_, ok := index.indexItemsMap[attribute]
return ok
}
func (index *blockIndex) getBlockLocByHash(blockHash []byte) (*fileLocPointer, error) {
if !index.isAttributeIndexed(IndexableAttrBlockHash) {
return nil, errors.New("block hashes not maintained in index")
}
b, err := index.db.Get(constructBlockHashKey(blockHash))
if err != nil {
return nil, err
}
if b == nil {
return nil, errors.Errorf("no such block hash [%x] in index", blockHash)
}
blkLoc := &fileLocPointer{}
if err := blkLoc.unmarshal(b); err != nil {
return nil, err
}
return blkLoc, nil
}
func (index *blockIndex) getBlockLocByBlockNum(blockNum uint64) (*fileLocPointer, error) {
if !index.isAttributeIndexed(IndexableAttrBlockNum) {
return nil, errors.New("block numbers not maintained in index")
}
b, err := index.db.Get(constructBlockNumKey(blockNum))
if err != nil {
return nil, err
}
if b == nil {
return nil, errors.Errorf("no such block number [%d] in index", blockNum)View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before blk, err := store.RetrieveBlockByHash([]byte(hexHash)) // after raw, _ := hex.DecodeString(hexHash) blk, err := store.RetrieveBlockByHash(raw)
Defensive patterns
Strategy: validation
Validate before calling
func blockHashIndexed(ledger lgr.PeerLedger, hash []byte) (bool, error) {
bc, err := ledger.GetBlockchainInfo()
if err != nil { return false, err }
blk, err := ledger.GetBlockByNumber(bc.Height - 1)
if err != nil { return false, err }
if len(blk.Data.Hash) == 0 { return false, errors.New("index may not maintain block hashes") }
_ = hash // compare against known block hashes or verify via header before lookup
return true, nil
} Type guard
func is32ByteHash(b []byte) bool { return len(b) == 32 } Try / catch
blk, err := store.RetrieveBlockByHash(hash)
if err != nil {
if strings.Contains(err.Error(), "no such block hash") {
return nil, ErrBlockNotIndexed // handle as not-found, not fatal
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: Cross-channel hash lookups, string-vs-bytes hash handling mistakes, peers with index DBs wiped or recreated without reindexing, snapshots restored without the index.
Related errors
- block numbers not maintained in index
- no such block number [%d] in index
- transaction IDs not maintained in index
- error while trying to check the presence of TXID [%s]
- error in block index: %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/6ae021c17d7ab087.
Report an issue: GitHub.