Adding New Blocks to the Blockchain (2024)

Adding new blocks to the blockchain

  • Adding New Blocks to the Blockchain (1)Greg Walker
  • Adding New Blocks to the Blockchain (2)
  • Download PDF

Mining is the process of trying to add a new block of transactions on to the blockchain.

It's a network-wide competition where any node on the network can work to try and add the next block on to the chain.

When a new block is mined, it gets broadcast across the network, where each node independently verifies and adds it on to their blockchain.

After adding the new block, each mining node restarts the process to try to build on top of this new block in the chain. As a result, the blockchain is regularly updated thanks to a collaborative effort of nodes across the network.

The system designed so that a new block is mined an average of once every 10 minutes.

Method

How does mining work?

The mining process begins by filling a candidate block with transactions from your node's memory pool.

This candidate block is what we're going to try and mine on to our blockchain (and then send to everyone else so they can add it to their blockchain too).

Next we construct a block header for this candidate block. This is basically a short summary of all of the data inside the block, which includes a reference to an existing block in the blockchain that we want to build on top of.

Block Header

Now we are ready to start mining this block.

To do this we put this block's block header through the SHA-256 hash function twice (called HASH256 for short), and hope that the number it spits out is below the current target.

HASH256

If the hash of your block header isn't below the target, you can keep trying by incrementing the nonce field in the block header. This allows you to keep the same basic block header, but get a completely different hash result for it.

And if you're lucky, you may end up getting a block hash that's below the current target.

Synchronization

How do nodes update their blockchain?

If a miner manages to get a block hash for their candidate block below the target, they will broadcast that block to the rest of network.

Each node will then confirm that the block header hashes to below the target, then add this "mined" block on to their blockchain.

From here, each node will stop working on their own candidate block, construct a new one (with fresh transactions from their memory pool), and start trying to build on top of this new block in the chain.

As a result, miners are constantly working independently (yet collaboratively) to extend the blockchain with new blocks of transactions.

Proof of Work

What does proof of work mean?

The mining process is often referred to as proof of work.

The term "proof of work" just refers to the fact that it takes work to get a block hash below the target. And if you can, anyone else can check that work has been done by confirming that the hash for the block you have constructed is indeed below the target.

In other words, the hash function is used as a way to prove that you have performed a required amount of "work" on your block.

The proof-of-work involves scanning for a value that when hashed, such as with SHA-256, the hash begins with a number of zero bits.

Miners

Who can mine blocks?

Any node can try to mine a block, and each node has a chance of being successful.

This means we have a network-wide competition where any node on the network could be the one to add the next batch of transactions on to the blockchain.

However, although anyone can try mining, being able to perform hash calculations as fast as possible improves your chances of successfully mining the next block.

Anyone's chance of finding a solution at any time is proportional to their CPU power.

As a result, miners with the most processing power (or "hashing power") are more likely to mine a block than those who cannot hash as quickly. So even though anyone can mine, it favours those with specialized mining hardware and access to cheap electricity to power that hardware.

But still, nothing is stopping you from mining if you want to.

Block Reward

What's the incentive to mine blocks?

If you are able to mine a block you can claim a block reward.

You see, when you construct a candidate block, you can put your own special transaction at the top of the block. This is called the coinbase transaction, and it allows you to send yourself a fixed amount of bitcoins that did not previously exist.

So if you end up mining this block, you would be able to spend the bitcoins you claimed from the coinbase transaction after the block reaches 100 blocks deep in the longest chain.

Therefore, this block reward acts as an incentive for miners to mine new blocks and continually try to extend the longest known chain of blocks.

  • Sending bitcoins that did not previously exist is only allowed in the coinbase transaction. This makes the coinbase transaction the source of all new bitcoins.
  • The presence of the block reward is why this process is called "mining". However, from a technical point of view, mining is mainly concerned with adding new transactions to the blockchain.

Interval

How long does it take to mine a block?

The mining system is designed so that one miner across the bitcoin network will successfully mine a new block once every 10 minutes (on average).

This timing is controlled by the target, which is like a limbo pole that a block's hash has to get under for the block to be allowed on to the blockchain.

Target Adjustment

If blocks are mined faster than 10 minutes on average over a two-week period (e.g. because more miners join the network), the target will adjust downwards so that it becomes more difficult to mine a block, and so the average time between blocks reverts back to around 10 minutes.

As a result, the target regularly adjusts to try and keep a regular interval of 10 minutes between new blocks being mined. This enforces a consistent rate of new blocks, in addition to a consistent issuance of new bitcoins in to the network.

