Bitcoin in Practice: ChainTracker

By Kurt Wuckert Jr.

ChainTracker: the node’s “where are we right now?” system

A node has a lot of jobs, but before it can do anything useful, it has to answer one question correctly: what is the current longest chain of blocks? That is the primary responsibility of ChainTracker.

ChainTracker does what the name implies. It tracks the chain, stays aware of new blocks as they are discovered, and keeps the node aligned with the rest of the network.

Staying in sync with the network

ChainTracker listens for messages coming in through the node’s networking layer (BSN). When another node announces it has discovered a new block, ChainTracker responds to that event and updates the node’s internal state so the node stays in sync with what is happening externally.

If the node falls behind, ChainTracker coordinates the catch-up process. It orchestrates block downloading in cooperation with block download and storage services, then passes the downloaded blocks into Block Validator so they can be checked.

What ChainTracker stores

ChainTracker maintains the block headers that make up the chain. A block header is a compact summary of a block that lets you link blocks together and identify the chain without needing all transaction data immediately.

For each block header, ChainTracker also stores a bit of metadata, basically a place to keep useful facts about that block as the node sees it. The material lists examples of this metadata, including:

  • Number of transactions

  • Download timestamp

  • Download source

  • Validation timestamp

  • Number of validations (for cases where a block needs to be downloaded and validated again, such as when a block is corrupted)

This is practical bookkeeping. It tells the node not only what the chain is, but also what it has done with each part of that chain.

Building the chain from Genesis to the tip

ChainTracker queries peers in the network to get block headers, allowing it to build the chain internally from the Genesis block up to the current tip.

While blocks are being validated, ChainTracker tracks that process and keeps other components informed. It makes sure the rest of the node knows when blocks have been validated, and also when blocks are invalidated.

How ChainTracker coordinates with other node systems

ChainTracker is a central coordinator. It interacts with several other subsystems to keep the node consistent:

Tip Manager

ChainTracker interacts with the Tip Manager, which monitors incoming communication from other nodes through BSN and receives their announced tip IDs. That is part of how the node learns, “this is the latest chain tip other nodes are building on.”

Mempool and “pool rebase”

ChainTracker also talks to the mempool, the holding area for valid transactions waiting to be included in a block.

The mempool needs to be aligned to the active tip. If ChainTracker updates what it believes is the correct, valid tip ID, it sends a message to the mempool to realign. That realignment process is called pool rebase.

UTXO storage

Finally, ChainTracker interacts with UTXO storage services. UTXOs are the current spendable outputs, so their state must match the chain the node considers authoritative.

By keeping UTXO storage aligned to the longest chain tip recognized by the network, the node ensures UTXO status is correct based on the chain with the most proof of work.

ELI15(ish...)

Picture bitcoin like a shared notebook that a big group is writing in. Every 10 minutes or so, someone adds a new page. The “longest chain” is just the notebook stack that has the most pages in order.

ChainTracker is the part of a node that constantly checks, “Which notebook stack is the real one right now?”

  • It listens when other people say, “We added a new page.”

  • If your notebook is missing pages, it goes and downloads the pages you missed.

  • It keeps a list of page summaries (headers) so it can track the whole notebook from the first page to the newest page.

  • It tells other parts of the node, “This is the current newest page, line up with this.”

The mempool is like a tray of sticky notes with transactions waiting to be written into the next page. If ChainTracker switches to a different “newest page,” it tells the tray to line up with that page again. That reset is what the text calls a pool rebase.

And the UTXO set is like your wallet’s list of spendable cash slips. If you are looking at the wrong notebook stack, your wallet list can be wrong too. ChainTracker helps keep everything synced to the chain with the most work behind it.