Blockchain and crypto mining

“A blockchain is a magic computer that anyone can upload programs to and leave the programs to self-execute, where the current and all previous states of every program are always publicly visible, and which carries a very strong crypto economically secured guarantee that programs running on the chain will continue to execute in exactly the way that the blockchain protocol specifies.”

— Vitalik Buterin, co-founder of Ethereum

What is a blockchain?

A Blockchain is a bit like a database, in that they both store information digitally. A crucial difference is in how that data is structured: a traditional database stores data in tables comprised of rows and columns. As more data is added, the tables grow in size. A blockchain, as the name suggests, stores its data in blocks that are joined together chronologically. Each block grows as new data is added and when the block is full a new block is formed and added to the chain with a link to the previous block. Thus forming a chain of blocks.

What makes blockchain technology so unique is in how this data is distributed, which ensures it is difficult or nearly impossible for the data stored within it to be hacked or tampered with.

It does this by utilising something called Distributed Ledger Technology (DLT). This means that instead of records being maintained in a single centralised database, a blockchain’s ledger is distributed across multiple nodes (computers) in a network. Each node maintains a full copy of the blockchain and when a new block of data is added, that block is published to each and every node.

Using the Bitcoin network as an example, as of October 2022 there were over  14,000 full bitcoin nodes operating around the world responsible for verifying, authenticating, and storing all transactions occurring on the blockchain network. The distributed nature of blockchain technology is a major advantage over more traditional centralised systems which typically have a single point of failure.

Consider a scenario where a hacker wants to steal your money, or  rogue governments wants to freeze your assets or place  limitations on how & when you can spend your money, this is easily achieved in the current centralised models that have a single point of failure and consensus. With a decentralised system, bad actors are unable to implement this as the point of failure is literally spread to thousands of nodes around the world all profiting from keeping the blockchain valid, accurate, and secure.