Purpose

Why do we use mining?

The system of mining allows computers across a network to resolve conflicts, without the need for a central computer to sort them out.

Bitcoin runs across a network of independent computers, so it's possible to create two conflicting transactions (sending the same bitcoins to different places) and insert them in to different nodes on the network at the same time. Some nodes will receive transaction A first, and other nodes will receive transaction B first.

But thanks to the mechanism of mining, only one of these transactions will make it in to the blockchain.

Eventually, one of the nodes on the network will mine a block of transactions from their memory pool, and broadcast this block to the rest of the network. When nodes receive this block, they will add it to their chain and remove any conflicting transactions from their memory pool.

As a result, the process of mining acts as a sorting mechanism for transactions across a network of computers; the mined blocks have the final say on which transactions belong in the blockchain.

Better still, thanks to the fact that anyone can mine, no single node on the network is ever in complete control of which transactions make it in to the blockchain.

A miner single can control which transactions make it on to the blockchain if they can acquire a majority of the mining power. This is known as a 51% attack.

Technical

How do you mine a block?

To mine a block, you start by constructing a block header for your candidate block.

For example, here's what the block header for block 100,000 would have started out like:

0100000050120119172a610421a6c3011dd330d9df07b63616c2cc1f1cd00200000000006657a9252aacd5c0b2940996ecff952228c3067cc38d4885efb5a4ac4247e9f337221b4d4c86041b00000000

Now you've got the block header, you try and "mine" it by putting it through HASH256. You keep incrementing the nonce value as you go to try and get a result below the target.

HASH256

For example:

Nonce Hash256-------- -------00000000: 5bd0d617b30a972407ad69a845cd74fb201d940cd45acc15fcd4761493bc3ae201000000: 6879c316d8a96269825111bb0616331307bb6677b2af55127922d8c568e4b2db02000000: 34d69cb489442234ec54462e18262bf1a9c756a4e7909e68edf979a0cb39a3fa03000000: 8cf5e032093cfcbf4f6b443608631dd33699fca13dcbd6118992f9d451b70dd804000000: a32d73e3f2fd0579c44080cb6b1717582d37b8f47a8445922dee0996b503c04c05000000: 70b11dabc90a107918a55eff7e940d41b0ce1924aeed2f0b7ccb2d4ee60e161706000000: b38afc30567703629226557a7748bea449693156e0b116b03a8442ccc3b9005e07000000: 2a6008f39daa1238388eadcab111c6b556c3d89a46558c98f8ed32746fb5d7b808000000: 248e33c82a744786e7e16336612221850e32f8e6cb09b2eb0b0730ac6beb71b409000000: a4aea05d2750e49e8f95f5608293f6b4f45bd34aee51e86893dd8c0230d191850a000000: ce2225a69a5bf2dbb25cbb27fda78a8c4c3ac5280ec7996426eeefeb0e5e1ecb...

Eventually you may find a nonce value that produces a hash result below the target:

Nonce Hash256-------- -------0f2b5710: 000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506
  • The nonce is a 4-byte field in little-endian byte order.
  • The result of hashing the raw block header through HASH256 will appear to be backwards at first. This is because block hashes are displayed in reverse byte order on blockchain explorers.

Reverse Bytes

Code

Here's some Ruby code that shows how you can mine a block (like the one above).

The code is simpler than you might think. The only tricky part is getting the block header data in the correct format before hashing it.

Mining Simulator

require 'digest/sha2'# -----------------# Utility Functions# -----------------# The hash function used in mining (convert hexadecimal to binary first, then SHA256 twice)def hash256(data) binary = [data].pack("H*") hash1 = Digest::SHA256.digest(binary) hash2 = Digest::SHA256.hexdigest(hash1)end# Convert a number to fit inside a field that is a specific number of bytes e.g. field(1, 4) = 00000001def field(data, size) hex = data.to_i.to_s(16).rjust(size * 2, '0')end# Reverse the order of bytes (often happens when working with raw bitcoin data)def reversebytes(data) data.scan(/../).reverse.joinend# ------------# Block Header (e.g. block 100,000)# ------------# Target (optional)target = '000000000004864c000000000000000000000000000000000000000000000000'# Block Header (Fields)version = '1'prevblock = '000000000002d01c1fccc21636b607dfd930d31d01c3a62104612a1719011250'merkleroot = 'f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766'time = '1293623863' # Unixtime (29 Dec 2010, 11:57:43)bits = '1b04864c'nonce = 0 # 274148111# Block Header (Serialized)header = reversebytes(field(version, 4)) + reversebytes(prevblock) + reversebytes(merkleroot) + reversebytes(field(time, 4)) + reversebytes(bits)# -----# Mine!# -----loop do # hash the block header attempt = header + reversebytes(field(nonce, 4)) result = reversebytes(hash256(attempt)) # show result puts "#{nonce}: #{result}" # end if we get a block hash below the target if result.to_i(16) < target.to_i(16) break end # increment the nonce and try again... nonce += 1end

