#block #iterator #bitcoin #parser #bitcoin-rust

brk_parser

A very fast Bitcoin Core block parser and iterator built on top of bitcoin-rust

28 releases

Uses new Rust 2024

new 0.0.27 Apr 18, 2025
0.0.26 Apr 18, 2025
0.0.11 Mar 31, 2025
0.0.2 Feb 27, 2025

#30 in Magic Beans

Download history 262/week @ 2025-02-21 583/week @ 2025-02-28 195/week @ 2025-03-07 201/week @ 2025-03-14 88/week @ 2025-03-21 238/week @ 2025-03-28 1048/week @ 2025-04-04 449/week @ 2025-04-11

1,881 downloads per month
Used in 6 crates (5 directly)

MIT license

115KB
4K SLoC

BRK Parser

GitHub Repo stars kibo.money License Version Documentation Size Dependency status Discord Nostr Bluesky X

A very fast and simple Rust library which reads raw block files (blkXXXXX.dat) from Bitcoin Core node and creates an iterator over all the requested blocks in sequential order (0, 1, 2, ...).

The element returned by the iterator is a tuple which includes the:

  • Height: Height
  • Block: Block (from bitcoin-rust)
  • Block's Hash: BlockHash (also from bitcoin-rust)

Tested with Bitcoin Core v25.0..=v28.1

Requirements

Even though it reads blkXXXXX.dat files, it needs bitcoind (with no particular parameters) to run with the RPC server to filter out forks.

Peak memory should be around 500MB.

XOR-ed blocks are supported.

Disclaimer

A state of the local chain is saved in {bitcoindir}/blocks/blk_index_to_blk_recap.json to allow for faster starts (see benchmark below) but doesn't yet support locking. Thus, it is highly recommended to run one instance of brk_parser at a time.

Benchmark

brk_parser bitcoin-explorer (deprecated) blocks_iterator*
Runs with bitcoind Yes ✅ No ❌ Yes ✅
Runs without bitcoind No ❌ Yes ✅ Yes ✅
0..=855_000 4mn 10s 4mn 45s > 2h
800_000..=855_000 0mn 52s (4mn 10s if first run) 0mn 55s > 2h

* blocks_iterator is with the default config (and thus with skip_prevout = false which does a lot more than just iterate over blocks) so it isn't an apples to apples comparaison and the numbers are misleading. You should expect much closer times. Will update the benchmark with skip_prevout = true as soon as possible.

Benchmarked on a Macbook Pro M3 Pro

Dependencies

~17MB
~252K SLoC