14,000k + Nodes in the Bitcoin Network (https://bitnodes.io/what-is-a-bitcoin-node/)

Properties of Distributed Ledger Technology (DLT)

Not only is blockchain distributed making it secure from tampering it is also immutable, meaning transactions cannot be reversed. Where a traditional database allows records to be added, deleted, or modified, with Blockchain only new transactions can be added once they have been confirmed.

A fundamental principle of Distributed Ledger Technology is the achievement of consensus .

Consensus is where the blockchain network participants agree on the validity of the records in the chain.

There are various consensus mechanisms a blockchain may be programmed to use, the two most prominent being Proof of Work  (PoW) and Proof of Stake (PoS) .

Each blockchain is programmed with a protocol that defines a set of rules and frameworks. The protocol determines the mechanism that is used to validate the blockchain and the frequency with which new blocks are added to the chain.

For example, Bitcoin utilises a mechanism called Proof of Work (POW) and adds a new block to the chain about every 10 minutes, whilst Ethereum, a different blockchain platform, has recently moved to a Proof of Stake (POS) model
and produces a new block about every 12 seconds.

Whichever mechanism is used, the goal is the same: to achieve consensus on blockchain validity.

achieving network consensus

Consensus is the result of all network participants agreeing on the validity of the records in the blockchain.

Since cryptocurrencies are decentralised and not controlled by a central authority verifying transactions, they require a method of authenticating the transactions that take place and then confirming the new blocks to be added to the blockchain. Two such methods are Proof of Work and Proof of Stake. 

what is proof of work?

Proof-of-Work (PoW) is the original consensus mechanism whereby nodes (computers on the network running the blockchain software) compete against each other by solving increasingly difficult mathematical equations to produce new blocks on the blockchain in return for a financial reward.

what is proof of stake?

Proof-of-Stake (PoS) is an alternative consensus mechanism whereby users stake their cryptocurrency to become network validators. The blockchain protocol randomly selects staked validators to confirm transactions and create new blocks in return for a financial reward.

Proof of WOrk COnsensus mechanism

In the POW consensus model there are two key roles carried out by nodes on the network.

  • Validating transactions – computers that are responsible for validating transactions that occur on the network.
  • Mining – computers that are responsible for publishing blocks of validated transactions.

Validating Transaction Nodes

When a transaction occurs (e.g., someone buys something) it is broadcast to the network and picked up by a node for validation. They check for valid cryptographic keys of parties involved in the transaction and that funds are available.
It is broadcast again to nearby nodes to verify the transaction. The goal is to achieve consensus from as many nodes as possible.

Where a transaction is deemed invalid, e.g., cryptographic keys are invalid (wrong address) or there are insufficient funds to make the payment then the transaction is dropped and no funds are transferred.

Once a transaction is validated it is published to a memory pool (a bit like a queue) along with thousands of other validated but unconfirmed transactions. For example:

  1. Peter sent 1000 Bitcoin to Jose (£17.5m)
  2. Layla swapped 0.05 bitcoin for 0.003 Ether on a crypto exchange (£750).
  3. Jose paid 0.0005 Bitcoin for shopping at a supermarket (£7.50).

*as of October 2022 1 bitcoin = £17,500

The unconfirmed transactions sit in the queue until they are picked up by a mining node to be packaged into a block. As there are on average about 2-4 transactions added to the memory pool per second, and only a finite amount of time
before the next block is added to the chain, how does the proof of work protocol know which transactions to process first?

the importannce of transaction fees in mining

Not all transactions are created equal, some carry more urgency or importance than others. When a transaction is initiated, the sender associates with it an indication as to the speed with which they want the transaction to take place.
Transactions of greater importance that requires immediate confirmation, i.e., on the next block, may be associated with a higher fee. By contrast, a transaction of lesser importance may be associated with a lower fee. The fee will also change in accordance with the congestion on the network at the time.

It is important to note that the fee isn’t impacted directly by the monetary amount being transferred, but is determined by the sender based upon the speed at which they wish the transaction to take place and the congestion on the network. As of October 2022, the average fee involved in including a transaction on the next available block is about £0.25p. For inclusion on a block in the next hour or later it is about £0.05p. This is irrespective of the amount being transferred, i.e., it’s the same fee if the amount being transferred is £1 or £1billion. In commerce, transaction fees are factored into the price of goods and passed on to the customer or shared with the business. When purchasing with a credit or debit card the customer isn’t aware of the transaction fees. For reference, a typical transaction fee incurred on a £1 purchase with a credit card is about £0.04p and for a £1000 purchase it would be £22.52. A non-urgent purchase made with Bitcoin would currently cost £0.05p regardless of whether you were buying a coffee for £1, sending a friend £1000 or buying a house for £1 million. This is a clear illustration as to why many believe Bitcoin isn’t a viable cryptocurrency option for micropayments that require immediate settlement, but is ideal for large transactions/ purchases and as a store of value like gold or fine art (i.e., Bitcoin is for saving, not for spending). 

The job of picking up and processing the transactions is carried out by mining nodes.

mining nodes

Miners are industrial-scale supercomputers that are responsible for packaging validated transactions into a block and adding that block to the chain. A transaction is only confirmed when it is added to a block.

Miners decide which transactions to include in a block based upon the associated transaction fee. The higher the fee, the greater the chance of inclusion in the next block. This mechanism is needed because a block is limited in the number of transactions it can hold. Bitcoin, for example, is coded to have a maximum block size of 1Mb which means that each block is limited to a maximum of about 2000 transactions. If there are many thousands of transactions taking place at any given moment then the transaction fee is an essential part of the protocol used by miners to determine priority.

In return for carrying out this role, miners are rewarded when they add a new block to the blockchain. This reward comes in the form of newly minted cryptocurrency and the fees associated with the transactions included in the block.
Mining, therefore, is effectively just a record-keeping service, achieved through computer processing power with the objective of keeping the blockchain consistent, complete, and unalterable.

how blocks are produced and what is in them?

Each block contains many properties, and is best conceptualized by imagining it as two sections, one for Transactions and one for the Block Header:

Transactions
Each block contains a list of all the transactions that have been packaged up to be processed for this block. The list of transactions is then hashed and included in the block header.

Block Header
The Block Header contains many properties that identify the block and it’s contents, and maintain integrity of the chain:

  • Transaction Hash – this is reference to all transactions that are included in this block.
  • Meta Data – this is saved on each block to record the timestamp, mining difficulty, and blockchain software number.
  • Proof of Work Solution – there are thousands of nodes all competing with each other to be the one that proposes the next block that is added to the chain in return for the rewards. This competition takes us to the
    heart of what proof of work is. For each block that is produced a miner must provide the solution to a very difficult to solve mathematical puzzle before the block can be submitted to the network. There are multiple valid solutions
    for any given block, and only one solution needs to be found for the block to be solved. Once solved, other nodes in the network can easily confirm that the solution is correct.
    Mining, therefore, is the process of competing to be the next to find the answer that ‘solves’ the current block.

    By way of example, consider that the next block to the mined had an answer that was made up of 64 numbers of 1-16: 7, 15, 8, 13, 7, 1, etc. Each miner is competing with each other to compute the correct sequence and the first miner
    who does so gets to publish the block and claim the rewards. 

    As the bitcoin protocol aims to produce a block every ten minutes and to keep to this schedule the mining difficulty, i.e., the answer to the puzzle, will adjust automatically depending on the miners capabilities, e.g., their computer
    processing power and number of miners.
  • Hash from Previous Block – The final key property on the block is a hash of the previous block header. When a new block is being added to the chain it will contain a hash of all the previous block header information.
    This ensures the blockchain is kept in sync.

Hashing is a one-way encryption process that is used to secure information being shared between parties. A value that has been hashed cannot be reverse engineered to get to the original plain text meaning if a security breached occurred
on a hashed value the original value would still be protected.

blocks chained together to form a blockchain
mining rewards

In return for their role in maintaining the blockchain, miners receive the fees associated with the transactions that were published in a block as well as newly minted cryptocurrency. The blockchain protocol determines how much of a cryptocurrency there is (total supply) and how much is to be minted as a reward.

Using Bitcoin as an example, when  block 1 was published on January 9th 2009 the reward paid out to the lucky mining node was 50 Bitcoin. In today’s money that is equivalent to about £875,000. The protocol determines that each 210,000 blocks the reward paid  to miners is halved – so in November 12th 2012 miners started to receive 25 Bitcoin per block. The current reward paid to the miners who wins the race to publish the next block is 6.25 bitcoin (£110,000), and around  March 20th 2024 when block 840,000 is published that reward will half again to 3.125 bitcoin.

This schedule of reward halving is set to continue until all the available Bitcoin (total supply) has been mined. Bitcoin has a total supply of 21 million coins, of which 19.1 million have been mined already, and at current estimates it will take until 2140 before the final Bitcoin is mined. 

proof of stake consensus mechanism

Lorem ipsum dolor sit amet, at mei dolore tritani repudiandae. In his nemore temporibus consequuntur, vim ad prima vivendum consetetur. Viderer feugiat at pro, mea aperiam

Proof of Stake (PoS) is an alternative type of consensus mechanism to PoW. Both are used to validate cryptocurrency transactions and add new blocks to the blockchain. In contrast to the Proof of Work mechanism which harnesses energy-hungry
computational power to solve increasing complex equations, Proof of Stake validation is achieved by asking cryptocurrency coin owners to become validators themselves by staking their coins on the network. In return for this they
receive ….

Since proof of stake is much more energy-efficient, it has become more popular as attention has turned to the impact crypto mining is having on the planet.