Commands

bitcoin-cli getblocktemplate

This command grabs transactions from your node's memory pool and returns the data you need to start mining a new block.

Annoyingly you also have to provide an awkward array to specify the kind of block template you want (see BIP22). This is what I typically use: bitcoin-cli getblocktemplate '{"rules": ["segwit"]}'

This command returns the key block header information like the previous block, time, and bits, but you will need to construct the merkle root yourself.

bitcoin-cli submitblock [hex]

Send a raw block in to the network.

For example, this is the genesis block:

$ bitcoin-cli submitblock 0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000

This is a complete raw block. It must include the block header, the transaction count, and all the raw transaction data.

bitcoin-cli getmininginfo

This command returns some interesting mining information.

For example:

$ bitcoin-cli getmininginfo{ "blocks": 854633, "currentblockweight": 3995601, "currentblocktx": 7035, "difficulty": 82047728459932.75, "networkhashps": 6.757386147813634e+20, "pooledtx": 67791, "chain": "main", "warnings": ""} 

If you run bitcoin-cli getblocktemplate beforehand it will also show you how many transactions from the memory pool are currently being included in the next block (under currentblocktx).

Resources

Adding New Blocks to the Blockchain (2024)

FAQs

Adding New Blocks to the Blockchain? ›

To add a candidate block to the blockchain, you hash the data in the block header and hope that the result is below a certain target value. The target is calculated from the difficulty, which is a value set by the bitcoin network

bitcoin network
And because all the nodes on the network work to share transactions, everyone on the network will eventually know about the latest transactions. Good network. The Bitcoin Network is described as a "peer-to-peer (P2P) network", because: Everyone is connected to each other, so it's a network.
https://learnmeabitcoin.com › beginners › guide › network
to regulate how difficult it is to add a block of transactions to the blockchain.

How are new blocks added to the blockchain? ›

If a majority of miners — 51% or more — reach consensus on the solution, the miner will be allowed to add their new block to the blockchain and receive the block reward. This same process repeats every 10 minutes on the Bitcoin network as new blocks are added and the data chain grows.

How often is a new block added to the blockchain? ›

A new block, containing transactions that occurred since the last block, is “mined” every 10 minutes on average, thereby adding those transactions to the blockchain.

What is the correct order of adding a new block to blockchain? ›

Expert-Verified Answer
  1. The correct sequence involved in a block creation is:
  2. Transaction initiated.
  3. Transaction validated.
  4. Transactions Bundled & broadcasted.
  5. Proof of work consensus problem solved.
  6. Block added to the local chain and propagated to the network.
  7. Hence, the above mentioned is the right sequence.
May 24, 2023

How does each additional block added to the blockchain strengthen? ›

The blocks confirm the exact time and sequence of transactions, and the blocks link securely together to prevent any block from being altered or a block being inserted between two existing blocks. Each additional block strengthens the verification of the previous block and hence the entire blockchain.

How are things added to the blockchain? ›

Once a transaction is recorded, its authenticity must be verified by the blockchain network. After the transaction is validated, it is added to the blockchain block. Each block on the blockchain contains its unique hash and the unique hash of the block before it.

How long does it take to add a block to the blockchain? ›

The Bitcoin network has a mechanism for ensuring that no matter how much hash rate is produced by all miners, one new block is only created on average every ten minutes. This mechanism is called the difficulty adjustment. ➤ Learn more about Bitcoin's difficulty adjustment.

What is the purpose of a block in a blockchain? ›

Blocks record and confirm the time and sequence of transactions, which are then logged into the blockchain, within a discrete network governed by rules agreed to by the network participants.

How often is a new block mined? ›

After adding the new block, each mining node restarts the process to try to build on top of this new block in the chain. As a result, the blockchain is regularly updated thanks to a collaborative effort of nodes across the network. The system designed so that a new block is mined an average of once every 10 minutes.

What are the four requirements a new block must meet in order to be valid? ›

Validating a New Block
  • The block data structure is syntactically valid.
  • The block header hash is equal to or less than the target (enforces the Proof-of-Work)
  • The block timestamp is less than two hours in the future (allowing for time errors)
  • The block size is within acceptable limits.

