Bitcoin Core Block Filter Index: BIP158 Storage and RPC Queries
Bitcoin Core's optional block filter index builds compact representations of blocks for efficient wallet discovery. The basic filter defined by BIP158 encodes relevant output scripts and scripts of spent previous outputs. A wallet can test its own scripts against a filter without requesting every complete block.
Index construction
Enable the basic filter index with blockfilterindex=1. Bitcoin Core derives filters from validated block data and the information needed to identify spent previous outputs. Basic filters exclude output scripts beginning with OP_RETURN and omit empty scripts according to the specification.
The Golomb-coded set representation is probabilistic: matching scripts can produce false positives. A correctly constructed filter does not omit an element that the specification requires it to include. A wallet must retrieve and inspect matching blocks to establish actual transaction relevance.
Filter headers and RPC
Filter headers link successive filter hashes, allowing clients to check consistency across a sequence. They are separate from Bitcoin block headers and are not committed to by the proof-of-work block header.
````
bitcoin-cli getindexinfo
bitcoin-cli getblockfilter "$BLOCKHASH" basic
The getblockfilter result contains the encoded filter and its filter header. The caller should obtain block hashes from the intended active chain and handle reorganizations explicitly. A filter match alone is not a transaction inclusion proof or a confirmation.
Local indexing versus peer service
Building a local filter index and serving filters to remote peers are separate operational choices. The peerblockfilters option controls BIP157 peer service in supported Bitcoin Core releases and requires the basic index. An application using local RPC does not need to expose that peer service simply to query its own index.
Pruning and historical retrieval
A synchronized filter index can retain compact filters after the corresponding raw blocks are pruned. This does not restore the discarded block contents. A wallet may discover a historical match but still need to retrieve the full block from another source. Initial indexing needs the relevant historical data, so enabling the index late on a pruned node can require a rebuild.
Design guidance
Store scan checkpoints with both height and block hash. On a reorganization, rewind to the common ancestor and process replacement filters. Verify retrieved blocks and transactions according to the application's trust model. Compact filters are a discovery optimization, not a substitute for consensus validation.
Primary references
BIP157: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
BIP158: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
Bitcoin Core filter index: https://github.com/bitcoin/bitcoin/blob/master/src/index/blockfilterindex.cpp
