Longest Chain | The Blockchain that Nodes Adopt (2024)

The chain of blocks nodes adopt as their blockchain

  • Longest Chain | The Blockchain that Nodes Adopt (1)Greg Walker
  • Longest Chain | The Blockchain that Nodes Adopt (2)

Current Longest Chain:

  • Height: 844979
  • Chainwork: 0x00000000000000000000000000000000000000007b271d230c50cc2c75b05eb8

The longest chain is what Bitcoin nodes accept as the valid version of the blockchain.

The longest chain rule allows every node on the network to agree on what the blockchain looks like, and therefore agree on the same transaction history.

In other words, it means that computers acting independently over a network can maintain the same view of a globally updated file.

The proof-of-work chain is the solution to the synchronisation problem, and to knowing what the globally shared view is without having to trust anyone.

Definition

What is the longest chain?

The longest chain is the chain of blocks that took the most effort to build.

In short, to add a new block to the blockchain you need to use processing power, which means that every block on the blockchain required a certain amount of energy to get there.

Therefore, a blockchain with more blocks in it will have taken more energy to build than a chain with fewer blocks in it, and as a rule nodes will always adopt this chain over a "shorter" one.

As a result, nodes will always adopt the chain that took the most energy to build, and this is what we mean when we refer to the "longest chain".

The majority decision is represented by the longest chain, which has the greatest proof-of-work effort invested in it.

Misconception

Is the longest chain the one with the most blocks?

You'd think that the longest chain is simply the one with the most blocks in it, but the chain that required the most energy to build is not necessarily the one with the most blocks in it.

This is because changes to the difficulty mean that some blocks are going to require more energy to mine than others.

For example, within the same difficulty period every new block requires the same amount of effort to be mined, and therefore adds the same amount of "work" to the chain:

However, if the difficulty increases (because blocks were mined more quickly than every 10 minutes on average), the blocks in the new difficulty period are going to take more effort to mine:

Now, seeing as nodes adopt the chain with the most work, they wouldn't actually adopt a chain with more blocks in it if it didn't require as much work to build.

For example, if you construct two different blockchains spanning multiple difficulty periods, nodes will adopt the one that has the most cumulative "chainwork", and not simply the one with the most blocks in it:

So in summary, the phrase "longest chain" refers to the blockchain that has taken the most energy to build. For the most part this is usually the chain with the most blocks in it, but to be more precise it's the chain with the most amount of work in it.

In the first version of Bitcoin Satoshi actually used the number of blocks as the metric for determining the longest chain, believing this to be the chain that would have taken the most work to build. However, this is vulnerable to manipulation, so it was later changed to using chainwork as the metric for the longest chain instead.

Chainwork

How do you calculate the longest chain?

The longest chain is measured by a metric called "chainwork".

[Chainwork] is the total number of hashes that are expected to have been necessary to produce the current chain.

To work out chainwork, you just need to work out how many hashes you would have needed to perform to mine each block in the chain, then add them up.

Calculation

The process of mining involves hashing a block header.

Every time you perform a hash, the hash function spits out a 256-bit number, which could be anywhere between 0 and:

0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

To successfully mine this block on to the blockchain, this hash result needs to be below the target value for that particular height in the chain. The target for the first ever block was set at:

0x00000000ffff0000000000000000000000000000000000000000000000000000

So to work out how many hashes you'd need to perform (on average) to get below this value, you divide the maximum range of numbers by the number you want to get below.

0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff /(0x00000000ffff0000000000000000000000000000000000000000000000000000 + 1)= 0x0100010001

This means you would need to perform 0x0100010001 (4295032833) hashes on average to get a result below this target value. Therefore, this was the actual chainwork for that first block.

So to work out the total chainwork in a chain, you just work out the expected hashes for each block and add them all up.

You can find out what the target was for each block by looking at the bits field in the block header.

Average Hashes Explained

Let's say you're randomly generating numbers between 1 and 100, and you're hoping to randomly generate a number of 5 or below. On average, how many numbers would you need to generate before you get one below your target?

100 / 5 = 20

So on average you'll need to generate 20 numbers to get one that is below 5.

This is exactly the same kind of calculation that takes place in Bitcoin, but just with bigger numbers (and usually calculated using hexadecimal values instead).

Example

To give a quick example of how chainwork is calculated, let's calculate the chainwork for the fourth block in the blockchain.

The target did not adjust for the first 2016 blocks, so each the average number of hashes required to mine each of these first 4 blocks will be the same:

