The Blockchain Chief Bitcoin Book / Part IV: Advanced Features
Chapter 14

Architecture & Evolution

The ongoing effort to modularize Bitcoin Core: extracting the consensus engine into libbitcoinkernel, splitting processes via IPC, protecting against peer abuse, and supporting privacy networks.

libbitcoinkernel

The most ambitious ongoing refactor in Bitcoin Core is the extraction of consensus-critical code into a standalone library called libbitcoinkernel. The goal: any project can link against this library and validate blocks identically to Bitcoin Core, without pulling in networking, wallet, or GUI code.

Why It Matters

Bitcoin's consensus rules are scattered across dozens of source files, interwoven with P2P networking, RPC handling, and wallet logic. This coupling creates several problems:

The C API

libbitcoinkernel exposes a pure C API through kernel/bitcoinkernel.h, using opaque pointer types for safety and ABI stability:

btck_Context context Holds callbacks and state for validation events
btck_ChainstateManager chainstate_manager Central validation object: UTXO set, block index, active chain
btck_Block block Deserialized block, ready for validation
btck_Transaction transaction A single transaction with inputs and outputs
btck_ScriptPubkey script_pubkey Output script for script verification

What You Can Do

Design Principles

💡 Work in Progress

As of 2025, libbitcoinkernel is functional but not yet included in official releases. The API is unversioned and subject to breaking changes. The long-term vision is a stable, versioned library that alternative node implementations and tools can depend on safely.

Multiprocess Architecture

Bitcoin Core is historically a single monolithic process: node, wallet, and GUI all run in the same address space. The multiprocess project splits these into separate OS processes communicating over IPC (inter-process communication).

The Interfaces Layer

Before multiprocess, an abstraction layer was built: the interfaces/ directory defines clean boundaries between subsystems:

IPC via Cap'n Proto

The multiprocess framework uses Cap'n Proto for serialization and communication between processes. Each interface is described in a .capnp schema file, and the framework generates proxy objects that transparently forward method calls across process boundaries.

bitcoin-nodeRuns validation, mempool, P2P networking. The core consensus process.
↔ Cap'n Proto IPC
bitcoin-walletManages keys, creates and signs transactions. Communicates via interfaces::Chain.
↔ Cap'n Proto IPC
bitcoin-guiQt-based UI. Communicates via interfaces::Node and interfaces::Wallet.

Benefits

Peer Eviction Logic

Bitcoin Core limits the number of inbound connections (default: 125 total, with a portion reserved for inbound). When a new inbound peer connects and slots are full, the node must decide which existing peer to evict. The eviction algorithm aims to keep a diverse, useful set of peers while resisting eclipse attacks.

Protection Criteria

Before eviction, peers are protected in several rounds:

  1. 4 peers with lowest ping time: fast peers are valuable for block relay
  2. 4 peers that most recently sent us transactions: actively relaying peers
  3. 4 peers that most recently sent us blocks: important for staying in sync
  4. Up to 8 peers on privacy networks: Tor, I2P, and CJDNS peers are protected by ratio to preserve network diversity
  5. Half of remaining peers by longest connection time: long-lived connections are harder for an attacker to establish

Eviction Selection

After protection rounds, if any candidates remain, the algorithm groups them by network group (based on IP prefix). The network group with the most candidates loses one peer: the one connected most recently. This prevents an attacker from monopolizing connections from a single network range.

💡 Why Protect Privacy Networks?

Tor and I2P peers typically have higher latency than IPv4/IPv6. Without special protection, they would be systematically evicted due to high ping times, reducing the network's resilience against surveillance and partitioning attacks. The ProtectEvictionCandidatesByRatio() function reserves slots specifically for these peers.

Privacy Networks

Bitcoin Core supports multiple privacy-preserving network transports, allowing nodes to operate without revealing their IP address.

Tor (The Onion Router)

I2P (Invisible Internet Project)

CJDNS

ZMQ Notifications

Bitcoin Core can push real-time notifications to external applications using ZeroMQ (ZMQ) publish-subscribe sockets. This is faster than polling RPC.

Available Topics

zmqpubhashtx Transaction hash when it enters the mempool or is confirmed
zmqpubhashblock Block hash when a new block is connected
zmqpubrawtx Full serialized transaction (raw bytes)
zmqpubrawblock Full serialized block (raw bytes)
zmqpubsequence Sequence notifications: mempool add/remove, block connect/disconnect

Configuration

Each topic binds to a separate ZMQ endpoint: -zmqpubhashtx=tcp://127.0.0.1:28332. Subscribers connect to these endpoints and receive a continuous stream of notifications. Each message includes a sequence number to detect missed messages.

REST Interface

Bitcoin Core includes a lightweight REST API (enabled with -rest) for retrieving blockchain data without RPC authentication.

Available Endpoints

Responses are available in JSON (.json), binary (.bin), or hex (.hex) formats. The REST interface is read-only; it cannot submit transactions or modify state.