brk_parser
High-performance Bitcoin block parser for raw Bitcoin Core block files
brk_parser
provides efficient sequential access to Bitcoin Core's raw block files (blkXXXXX.dat
), delivering blocks in height order with automatic fork filtering and XOR encryption support. Built for blockchain analysis and indexing applications that need complete Bitcoin data access.
What it provides
- Sequential block access: Blocks delivered in height order (0, 1, 2, ...) regardless of physical file storage
- Fork filtering: Automatically excludes orphaned blocks using Bitcoin Core RPC verification
- XOR encryption support: Transparently handles XOR-encrypted block files
- High performance: Multi-threaded parsing with ~500MB peak memory usage
- State persistence: Caches parsing state for fast restarts
Key Features
Performance Optimization
- Multi-threaded pipeline: 3-stage processing (file reading, decoding, ordering)
- Parallel decoding: Uses rayon for concurrent block deserialization
- Memory efficient: Bounded channels prevent memory bloat
- State caching: Saves parsing state to avoid re-scanning unchanged files
Bitcoin Integration
- RPC verification: Uses Bitcoin Core RPC to filter orphaned blocks
- Confirmation checks: Only processes blocks with positive confirmations
- Height ordering: Ensures sequential delivery regardless of storage order
XOR Encryption Support
- Transparent decryption: Automatically handles XOR-encrypted block files
- Streaming processing: Applies XOR decryption on-the-fly during parsing
Usage
Basic Block Parsing
use Parser;
use Height;
use ;
// Setup RPC client (must have static lifetime)
let rpc = Box leak;
// Create parser
let parser = new;
// Parse all blocks sequentially
parser.parse
.iter
.for_each;
Range Parsing
// Parse specific height range
let start = Some;
let end = Some;
parser.parse
.iter
.for_each;
Single Block Access
// Get single block by height
let genesis = parser.get;
println!;
Real-world Usage Example
use Parser;
use Block;
Output Format
The parser returns tuples for each block:
Height
: Block height (sequential: 0, 1, 2, ...)Block
: Complete block data from thebitcoin
crateBlockHash
: Block's cryptographic hash
Performance Characteristics
Benchmarked on MacBook Pro M3 Pro:
- Full blockchain (0 to 855,000): ~4 minutes
- Recent blocks (800,000 to 855,000): ~52 seconds
- Peak memory usage: ~500MB
- Restart performance: Subsequent runs much faster due to state caching
Requirements
- Running Bitcoin Core node with RPC enabled
- Access to Bitcoin Core's
blocks/
directory - Bitcoin Core versions v25.0 through v29.0 supported
- RPC authentication (cookie file or username/password)
State Management
The parser saves parsing state in {output_dir}/blk_index_to_blk_recap.json
containing:
- Block file indices and maximum heights
- File modification times for change detection
- Restart optimization metadata
Note: Only one parser instance should run at a time as the state file doesn't support concurrent access.
Dependencies
bitcoin
- Bitcoin protocol types and block parsingbitcoincore_rpc
- RPC communication with Bitcoin Corecrossbeam
- Multi-producer, multi-consumer channelsrayon
- Data parallelism for block decodingserde
- State serialization and persistence
This README was generated by Claude Code