Block 0 Target: 0x00000000ffff0000000000000000000000000000000000000000000000000000 Average Hashes: 2**256 / (Target + 1) = 4295032833Block 1 Target: 0x00000000ffff0000000000000000000000000000000000000000000000000000 Average Hashes: 2**256 / (Target + 1) = 4295032833Block 2 Target: 0x00000000ffff0000000000000000000000000000000000000000000000000000 Average Hashes: 2**256 / (Target + 1) = 4295032833Block 3 Target: 0x00000000ffff0000000000000000000000000000000000000000000000000000 Average Hashes: 2**256 / (Target + 1) = 4295032833

The total chainwork will be the sum of the average number of hashes to mine each of these blocks:

Total Chainwork = 4295032833 + 4295032833 + 4295032833 + 4295032833 = 17180131332 = 0x400040004

We can check that our calculation is correct using bitcoin-cli:

bitcoin-cli getblockhash 30000000082b5015589a3fdf2d4baff403e6f0be035a5d9742c1cae6295464449bitcoin-cli getblock 0000000082b5015589a3fdf2d4baff403e6f0be035a5d9742c1cae6295464449{ ... "chainwork": "0000000000000000000000000000000000000000000000000000000400040004", ...}

Purpose

Why do nodes adopt the longest chain?

Having nodes adopt the longest available chain allows computers across a network to agree on the same version of the blockchain.

Here are two situations where this proves to be useful:

1. Resolving disagreements when two blocks are mined at the same time.

Due to the fact that bitcoin operates on a network, it's possible that two independent computers will mine a block at the same time. In this situation, nodes across the network will end up being in disagreement about which of these two blocks should be at the top of the blockchain.

However, this situation can be resolved by having nodes adopt the longest chain of blocks. This is because the next block to be mined will build upon one of these two blocks, creating a new longest chain that all nodes on the network will be happy to adopt.

So even though nodes can be in disagreement at any given time (due to the unpredictability of mining and the speed of broadcasting data across a network), adopting the longest available chain means that nodes will always eventually agree on the same view of the blockchain.

2. Protecting blocks already mined on to the blockchain.

The fact that nodes always adopt the longest chain as the valid version of the blockchain means that it is very difficult to replace blocks (and therefore transactions) already in the chain.

If someone wanted to replace a transaction in the blockchain, they would need to work to build a new longest chain to replace the current one.

However, if the majority of miners are continually working to extend the same current longest chain, an individual miner won't be able to compete to outwork the combined effort of all the other miners.

As a result, the combined effort of miners coordinating to extend the same chain protects existing blocks and transactions from being replaced by a single miner.

Think of it as a cooperative effort to make a chain.

FAQ

Why do miners choose to build on the longest chain?

Because a miner can claim a block reward if they are able to mine a block.

However, the bitcoins from this block reward can only be spent if the block becomes 100 blocks deep in the longest chain. Therefore, this block reward incentivises miners to always try and mine new blocks that will become part of the longest chain (by always trying to build on to the current longest one).

Miners initially claim the block reward through the coinbase transaction.

What happens transactions that are not part of the longest chain?

A transaction inside a block that is not part of the longest chain is invalid.

If you tried to spend the outputs from a transaction that is not in the longest chain, nodes would not accept this new transaction nor try to mine it in to a block. This is because nodes only consider the longest chain as the valid history of transactions, and anything outside of that is not a valid transaction.

So only the transactions inside the longest chain are considered to be part of the valid transaction history, and any transactions outside of it effectively never took place.

It's recommended that you wait for a transaction to make it to 2 or more blocks deep in to the blockchain before you consider bitcoins to be "yours". There is always a chance that the topmost blocks in the blockchain could change due to a chain reorganisation, making previously valid blocks and transactions invalid.

Commands

You can find the chainwork values for yourself using these bitcoin-cli commands:

bitcoin-cli getblockchaininfo

See the total chainwork for the current longest chain.

$ bitcoin-cli getblockchaininfo{ "chain": "main", "blocks": 599501, "headers": 599767, "bestblockhash": "0000000000000000000cb6141c8076e24f3a1799eef37201634ef392197668f3", "difficulty": 13008091666971.9, ... "chainwork": "0000000000000000000000000000000000000000094b1874d991d4e1fc51005a", ...}

bitcoin-cli getblock [blockhash]

See the chainwork for any given block in the chain.

