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: 846844
  • Chainwork: 0x00000000000000000000000000000000000000007d55ec37e4679d0276b18472

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

What is the longest chain in the blockchain? ›

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.

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? ›

Blocks might arrive at different nodes at different times, causing the nodes to have different perspectives of the blockchain. To resolve this, each node always selects and attempts to extend the chain of blocks that represents the most Proof-of-Work, also known as the longest chain or greatest cumulative work chain.

What is the largest blockchain network? ›

Top Blockchains by Total Value Locked (TVL)

With a Total Value Locked (TVL) of $62.1 Billion, Ethereum has the largest market share across all blockchains today. Collectively the TVL of all chains is worth $96.8 Billion, representing a 0.3% movement in the last 24 hours.

What is the longest chain rule? ›

The longest chain is what individual nodes accept as the valid version of the blockchain. The rule that nodes adopt the longest chain of blocks 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 number 1 blockchain? ›

Top Blockchains
#NameDapps
1BNB Chain BNB5,364 +11
2Ethereum ETH4,609 +7
3Polygon MATIC2,134 +12
4TRON TRX1,381 0
21 more rows

Which is the oldest blockchain? ›

Under their company Surety, their document certificate hashes have been published in The New York Times every week since 1995. The first decentralized blockchain was conceptualized by a person (or group of people) known as Satoshi Nakamoto in 2008.

What is the most actively used blockchain? ›

Which is the most actively used blockchain? Here's the best way to solve it. The most actively used blockchain is Ethereum.

Which blockchains have the most nodes? ›

the crypto network with the most nodes is Bitcoin. Bitcoin has a large and decentralized network of nodes spread across the globe. These nodes help maintain the blockchain by validating transactions and ensuring the network's security and consensus.

How many nodes are needed for a blockchain? ›

One node is theoretically able to run a blockchain, though at least two or more nodes are recommended to support a blockchain for stability and security purposes. The number of nodes needed for a blockchain will also vary depending on the type of consensus mechanism being used.

Does every node store the entire blockchain? ›

Yes, nodes store a copy of the entire blockchain data. This is what makes blockchains decentralized and secure. Each node has its own local copy of the blockchain, containing all the transactions and blocks that have ever occurred on the network.

What is the most usable blockchain? ›

Ethereum is the best secure block chain based secure crypto currency platform.

Which is the fastest blockchain in the world? ›

Solana Emerges As World's Fastest Blockchain, Surpassing Ethereum and Bitcoin. According to U. Today, Solana has been identified as the fastest blockchain globally, according to a recent report by CoinGecko. The network processed over 95 million transactions in a single day.

Which blockchain is the most active? ›

Most Active Blockchains: Ranked by Daily Users
  • Here's why DAUs matter: • ...
  • Tron. Imagine a colosseum buzzing with gladiators. ...
  • BNB. Launched by Binance, BNB Chain has emerged as a major DeFi player. ...
  • Polygon. ...
  • Ronin. ...
  • Solana. ...
  • Ethereum. ...
  • Bitcoin.
Apr 12, 2024

What is the maximum size of a blockchain? ›

There is no size limit to the blockchain. Each block has a size limit of 1MB, but blocks are added to the chain every 10min, so it will keep increasing in size so long as there is at least one computer mining bitcoins.

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.

What is Nakamoto longest chain protocol? ›

Longest chain protocols were introduced in the context of the Bitcoin blockchain protocol (Nakamoto 2008) utilizing proof of work as the mechanism to facilitate block generation. Their basic security properties as consensus protocols were studied in a number of works starting with (Garay et al.

Top Articles
How to Remove Gold from Circuit Boards: Easy Step by Step Guide 2021
The 3 Important Qualities of Customer Service | Brittany Hodak
Nullreferenceexception 7 Days To Die
Toa Guide Osrs
Radikale Landküche am Landgut Schönwalde
Food King El Paso Ads
Paris 2024: Kellie Harrington has 'no more mountains' as double Olympic champion retires
LeBron James comes out on fire, scores first 16 points for Cavaliers in Game 2 vs. Pacers
Https //Advanceautoparts.4Myrebate.com
Wnem Radar
Slushy Beer Strain
Drago Funeral Home & Cremation Services Obituaries
7440 Dean Martin Dr Suite 204 Directions
5 high school volleyball stars of the week: Sept. 17 edition
Leader Times Obituaries Liberal Ks
Po Box 35691 Canton Oh
Craigslist In Flagstaff
The Ultimate Style Guide To Casual Dress Code For Women
Vrachtwagens in Nederland kopen - gebruikt en nieuw - TrucksNL
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Allybearloves
Rqi.1Stop
‘The Boogeyman’ Review: A Minor But Effectively Nerve-Jangling Stephen King Adaptation
2021 Volleyball Roster
Slim Thug’s Wealth and Wellness: A Journey Beyond Music
Caring Hearts For Canines Aberdeen Nc
Wood Chipper Rental Menards
Craigslist Northern Minnesota
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
031515 828
Craigslist Scottsdale Arizona Cars
Primerica Shareholder Account
Earthy Fuel Crossword
Metro By T Mobile Sign In
Serenity Of Lathrop - Manteca Photos
Darrell Waltrip Off Road Center
Police Academy Butler Tech
Missouri State Highway Patrol Will Utilize Acadis to Improve Curriculum and Testing Management
About Us | SEIL
Elizaveta Viktorovna Bout
Craigslist Pets Plattsburgh Ny
Anhedönia Last Name Origin
Mississippi weather man flees studio during tornado - video
Best Conjuration Spell In Skyrim
Chr Pop Pulse
Human Resources / Payroll Information
A Man Called Otto Showtimes Near Cinemark Greeley Mall
Blippi Park Carlsbad
10 Best Tips To Implement Successful App Store Optimization in 2024
Arre St Wv Srj
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 5515

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.