Crate bitcoin_block_parser

source
Expand description

§Bitcoin Block Parser

Crates.io Docs MIT licensed

Fast optimized parser for the bitcoin blocks data with UTXO tracking.

⚠️ The API is still evolving and should not be considered stable until release 1.0.0

§Features

  • Parses blocks into the Rust bitcoin Block format for easier manipulation
  • Can track whether any TxOut in a Transaction is spent or unspent
  • Can track the Amount of every TxIn for calculating metrics such as fee rates
  • Or implement your own custom multithreaded BlockParser
  • Uses many optimizations to provide the best block parsing performance

§Requirements / Benchmarks

  • You must be running a non-pruning bitcoin node (this is the default configuration)
  • You should look at the table below to understand how much RAM you need (tunable through Options)
  • We recommend using fast storage and a multithreaded CPU for best performance

Our benchmarks were run on NVMe storage with a 32-thread processor on 850,000 blocks:

FunctionTimeMemory
DefaultParser5 min3.5 GB
FilterParser17 min9.3 GB
UtxoParser39 min17.5 GB

§Quick Usage

use bitcoin_block_parser::*;

// Iterates over all the blocks in the directory
for block in DefaultParser.parse_dir("/home/user/.bitcoin/blocks").unwrap() {
  // Do whatever you want with the parsed block here
  block.unwrap().check_witness_commitment();
}

Re-exports§

Modules§

  • The BlockParser trait allows you to implement a custom parser or use one of the predefined ones.
  • Use HeaderParser to read from your node’s blocks directory.
  • The FilterParser and UtxoParser parser must be used together in order to track UTXOs as they move through the tx graph, giving you a map between: