# The most-work chain

> How Pearl nodes choose between competing branches: most total work, plus a quarter-block margin (the code comment says half). Ties, reorgs and confirmations.

Source: https://pearlcodex.com/technical/blockchain/most-work-chain/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

Mining is a lottery, and sometimes two people win almost at once. Two miners each find a valid block on top of the same parent, a few seconds apart, and send them out. Half the network hears about one first, half about the other. For a moment, the chain has two tips.

Nodes need a rule to settle this without talking it over. The rule is the same idea as Bitcoin’s: follow the branch with the most work. Pearl adds one twist, a safety margin before switching.

## Try it

Build a short chain, then edit a block and watch every block after it break. The heavier unbroken chain is the one nodes keep.

_Interactive: A chain of blocks. Try it on the page: <https://pearlcodex.com/technical/blockchain/most-work-chain/>_

## Which branch do nodes follow?

The valid one with the most total [work](https://pearlcodex.com/glossary/#chain-work). Each block’s work is 2²⁵⁶ ÷ (target + 1), the expected effort to win it, and a branch’s work is the sum over all its blocks, back to genesis.

Note “most work”, not “most blocks”. Because work grows with difficulty, a long chain of easy blocks can lose to a short chain of hard ones. In practice, with WTEMA keeping neighboring blocks at almost the same difficulty, the longer branch nearly always wins.

The newest block of the branch a node follows is its [tip](https://pearlcodex.com/glossary/#chain-tip). Everything below is “the chain” as far as that node is concerned.

_A split. Blocks 101a and 101b share a parent, so they carry identical bits and identical work. A node that saw 101a first stays on it. When 102b arrives, branch b leads by a whole block and every node moves to it; 101a becomes stale._

## What is Pearl’s quarter-block margin?

A node switches from its current tip to a competing one only if **both** of these hold:

1. the competing branch has strictly more total work, **and**
2. its lead is at least a quarter of the work of the smaller of the two tip blocks.

$$
\begin{aligned} \text{switch} \iff{} & W_{\text{new}} > W_{\text{now}} \\ \text{and } & W_{\text{new}} - W_{\text{now}} \ge \tfrac{1}{4}\min(w_{\text{tip}}, w_{\text{new tip}}) \end{aligned}
$$

_W = total chain work; w = one block’s work._

At block 130,827’s difficulty, one block’s work is 11,303,469,090,474,696,447,598, so the margin is 2,825,867,272,618,674,111,899.

Pearl’s code was run on this rule with competing branches whose lead was a fraction of one block’s work:

| Lead of the competing branch | Switch? |
| ---------------------------- | ------- |
| 0 (a tie)                    | no      |
| 1/16 of a block              | no      |
| 3/16 of a block              | no      |
| 4/16 = 1/4 of a block        | **yes** |
| 5/16 of a block              | yes     |
| one whole block              | yes     |

> **Warning: The comment says half; the code says a quarter**
>
> The comment above `ShouldChangeTip` says the advantage must be “at least half the lesser of the two tips’ individual block work values”. The code computes the threshold as `Rsh(minBlockWork, 2)`, a right shift by 2 bits, which divides by 4. The code is what every node runs, so the margin is **¼**. Which one the authors intended isn’t documented.

## What happens in a tie?

Nothing: equal work fails the first condition, so a node keeps the tip it already has. This is the [first-seen rule](https://pearlcodex.com/glossary/#first-seen-rule), as in Bitcoin.

On Pearl, a fresh split is _always_ an exact tie. A block’s required bits depend only on its parent’s bits and its parent’s solve time (that’s [WTEMA’s one-block lag](https://pearlcodex.com/technical/difficulty/wtema/)). Two blocks on the same parent therefore need identical bits and carry identical work. Whichever one a node hears first, it keeps.

The tie breaks when the next block arrives. Whichever branch it extends now leads by a whole block of work, far beyond the quarter-block margin, and every node moves there.

## Why add a margin at all?

The code’s own comment gives the reason: to prevent “trivial-margin reorgs”. Without it, a branch could win by a crumb of work.

Where would a crumb come from? From timestamps. Two branches of the same length, split two or more blocks back, can carry slightly different bits, because each branch’s timestamps steer its own WTEMA steps.

> **Scenario · made-up numbers: Two branches, two blocks each**
>
> From block 130,827’s bits, `0x176af3a6`, branch A’s first block takes 100 seconds and branch B’s takes 300. Their second blocks then need different bits: `0x176aef64` on A, `0x176af872` on B. Pearl’s code says A’s second block carries 3,738,081,891,098,334,204 more work than B’s: about 0.03% of a block. Without the margin, that crumb, which a miner can steer just by choosing its timestamp, would be enough to flip every node from B to A. With it, nobody moves until one branch is a real quarter-block ahead.

## What is a reorg?

When a node does switch, it performs a [reorganization](https://pearlcodex.com/glossary/#reorg): it disconnects blocks from its old tip back to the point where the branches split, then connects the new branch’s blocks in order, checking each one.

- Transactions in the disconnected blocks that aren’t in the new branch go back to the [mempool](https://pearlcodex.com/glossary/#mempool), to be mined again.
- The disconnected blocks become [stale](https://pearlcodex.com/glossary/#stale-block). Their coinbase rewards never existed as far as the chain is concerned, which is why [coinbase outputs wait 100 blocks](https://pearlcodex.com/technical/emission/block-reward/) before they can be spent.
- A reorg can never reach below the latest [checkpoint](https://pearlcodex.com/technical/blockchain/checkpoints/): nodes refuse blocks that fork the chain before it.

Pearl’s light client uses the same rule, with the same quarter-block margin, when its headers disagree.

## How many confirmations are enough?

There’s no protocol answer; it depends on how much is at stake. Each [confirmation](https://pearlcodex.com/glossary/#confirmation) is another block of work an attacker would have to redo, and then outrun the honest network by a quarter of a block. Waiting longer makes undoing a payment rapidly harder.

**Make a guess:** A node follows branch A, 5 blocks above the split. Branch B appears with 5 blocks too, and slightly more total work. Does the node switch?

**Answer:** Only if B’s lead is at least a quarter of a block’s work.

Five blocks each, built from the same starting difficulty a few minutes apart, typically differ in total work by well under one percent of a block. That’s far below the quarter-block margin, so the node stays on A. When either branch gains a sixth block, it leads by about a whole block and wins.

> **Pearl vs Bitcoin**
>
> Both follow the valid chain with the most cumulative work, computed the same way, and both keep the first-seen tip on a tie. Bitcoin switches for any lead, however small; Pearl insists on a quarter of a block’s work. And because Pearl’s difficulty moves after every block, same-length branches can differ by a little work, which is exactly the case the margin is there for.

**Code: ShouldChangeTip**

From [`chain.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/chain.go#L1166-L1188):

`node/blockchain/chain.go`

```go
func ShouldChangeTip(currentWork, proposedWork, currentTipBlockWork, proposedTipBlockWork *big.Int) bool {
	if currentWork.Cmp(proposedWork) >= 0 {
		return false // not strictly more work: keep the current tip
	}
	diff := new(big.Int).Sub(proposedWork, currentWork)
	minBlockWork := currentTipBlockWork
	if proposedTipBlockWork.Cmp(currentTipBlockWork) < 0 {
		minBlockWork = proposedTipBlockWork
	}
	threshold := new(big.Int).Rsh(minBlockWork, 2) // ÷ 4, despite the comment's "half"
	return diff.Cmp(threshold) >= 0
}
```

The light client calls the same function in [`spv/blockmanager.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/spv/blockmanager.go#L2694-L2697).

## In short

- When two miners extend the chain at once, the chain splits. Each node keeps following one branch, its tip, until another branch overtakes it.
- Nodes compare branches by total work, the sum of each block’s 2²⁵⁶ ÷ (target + 1), not by number of blocks.
- Pearl switches only if the new branch has more work and leads by at least a quarter of the smaller tip block’s work. The code comment says half, but the code shifts by 2: a quarter.
- Sibling blocks on the same parent always need identical bits, so a fresh split is an exact tie, and nodes keep the block they saw first. The next block settles it.
- Switching is a reorg: blocks are disconnected, their transactions return to the waiting room, and their coinbases vanish, which is why mined coins wait 100 blocks.

## Read the code

- [ShouldChangeTip: more work plus a quarter-block margin](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/chain.go#L1166-L1188) `node/blockchain/chain.go:1166-1188`
- [CalcWork: 2²⁵⁶ ÷ (target + 1)](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/internal/workmath/difficulty.go#L141-L153) `node/blockchain/internal/workmath/difficulty.go:141-153`
- [No forks below the latest checkpoint](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/blockchain/validate.go#L705-L726) `node/blockchain/validate.go:705-726`
- [The light client uses the same rule](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/spv/blockmanager.go#L2694-L2697) `spv/blockmanager.go:2694-2697`

## Sources

### Pearl source

- [Pearl source code at v1.5.5](https://github.com/pearl-research-labs/pearl/tree/v1.5.5)

### Other

- [Bitcoin Developer Guide: block chain overview](https://developer.bitcoin.org/devguide/block_chain.html)
- [Bitcoin Wiki: Chain reorganization](https://en.bitcoin.it/wiki/Chain_Reorganization)