What is the first block in a blockchain called? ›

A genesis block is the first block of a blockchain. Genesis block is almost hardcoded into the software of the applications that utilize its blockchain.

What type of transaction cannot be stored in blocks on a blockchain? ›

A transaction that assigns copyright ownership to a song cannot be stored in blocks on block chain. Explanation: As we know, blocks on bitcoins store data about monetary transaction. Block chain is the centralized chain and therefore there is no central place for it to be stored.

How do I create a new blockchain? ›

Now, let's dive into each step.
  1. Make Sure Blockchain Is Right for Your Use Case. Building on the blockchain isn't easy. ...
  2. Choose Your Protocol. When setting up your blockchain, you have to choose a protocol. ...
  3. Identify the Best Consensus Algorithm. ...
  4. Deploy Your Network. ...
  5. Launch Your First Smart Contract.
Jun 9, 2024

How are new blocks added to the blockchain in a? ›

Mining – the process of verifying and adding blocks to a blockchain ledger, as well as adding cryptocurrency coins into circulation using a proof-of-work consensus mechanism.

How do Blockchains accumulate blocks? ›

Once the participants have reached a consensus, transactions on the blockchain are written into blocks equivalent to the pages of a ledger book. Along with the transactions, a cryptographic hash is also appended to the new block. The hash acts as a chain that links the blocks together.

How often do blocks get added to the Bitcoin blockchain? ›

The first mining node to validate their block and add it to the blockchain earns the block reward. This repeats roughly every 10 minutes.

How are new blocks appended to a blockchain by linking to the previous block's? ›

The hash is the unique identity of the block as there is no two blocks with the same hash. The new block is chained to its previous block by appending the hash of the previous block to its block.

How are the blocks linked in blockchain? ›

Definition. A blockchain is “a distributed database that maintains a continuously growing list of ordered records, called blocks.” These blocks “are linked using cryptography. Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data.

How is the blockchain updated? ›

A blockchain is a type of distributed database or ledger, which means the power to update a blockchain is distributed between the nodes, or participants, of a public or private computer network. This is known as distributed ledger technology (DLT).

Top Articles
Onboard to Microsoft Defender Vulnerability Management - Microsoft Defender Vulnerability Management
Bajaj Consumer Care Ltd share price | About Bajaj Consumer | Key Insights
Spectrum Gdvr-2007
Riverrun Rv Park Middletown Photos
DPhil Research - List of thesis titles
Missed Connections Inland Empire
Insidious 5 Showtimes Near Cinemark Tinseltown 290 And Xd
Lexington Herald-Leader from Lexington, Kentucky
Costco The Dalles Or
Www.megaredrewards.com
Mawal Gameroom Download
Graveguard Set Bloodborne
Camstreams Download
2016 Hyundai Sonata Price, Value, Depreciation & Reviews | Kelley Blue Book
Alaska: Lockruf der Wildnis
Pittsburgh Ultra Advanced Stain And Sealant Color Chart
Colts Snap Counts
Sivir Urf Runes
Pay Boot Barn Credit Card
Fsga Golf
Baja Boats For Sale On Craigslist
Www.patientnotebook/Atic
Imouto Wa Gal Kawaii - Episode 2
Cookie Clicker Advanced Method Unblocked
Panola County Busted Newspaper
Watertown Ford Quick Lane
Craigslist Comes Clean: No More 'Adult Services,' Ever
Vadoc Gtlvisitme App
Gt7 Roadster Shop Rampage Engine Swap
Average weekly earnings in Great Britain
Rust Belt Revival Auctions
Orange Pill 44 291
Metro By T Mobile Sign In
Msnl Seeds
Can You Buy Pedialyte On Food Stamps
National Insider Threat Awareness Month - 2024 DCSA Conference For Insider Threat Virtual Registration Still Available
Noaa Marine Weather Forecast By Zone
Lbl A-Z
About My Father Showtimes Near Amc Rockford 16
Traumasoft Butler
Ts In Baton Rouge
Phmc.myloancare.com
877-552-2666
Pas Bcbs Prefix
Underground Weather Tropical
Ronnie Mcnu*t Uncensored
Craigslist Charles Town West Virginia
Houston Primary Care Byron Ga
91 East Freeway Accident Today 2022
Morgan State University Receives $20.9 Million NIH/NIMHD Grant to Expand Groundbreaking Research on Urban Health Disparities
Mazda 3 Depreciation
Scholar Dollar Nmsu
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 6153

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.