Digital Notes - 3
Digital Notes - 3
Distributed Consensus:
Content Summary: Distributed systems, Consensus decision- making, Blockchain
Consensus, Blockchain Nodes: Light nodes, Full Nodes, Mining Nodes, Byzantine
Generals Problem, Byzantine Fault Tolerance, Practical and Federated BFT, Consensus
Algorithms: Proof of Work, Proof of Stake, Proof of Work v Stake, Delegated Proof of
Stake, Proof of Importance, Proof of Elapsed Time, Proof of Capacity, Proof of Authority,
RAFT, 51% Attack, Forking, Hard and Soft Forking: Case Studies
This is possible only because of the presence of the consensus protocol which is a
core part of any Blockchain network. A consensus algorithm is a procedure through
which all the peers of the Blockchain network reach a common agreement about
the present state of the distributed ledger.
In this way, consensus algorithms achieve reliability in the Blockchain network and
establish trust between unknown peers in a distributed computing environment.
Essentially, the consensus protocol makes sure that every new block that is added to
the Blockchain is the one and only version of the truth that is agreed upon by all the
nodes in the Blockchain.
1
Blockchain Unit-3 Sem-7
Purpose of PoW: -
The purpose of a consensus mechanism is to bring all the nodes in agreement, that
is, trust one another, in an environment where the nodes don’t trust each other.
All the transactions in the new block are then validated and the new block is then added
to the blockchain.
The block will get added to the chain which has the longest block height.
Miners (special computers on the network) perform computation work in solving a
complex mathematical problem to add the block to the network, hence named,
Proof-of-Work.
With time, the mathematical problem becomes more complex.
Features of PoW: -
There are mainly two features that have contributed to the wide popularity of this
consensus protocol and they are:
o It is hard to find a solution to a mathematical problem.
o It is easy to verify the correctness of that solution.
Mining:
2
Blockchain Unit-3 Sem-7
The Proof-of-Work consensus mechanism has some issues which are as follows:
The 51% risk: If a controlling entity owns 51% or more than 51% of nodes in the
network, the entity can corrupt the blockchain by gaining the majority of the network.
Time-consuming: Miners have to check over many nonce values to find the right
solution to the puzzle that must be solved to mine the block, which is a time-consuming
process.
Resource consumption: Miners consume high amounts of computing power in order to
find the solution to the hard mathematical puzzle. It leads to a waste of precious
resources (money, energy, space, hardware). It is expected that 0.3% of the world’s
electricity will be spent to verify transactions by the end of 2028.
Not instantaneous transaction: Transaction confirmation takes about 10–60 minutes.
So, it is not an instantaneous transaction; because it takes some time to mine the
transaction and add it to the blockchain thus committing the transaction.
Why Proof-of-Stake:
o Before proof of stake, the most popular way to achieve distributed consensus was
through Proof-of-Work (implemented in Bitcoin).
o But Proof-of-Work is quite energy (electrical energy in mining a bitcoin) intensive.
So, a proof-of-work based consensus mechanism increases an entity’s chances of
mining a new block if it has more computation resources.
o A part from the upper two points, there are other weaknesses of a PoW based
consensus mechanism. In such a scenario, a Proof-of-Stake based mechanism holds
merit.
What is Proof-of-Stake:
o As understandable from the name, nodes on a network stake an amount
of cryptocurrency to become candidates to validate the new block and earn the fee
from it. Then, an algorithm chooses from the pool of candidates the node which will
validate the new block. This selection algorithm combines the quantity of stake
(amount of cryptocurrency) with other factors (like coin-age based selection,
randomization process) to make the selection fair to everyone on the network.
3
Blockchain Unit-3 Sem-7
Features:
Advantages of PoS:
Energy-efficient:
o As all the nodes are not competing against each other to attach a new block to the
blockchain, energy is saved. Also, no problem has to be solved (as in case of Proof-of-
Work system) thus saving the energy.
Decentralization:
o In blockchains like Bitcoin (Proof of Work system to achieve distributed consensus), an
4
Blockchain Unit-3 Sem-7
extra incentive of exponential rewards is in place to join a mining pool leading to a more
centralized nature of blockchain. In the case of a Proof-of-Stake based system (like
Peercoin), rewards are proportional(linear) to the amount of stake. So, it provides
absolutely no extra edge to join a mining pool; thus, promoting decentralization.
Security:
o A person attempting to attack a network will have to own 51% of the stakes (pretty
expensive). This leads to a secure network.
New technology:
PoS is still relatively new. Research is ongoing to find flaws, fix them and making it
viable for a live network with actual currency transactions.
5
Blockchain Unit-3 Sem-7
reward is added up to reward of the next witness which verifies that block.
o Such transactions are collected by the next witness, and such a block is
called stolen.
o Votes are proportionate to size of each voter’s stake. A user need not have a large
stake to enter the top tier of witnesses. Rather, votes from users with large stakes
can result in users with relatively small stakes being elevated to the top tier of
witnesses.
Advantages:
o DPoS blockchains have good protection from double-spending.
o DPoS is more democratic and financially inclusive due to lesser staking amount
required by a user/node.
o DPoS provides more decentralization as more people take part in the consensus due
to low entry threshold.
o DPoS doesn’t require lots of power to run network, which makes it more
sustainable.
o Transactions in DPoS is not dependent on computing power required to run
network, hence it is more scalable.
o DPoS separates election of block producers from block production itself which
opens door for more creative models to solve both problems in isolation.
o DPoS method provides foundation for implementing interesting governance models
in blockchain applications. In a sense, it forms a kind of democracy.
Disadvantages:
o Effective operation and decision making of network requires delegators to be well
informed and appoint honest witnesses.
o Limited number of witnesses can lead to centralization of network.
o DPoS blockchain is susceptible to problems of weighted voting. Users with smaller
stake can refuse from taking part in voting after considering that their vote is
insignificant.
Working of PoA :
o In PoA, rights to generate new blocks are awarded to nodes that have proven their
authority to do so. These nodes are referred to as “Validators” and they run
software allowing them to put transactions in blocks. Process is automated and does
not require validators to be constantly monitoring their computers but does require
maintaining the computer uncompromised. PoA is suited for both private networks
and public networks, like POA Network, where trust is distributed.
6
Blockchain Unit-3 Sem-7
Limitations:
o PoA is not decentralized but is just an effort to make centralized systems more
efficient.
o PoA validators are visible to anyone. Knowing validators identities could
potentially lead to third-party manipulation.
7
Blockchain Unit-3 Sem-7
o Vesting: Also known as ‘Harvesting’ is the most integral part of this consensus
mechanism. First, any node should have at least 10,000 XEM coins before they can
start harvesting or vesting. The consensus mechanism counts the number of coins
present in your account for a set number of days (mostly 30 days) for calculating
the Proof of Importance score of the node. Therefore, the higher the number of
XEM coins higher will be the node’s score.
o Number and size of transactions: Each transaction above a minimum size has an
impact on the Importance score and increases the chances of harvesting a block to
collect rewards. Larger and more frequent transactions will improve the PoI score
on the NEM network and the score is based on the transaction node makes in the
period of 30 days.
8
Blockchain Unit-3 Sem-7
9
Blockchain Unit-3 Sem-7
Benefits of PoET:
o Less power consumption: PoET doesn’t require much electricity consumption,
and the nodes can “go to sleep” and switch to other tasks for the specified time
thereby making the network time and energy efficient.
o Less resource intensive: PoET also provides a great solution to the “Random
Leader Selection Problem” without being resource-intensive or requiring complex
mechanisms. It is easily scalable as it allows the network to reach consensus more
quickly thus allowing faster processing of transactions.
o High transaction rate: PoET can go up to a million transactions per second.
o Equal opportunity: PoET allows for the same opportunity for the network
participants with time object and activation.
o Permissioned: Since it is a permissioned blockchain network, the process of
selecting validators ensures network security against cyberattacks.
o Limitations of PoET:
o Specialized hardware required: Even though it’s cheap there is a requirement for
specialized hardware for incorporating the Proof of Elapsed Time consensus
algorithm as a result, it cannot be used by most people.
o Compatibility issues: PoET highly depends on tools by Intel technology which
might raise compatibility issues with the other tools.
10
Blockchain Unit-3 Sem-7
The more coins they burn, the better their chances of being selected to mine the
next block. While PoB is an interesting alternative to PoW, the protocol still
wastes resources needlessly. And it is also questioned that mining power simply
goes to those who are willing to burn more money.
o There also exist other consensus algorithms like Proof of Activity, Proof of Weight,
Proof of Importance, Leased Proof of Stake, etc. It is therefore important to wisely
choose one as per the business network requirement because Blockchain networks
cannot function properly without the consensus algorithms to verify each and every
transaction that is being committed.
A reward is given to first miner to The validator does not receive a block
2. solve cryptographic puzzle of each reward instead they collect network fee
block. as their reward.
Hackers would need to have 51% of Hackers would need to own 51% of
4. computation power to add malicious all cryptocurrency on network, which is
block. practically impossible.
Proof of work systems are less energy Proof of Stake systems are much more
5. efficient and are less costly but more cost and energy efficient than POW
proven. systems but less proven.
11
Blockchain Unit-3 Sem-7
1. Full Nodes
As they maintain a complete copy of the Blockchain ledger, Full Nodes are the most
essential type of node in the Blockchain network. These nodes are able to
independently verify the entire Blockchain history since they download and store
copies of every transaction and block that occurs on the network. The stability of the
Blockchain network depends on Full Nodes, which constitute the foundation of the
network.
As part of a peer-to-peer network, Full Nodes communicate with other nodes to
maintain the accuracy and current state of the Blockchain. They validate
transactions and blocks by checking for inconsistencies, such as double-spending or
invalid signatures, before adding them to the Blockchain. Blockchain developers
and organizations that require a high level of security and control over their
Blockchain transactions often run Full Nodes. These nodes are in charge of
validating all blocks and transactions.
2. Light Nodes
Light Nodes are a more lightweight variation of Full Nodes, sometimes referred to
as SPV (Simplified Payment Verification) nodes. They are designed to operate on
mobile devices such as smartphones and tablets with limited storage and processing
power. Light Nodes do not download the entire Blockchain but rather a small
portion of it that contains information relevant to their transactions.
To obtain the information, Light Nodes are required to verify their transactions by
communicating with a number of Full Nodes in the network. Light Nodes are faster
and more efficient than Full Nodes, however, because they rely on Full Nodes for
validation, they are also less secure.
This type of blockchain node is designed for fast, straightforward processing of
transactions and daily activities, and is second in usage popularity only to archival
nodes.
Light nodes are equipped with only the essential data and rely on Full Nodes to
function, as they do not download the full blockchain.
12
Blockchain Unit-3 Sem-7
3. Miner Nodes
Miner Nodes are responsible for validating transactions and generating new blocks
on the Blockchain. These nodes execute complex calculations to solve mathematical
problems, allowing them to create new blocks and receive rewards in the form of
cryptocurrency. Miner Nodes require specialized hardware and software to perform
mining calculations. They are often run by major mining pools or individuals with
the financial ability to invest in the necessary equipment. Miner Nodes are critical
components of the Blockchain network, ensuring that new transactions are
processed and added to the Blockchain in a timely and secure manner.
In 1982, The Byzantine General’s Problem was invented by Leslie Lamport, Robert
Shostak, and Marshall Pease. Byzantine Generals Problem is an impossibility result
which means that the solution to this problem has not been found yet as well as
helps us to understand the importance of blockchain. It is basically a game theory
problem that provides a description of the extent to which decentralized parties
experience difficulties in reaching consensus without any trusted central parties.
The Byzantine army is divided into many battalions in this classic problem called
the Byzantine General’s problem, with each division led by a general.
The generals connect via messenger in order to agree to a joint plan of action in
which all battalions coordinate and attack from all sides in order to achieve success.
It is probable that traitors will try to sabotage (destroy) their plan by intercepting or
changing the messages.
As a result, the purpose of this challenge is for all of the faithful commanders to
reach an agreement without the imposters tampering with their plans.
The Byzantine Fault Tolerance was developed as inspiration in order to address the
Byzantine General’s Problem. The Byzantine General’s Problem, a logical thought
experiment where multiple generals must attack a city, is where the idea for BFT
originated.
Byzantine Fault Tolerance is one of the core characteristics of developing
trustworthy blockchain rules or features is tolerance.
When two-thirds of the network can agree or reach a consensus and the system still
continues to operate properly, it is said to have BFT.
Blockchain networks’ most popular consensus protocols, such as proof-of-work,
proof-of-stake, and proof-of-authority, all have some BFT characteristics.
In order to create a decentralized network, the BFT is essential.
The consensus method determines the precise network structure. For instance, BFT
has a leader as well as peers who can and cannot validate.
In order to maintain the sequence of the Blockchain SC transactions and the
consistency of the global state through local transaction replay, consensus messages
must pass between the relevant peers.
13
Blockchain Unit-3 Sem-7
More inventive approaches to designing BFT systems will be found and put into
practice as more individuals and companies investigate distributed and decentralized
systems. Systems that use BFT are also employed in sectors outside of blockchains,
such as nuclear power, space exploration, and aviation.
14
Blockchain Unit-3 Sem-7
pBFT tries to provide a practical Byzantine state machine replication that can work
even when malicious nodes are operating in the system.
Nodes in a pBFT enabled distributed system are sequentially ordered with one node
being the primary (or the leader node) and others referred to as secondary (or the
backup nodes). Note here that any eligible node in the system can become the
primary by transitioning from secondary to primary (typically, in the case of a
primary node failure). The goal is that all honest nodes help in reaching a consensus
regarding the state of the system using the majority rule.
A practical Byzantine Fault Tolerant system can function on the condition that the
maximum number of malicious nodes must not be greater than or equal to one-third
of all the nodes in the system. As the number of nodes increase, the system becomes
more secure.
15
Blockchain Unit-3 Sem-7
Under normal conditions, a node can stay in any one of the above three states. Only a
leader can interact with the client; any request to the follower node is redirected to the
leader node. A candidate can ask for votes to become the leader. A follower only
responds to candidate(s) or the leader. To maintain these server status(es), the Raft
algorithm divides time into small terms of arbitrary length. Each term is identified by
a monotonically increasing number, called term number.
Term number
This term number is maintained by every node and is passed while communications
between nodes. Every term starts with an election to determine the new leader. The
candidates ask for votes from other server nodes(followers) to gather majority. If the
majority is gathered, the candidate becomes the leader for the current term. If no
majority is established, the situation is called a split vote and the term ends with no
leader. Hence, a term can have at most one leader.
Servers update their term number if their term number is less than the term numbers
of other servers in the cluster. This means that when a new term starts, the term
numbers are tallied with the leader or the candidate and are updated to match with the
latest one (Leader’s)Candidate or Leader demotes to the Follower state if their term
number is out of date (less than others). If at any point of time, any other server has a
higher term number, it can become the Leader immediately.
As we said earlier that the term number of the servers are also communicated, if a
request is achieved with a stale term number, the said request is rejected. This
basically means that a server node will not accept requests from server with lower
term number
16
Blockchain Unit-3 Sem-7
Raft algorithm uses two types of Remote Procedure Calls (RPCs) to carry out
the functions:
1. Request Votes RPC is sent by the Candidate nodes to gather votes during an election
2. Append Entries is used by the Leader node for replicating the log entries and also as
a heartbeat mechanism to check if a server is still up. If heartbeat is responded back
to, the server is up else, the server is down. Be noted that the heartbeats do not contain
any log entries.
The Raft protocol is designed to be easily understandable considering that the most
popular way to achieve consensus on distributed systems was the Paxos algorithm,
which was very hard to understand and implement. Anyone with basic knowledge and
common sense can understand major parts of the protocol and the research paper
published by Diego Ongaro and John Ousterhout
It is comparatively easy to implement than other alternatives, primarily the Paxos,
because of a more targeted use case segment, assumptions about the distributed
system. Many open-source implementations of the Raft are available on the internet.
Some are in Go, C++, Java
The Raft protocol has been decomposed into smaller subproblems which can be
tackled relatively independently for better understanding, implementation, debugging,
optimizing performance for a more specific use case
The distributed system following the Raft consensus protocol will remain operational
even when minority of the servers fail. For example, if we have a 5 server node
cluster, if 2 nodes fail, the system can still operate.
The leader election mechanism employed in the Raft is so designed that one node will
always gain the majority of votes within a maximum of 2 terms.
The Raft employs RPC (remote procedure calls) to request votes and sync up the
cluster (using Append Entries). So, the load of the calls does not fall on the leader
node in the cluster.
Raft was designed recently, so it employs modern concepts which were not yet
understood at the time of the formulation of the Paxos and similar protocols. Any
node in the cluster can become the leader. So, it has a certain degree of fairness.
Limitations: -
Raft is strictly single Leader protocol. Too much traffic can choke the system. Some
variants of Paxos algorithm exist that address this bottleneck.
There are a lot of assumptions considered to be acting, like non-occurrence of
Byzantine failures, which sort of reduces the real life applicability.
Raft is a more specialized approach towards a subset of problems which arise in
achieving consensus.
17
Blockchain Unit-3 Sem-7
51% Attack: -
A 51% attack is a very difficult and challenging task on a blockchain network with a
large participation rate. In most cases, the group of attackers would need to be able to
control the necessary 51% and have created an alternate blockchain that can be
inserted at exactly the right moment. Then, they would need to out-hash the main
network. The cost of doing this is one of the most significant factors that prevent a
51% attack.
For example, one of the most advanced application-specific integrated circuit (ASIC)
miners is the WhatsMiner M63S. It costs more than $10,000 (new) and has
a hash rate of 406 tera hashes per second (TH/s).
A single or smaller group of miners would not be able to alter and mine the Bitcoin
blockchain with only a few of these machines. It would take thousands of these
ASICs to get ahead of the Bitcoin network. Smaller networks could be out-hashed
using these mining rigs, but the benefits of doing so wouldn't outweigh the costs of
funding the attack and setting it up.
18
Blockchain Unit-3 Sem-7
FORKS IN BLOCKCHAIN:
In simple terms, Forks in blockchain means copying the code and modifying it to
create a new software or product. In open-source projects Forks are very common and
used widely. So, cryptocurrencies like Ethereum and Bitcoin are decentralized and
open software so that anyone can contribute.
As they are open-sources they rely on their communities to make the software more
secure and reliable. Also, open source with the help of fork can make user interface
more interactive and look good, helping in gaining more users worldwide. In open
source the code is visible to everyone, anyone can modify, edit, access there is no
copyright claims for such actions.
For example: Tor browser is an open-source software, Linux one of the most widely
use Operating system is an open-source system, in similar way Bitcoin and Ethereum
protocol are also open sourced.
19
Blockchain Unit-3 Sem-7
TYPES OF FORKS:
1. CODEBASE FORK:
In codebase blockchain fork you can copy the entire code of a particular software.
Let us take BITCOIN as an example, so suppose you copied the whole blockchain
code and modified it according to your need, say that you decreased the block
creation time, made some crucial changes and created a faster software than
BITCOIN and publish / launch it has a new whole software named against you, by
completing the whole white paper work process. So in these way a new
BLOCKCHAIN will be created from an empty blank ledger. It’s a fact that many of
these ALT COINS which are now running on the blockchain are been made in this
way only by using the codebase fork i.e. they have made little up and down changes
in the code of BITCOIN and created their whole new ALT COIN.
2. LIVE BLOCKCHAIN FORK
Live Blockchain fork means a running blockchain is been divided further into two
parts or two ways. So, in live blockchain at a specific page the software is same and
from that specific point the chain is divided into two parts. So, in context to this fork
the Live Blockchain Fork can occur because of two reasons:
ACCIDENTAL FORK / TEMPORARY FORK:
When multiple miners mine a new block at nearly the same time, the entire network
may not agree on the choice of the new block. Some can accept the block mined by
one party, leading to a different chain of blocks from that point onward while others
can agree on the other alternatives (of blocks) available. Such a situation arises
because it takes some finite time for the information to propagate in the entire
blockchain network and hence conflicted opinions can exist regarding the
chronological order of events. In this fork, two or more blocks have the same block
height.
Temporary forks resolve themselves eventually when one of the chains dies out (gets
orphaned) because majority of the full nodes choose the other chain to add new
blocks to and sync with.
INTENTIONAL FORK:
In intentional fork the rules of the blockchain are been changed, knowing the code of
the software and by modifying it intentionally. This gives rise to two types of forks
which can occur based on the backwards-compatibility of the blockchain protocol
and the time instant at which a new block is mined. So Intentional fork can be of two
types:
20
Blockchain Unit-3 Sem-7
Add new functionality: The Blockchain code is upgraded regularly. Since most
public blockchains are open source, it is developed by people from around the world.
The improvements, issues are created, resolved and new versions are released when
the time is suitable.
Fix security issues: Blockchain (and cryptocurrency on top of it) is a relatively new
technology as compared to the traditional currency (notes, coins, cheque), research is
still underway to fully understand it. So, versions are bumped and updates are
released to fix the security issues that arise in the way.
Reverse transactions: The community can actually void all the transaction of a
specific period if they are found to be breached and malicious.
21