Date: 2024-12-08, Africa Bitcoin Conference 2024
In this workshop, we'll build a simple block data analysis tool. Rather than use the Bitcoin Core RPC interface, or parse raw block files, we'll be using the experimental, unreleased libbitcoinkernel. This workshop is aimed at more seasoned developers, please make sure to check you feel comfortable with the [[#Prerequisites]] listed below.
The libbitcoinkernel project is a new attempt at extracting Bitcoin Core's consensus engine. The kernel part of the name highlights one of the key functional differences from the deprecated libbitcoinconsensus and in fact, most libraries: it is a stateful library that can spawn threads, do caching, do I/O, and many other things that one may not normally expect from a library.
The workshop will be hosted using Python, but participants that prefer working with Rust, C or C++ are welcome to do so, and (limited) supporting materials in those languages will be provided.
- libbitcoinkernel: Extracting Bitcoin Core's consensus engine: https://www.youtube.com/watch?v=MdxIkH6GCBs&ab_channel=CarlDong
- The road ahead: https://thecharlatan.ch/Kernel/
- Project Tracking: bitcoin/bitcoin#27587
- C header API: bitcoin/bitcoin#30595
- basic knowledge of the Bitcoin protocol and consensus rules
- basic understanding of memory management and pointers
- comfortable building a Python, Rust, C or C++ project from scratch
Ahead of the workshop, make sure you've installed the shared bitcoinkernel
library to ensure you have all required dependencies, and to avoid wasting too much time compiling it. You also need to have a pre-synced (any chain, and not necessarily very recent) Bitcoin Core datadir, since that's what your application will be doing the data analysis on.
This step is required for everyone. Platform-specific compilation instructions are available in the various build-<platform>.md
documents on https://github.com/bitcoin/bitcoin/tree/master/doc.
Once you've installed all the dependencies, you should be able to install the shared bitcoinkernel
library as follows:
NUM_CORES=4
git clone https://github.com/TheCharlatan/bitcoin kernel
cd kernel
git checkout 35f8503285c672e8ee7e98617e236b38d8ce7a7f
cmake -B build -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON
cmake --build build -j $(NUM_CORES) && --install build
Note: you may need sudo
for the last step: sudo cmake --install build
bitcoinkernel
operates on a Bitcoin Core data directory. In this workshop, we'll be analyzing TapScript usage. To avoid having to sync the chain during the workshop, make sure you have a copy of a somewhat recent Bitcoin Core data directory available. Specifically, we need the blocks/
and chainstate/
directories. You can use any chain you like, but I would suggest using signet
or mainnet
.
I will have a USB thumbdrive with me containing a recent signet
chain to help bootstrap this if you're unable to get this downloaded ahead of time.