Skip to content

Instantly share code, notes, and snippets.

@l0rinc
Last active February 17, 2025 20:26
Show Gist options
  • Save l0rinc/83d2bdfce378ad7396610095ceb7bed5 to your computer and use it in GitHub Desktop.
Save l0rinc/83d2bdfce378ad7396610095ceb7bed5 to your computer and use it in GitHub Desktop.

This guide helps you compare the performance of two different versions of Bitcoin Core during the initial block download (IBD) process. You will run two builds and share the results.

Background and Purpose

I am working on improving the performance of the first phase of Bitcoin Core, specifically the process of downloading and validating the blockchain on a fresh machine. I have proposed several modifications that, based on my own measurements, result in measurable speed improvements. However, to ensure broader acceptance, I need help reproducing these results by having others run similar tests.

This is a technical process (though not overly complex, in my opinion), requiring the source code to be compiled. The goal is to validate these improvements on multiple setups and environments, which will help accelerate their adoption.

Requirements:

  • A GitHub account (to follow the discussion and results).
  • A Linux-based system (e.g., Ubuntu/Debian).
  • At least 1 TB of free space for blockchain data (temporary, can be deleted afterward).

Important: To keep the environment as consistent as possible, make sure no other applications or tasks are running on the machine during the experiment (can take several days).

Ideally, leave the machine idle for the duration of the test to avoid variability in the results.

Step 1: Install Required Packages

Install the necessary packages (on Debian/Ubuntu). Only install packages from trusted sources!

apt update && apt upgrade -y
apt install -y bsdmainutils build-essential ccache clang cmake curl git htop libboost-chrono-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-test-dev libboost-thread-dev libdb++-dev libdb-dev libevent-dev libgmp-dev libminiupnpc-dev libsqlite3-dev libssl-dev libtool libzmq3-dev llvm pkg-config python3 python3-zmq python3-pip hyperfine

Step 2: Download Bitcoin Core Source Code

Download the Bitcoin Core source code and fetch the two commits you want to compare (I’m not telling you which is "before" and which is "after", the results should speak for themselves).

git clone https://github.com/bitcoin/bitcoin.git && cd bitcoin
git fetch origin 5acf12bafeb126f2190b3f401f95199e0eea90c9 caa68f79c11e5c444977ce8dee8a43020b7b3c5a

Step 3: Prepare Blockchain Data Directory

Create a directory for blockchain data. This directory will require around 1 TB of free space but can be deleted after the experiment.

mkdir -p BitcoinData BitcoinData-logs

Step 4: Build the Bitcoin Core Binaries

Build the Bitcoin Core binaries using the following commands:

cmake -B build && cmake --build build -j4

Step 5: Run the Test

Let’s get to testing! \:D/ Note that you will need at least 16 Gb memory - otherwise lower DBCACHE to e.g. 500. Use hyperfine for automation (or you can do it manually if you can keep track of the changes):

STOP_HEIGHT=880000; \
COMMITS=5acf12bafeb126f2190b3f401f95199e0eea90c9,0e9fb2ed330960c0e4cd36b077c64ac7d0f84240; \
DBCACHE=5000; \
hyperfine \
--runs 3 \
--parameter-list COMMIT $COMMITS \
--prepare "rm -rf BitcoinData/* build/ && git checkout {COMMIT} && git clean -fxd && git reset --hard && cmake -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_WALLET=OFF && cmake --build build -j$(nproc) --target bitcoind && ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=1 -printtoconsole=0 || true" \
--cleanup "cp /mnt/my_storage/BitcoinData/debug.log /mnt/my_storage/logs/debug-{COMMIT}-$(date +%s).log" \
"COMMIT={COMMIT} ./build/src/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=$STOP_HEIGHT -dbcache=$DBCACHE -printtoconsole=0"

You can also vary the number of runs (to test it in a different setting), e.g. --runs 2 or DBCACHE=10000 or -stopatheight=800000 or compile with CLang (cmake -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_WALLET=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++).

Step 6: Document Your Setup and Share the Results

Post your results to bitcoin/bitcoin#31144 - making sure to include these details in your report:

  • hyperfine output (or the gist of BitcoinData-logs/*.json)
  • CPU type.
  • Whether you used an SSD or HDD.
  • Internet connection speed.
  • Any other relevant information about your environment.

Don't be too verbose, but share the important data (see previous replies for inspiration).

Thanks!

@mlori
Copy link

mlori commented Jan 14, 2025

  1. Just a remark. Using ~/BitcoinData in the parameters of hyperfine, fails for me with the following error:
    Error: Specified data directory "~/BitcoinData" does not exist.
    However, providing the full path, like /home/myUser/BitcoinData it works.

  2. The name of the created logfiles does not contain the commitId, but the COMMIT placeholder, is this intended? See:
    ls ~/BitcoinData-logs XOR-{COMMIT}-1736851992.json ...

Shouldn't the commitID be injected by Hyperfine when the file is created, based on the provided parameter list for COMMIT?

@l0rinc
Copy link
Author

l0rinc commented Jan 14, 2025

Fixed both, thanks!

@mlori
Copy link

mlori commented Jan 14, 2025

The working directory is in bitcoin/ so use rather ..BitcoinData/ and ..BitcoinData-logs/, with .. by pointing to the parent directory of the current directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment