Bitcoin Header Node (BHN) is a lightweight Bitcoin node that syncs and persists Bitcoin block headers. Developers can now verify Chainpoint proofs without needing a full Bitcoin node or a third-party API provider. BHN runs locally, syncs in an hour, and uses just 30MB of disk space. It’s written in Javascript and built with bcoin. Today, we’re releasing a beta version of BHN and looking for developer feedback.

http://github.com/chainpoint/bitcoin-header-node

Video Demo

Buck Perley gives an overview of BHN in this seven minute demo.

Why We Built BHN

Developers told us they wanted to verify Chainpoint proofs without needing to run a full Bitcoin node, or use an API provider such as Blockcypher. We built BHN to make it simple to verify a Chainpoint proof.

Chainpoint proofs are used to verify the integrity and timestamp of any data. Each Chainpoint proof contains a series of operations that commits some data to a Bitcoin block header. With just a Chainpoint proof (~1kb) and an 80 byte block header you can prove the integrity and timestamp of any data. You simply process the operations in the Chainpoint proof to calculate an expected hash value. The proof is valid if the hash matches the Merkle Root in a Bitcoin block header.

Learn more about Chainpoint

BHN provides a lightweight way to check if the Merkle Root in your Chainpoint proof exists in a Bitcoin block, without using a third-party api or running a Bitcoin full node. Before BHN, the lightest alternative would be an SPV (Simplified Payment Verification) node which requires about 170MB of disk space. While this is less than the ~200GB of disk space needed by a Bitcoin Full Node, we wanted to see if we could build something light enough to run in a browser extension or mobile device.

To reach this goal, we focused on two areas:

  1. BHN strips out all data not necessary to validate block headers and Bitcoin’s Proof-of-Work

  2. BHN can ignore blocks earlier than a specific block height

Because the Chainpoint protocol launched in 2015, the oldest block you could need for verification is January 1st, 2015. Earlier blocks don’t need to be downloaded.

BHN with all of the relevant blocks for verifying Chainpoint proofs is approximately 30MB and syncs in an hour. An SPV node takes a couple hours to sync, and requires over 5x more storage. A full node requires over 6,600x more disk space and can take days to sync.

How BHN Works

BHN connects to Bitcoin nodes, syncs headers from a specified block height, verifies Proof-of-Work locally, and exposes an API that lets you get header data. Let’s start by setting up BHN and showing how we’re incorporating it into Chainpoint.

Installing BHN

BHN can be installed via npm or downloaded directly from the GitHub repo. It can also be installed as a package and used within a JS project just like a normal bcoin node.

To startup BHN from a custom start height* all you have to do is run the following commands:

$ npm install -g bhn #installs bhn in your global node_modules directory

$ bhn --start-height=337022

You can use the HTTP API to interact with BHN. Most options available on a normal bcoin node can be passed to a BHN node. This can be done with curl, the CLI tool bclient, or in a JS script. For all available methods, see the BHN readme on GitHub and the bcoin API docs.

Chainpoint CLI Integration

We have integrated BHN directly into an upcoming version of the Chainpoint CLI. Using the same CLI tool you use to interact with the Chainpoint network, you can:

  • start and stop a bhn node

  • check BHN’s status

  • get a block header

  • execute many bitcoin RPC methods

Best of all, the Chainpoint CLI will verify all proofs against BHN, if you have one running. If you don’t run BHN, the CLI will fallback to asking remote Chainpoint nodes.

Built using Bcoin

BHN is built using bcoin, a JavaScript Bitcoin library that lets developers create a variety of Bitcoin tools including wallets, full nodes, or even a Bitcoin miner. Bcoin’s unique characteristics make it ideal for BHN:

Javascript

Bcoin is written in Javascript, which allows BHN to run on a wide range of different platforms — even in the browser!

Modular Design

Bcoin’s modular architecture makes it simple to include only the modules your application needs. This was key to creating a lightweight BHN. Many modules of a Bitcoin Full Node weren’t required. BHN needed a database for persisting the header information, an http/RPC server for communication, a network pool for communicating with peers, and an ephemeral chain for tracking and verifying incoming blocks. BHN didn’t need things like a mempool, wallet, miner, or to persist full block data.

Indexer Interface

A recent bcoin update added an Indexer interface, which listens for events that indicate a new block has been received and then indexes relevant data. We extended this Indexer interface, to persist a database of only the block header data that we need.

Next Steps

We hope developers find Bitcoin Header Node useful. Try BHN for yourself, review the code, and leave any comments, questions, or requests on GitHub.