$ bitcoin-cli getblock 00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699{ "hash": "00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699", ... "height": 12345, ... "bits": "1d00ffff", "difficulty": 1, "chainwork": "0000000000000000000000000000000000000000000000000000303a303a303a", ...}

Summary

The adoption of the longest chain of blocks allows nodes on a network of computers to be able to share a globally accepted view of the blockchain. Furthermore, the fact that it requires energy to add new blocks to the chain makes it very difficult for any individual to replace blocks that have already been mined in to the chain.

The "longest chain" usually refers to the chain with the greatest number of consecutive blocks, but technically it refers to the chain that has the most work in it based on how difficult it was to mine each block.

Resources

Longest Chain | The Blockchain that Nodes Adopt (2024)

FAQs

Longest Chain | The Blockchain that Nodes Adopt? ›

The longest chain is what Bitcoin nodes accept as the valid version of the blockchain. The longest chain rule allows every node on the network to agree on what the blockchain looks like, and therefore agree on the same transaction history.

What is the longest live running blockchain? ›

In 1995, Surety's offering constituted the first commercial deployment of a blockchain and is currently the oldest continuously running blockchain. In 2002, Haber joined HP Labs as a research scientist in the Princeton office, working there for 15 years on cryptography and security related problems.

Why do nodes always try to build on the longest chain? ›

Nodes always consider the longest chain to be the correct one and will keep working on extending it. A node will always try to build on top of the longest valid chain of proof-of-work, as any block discovered on a block that is not at the longest valid chain tip will never be built upon by competing nodes.

What is the heaviest chain rule in Bitcoin? ›

In Bitcoin and other more traditional systems, the Longest Chain Rule (LCR) stipulates that the canonical chain is the sequence of valid blocks with the most work (often referred to as the longest chain or, more accurately, the heaviest chain) [4].

What is the maximum length of a blockchain address? ›

A bitcoin address is a 26-62 alphanumeric character identifier that is used to receive bitcoin.

How many nodes can a blockchain have? ›

Thousands of nodes can be active at the same time on some Blockchains. Anyone may run a node by downloading a Blockchain's transaction history. Many crypto and Blockchain enthusiasts volunteer to run nodes.

How many nodes are needed for a blockchain? ›

In PoA, a limited number of nodes, known as signers, are authorized to validate transactions and secure the network. To resolve forks during consensus, an odd number of signer nodes is necessary. Thus, a minimum of two user nodes, along with a monitor node, is recommended for a PoA-based blockchain network.

Do Bitcoin miners run full nodes? ›

Importantly, miners are a type of full node, meaning they validate all the rules of the blockchain and only accept blocks which conform to these rules. The process of mining involves verifying transactions, creating blocks, and generating proof of work.

What are the 4 major blockchains? ›

This blog delves into the four main types of blockchain—public, private, consortium, and hybrid—each with distinct advantages, drawbacks, and ideal use cases, highlighting their growing importance in the finance sector.

What is the most powerful blockchain? ›

Ethereum is a platform that has been around for a while, is well-known, and is rightfully regarded as the greatest blockchain development platform. It is currently one of the most popular and quickly expanding networks among developers.

Which country is leading in blockchain? ›

Singapore. Singapore is a leading country in blockchain adoption, with the government investing heavily in blockchain research and development. Due to its favorable regulatory climate, Singapore has become a hotspot for initial coin offerings (ICOs), with many blockchain businesses choosing to incorporate there.

What is the 51% rule in blockchain? ›

A 51% attack is an attack on a blockchain by an entity or group that controls more than 50% of the network. Attackers with majority network control can interrupt the recording of new blocks by preventing other miners from completing blocks.

Which entity holds the most Bitcoin? ›

MicroStrategy at the Top. As the world's largest corporate owner of bitcoin, MicroStrategy holds 174,530 bitcoin valued at an estimated $9.1 billion as of February 22, 2024.

Who has the largest holding of Bitcoin? ›

Satoshi Nakamoto owns the most bitcoin with an estimated 1.1 million BTC. Satoshi not only invented but was also the first miner to create blocks of transactions.

Which blockchain is currently the fastest? ›

Tectum is the fastest layer-1 blockchain, with a speed of 1.3 million transactions per second. It uses proof of utility consensus to process transactions through trusted nodes.

Does blockchain grow infinitely? ›

3 Answers. Yes, the blockchain itself will keep increasing forever. On the other hand, one does not need to store the entire blockchain to use Bitcoin.

References

Top Articles
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6230

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.