This repository contains a set of scripts designed to analyze Bitcoin blocks, identify which mining pools mined each block, and extract detailed information such as block weights and coinbase transaction data. These scripts read blocks directly from the Bitcoin Core data directory within a specified interval.
The read_blocks.py script reads blocks from disk using the libbitcoinkernel library, accessed through Python wrappers available at py-bitcoinkernel.
- Install the Python wrapper for
libbitcoinkernelcorrectly as described in its documentation. - Stop the
bitcoindprocess before running this script.
Run the script with the following command:
python3 read_blocks.py --datadir=<directory> --chain_type=<chain> --start_height=<height> --end_height=<height> --output=<directory>--datadir: Path to the Bitcoin Core data directory. This allowslibbitcoinkernelto access block data.--chain_type: Specify the blockchain network (main,signet, ortestnet).--start_height: Block height to begin analysis.--end_height: Block height to stop analysis.--output: Directory where results will be saved (this directory must exist). Results will also appear in the./outputdirectory (There are some sample output there).
Note: The script's runtime depends on the block interval specified. For larger intervals, execution can take minutes to hours.
This script identifies the mining pool associated with each block by analyzing the scriptSig of the coinbase transaction. It uses an open-source list of mining pool tags from bitcoin-data/mining-pools, which is stored locally as pool-list.json.
Processes and consolidates the results of the block analysis for further evaluation.
The ./graphs directory contains scripts to visualize analysis results. These scripts generate various graphs using pandas, seaborn, and matplotlib.
Install the required libraries in a Python virtual environment:
pip install pandas seaborn matplotlib-
plt_large_coinbase_fig.py
Generates a box plot showing the distribution of coinbase transaction weights for pools that produce blocks with coinbase weights greater than 4000 WU. -
plt_coinbase_weights_fig.py
Creates a line chart displaying the average, minimum, and maximum coinbase transaction weights for various mining pools. -
plt_block_weights_fig.py
Produces a line chart illustrating the average, minimum, and maximum block weights for various mining pools.