Module 3 Distributed Consensus Updated
Module 3 Distributed Consensus Updated
Distributed Consensus
Video/ Youtube Link
LEC07 | Blockchain | Distributed Consensus by Mrs. G. Sowmya
(youtube.com)
1. Paxos Algorithm
Paxos is a classic consensus algorithm which ensures that a distributed system can agree on a
single value or sequence of values, even if some nodes may fail or messages may be
delayed. Key concepts of paxos algorithm include:
Paxos Algorithm
Roles:
o Proposer: Initiates the proposal of a value.
o Acceptor: Accepts proposals from proposers and communicates its acceptance.
o Learner: Learns the chosen value from acceptors.
Phases:
o Phase 1 (Prepare): Proposers send prepare requests to a majority of acceptors to
prepare them to accept a proposal.
o Phase 2 (Accept): Proposers send accept requests to acceptors with a proposal,
which is accepted if a majority of acceptors agree.
Working:
o Proposers: Proposers initiate the consensus process by proposing a value to be
agreed upon.
o Acceptors: Acceptors receive proposals from proposers and can either accept or
reject them based on certain criteria.
o Learners: Learners are entities that receive the agreed-upon value or decision
once consensus is reached among the acceptors.
Safety and Liveness:
o Paxos ensures safety (only one value is chosen) and liveness (a value is eventually
chosen) properties under normal operation assuming a majority of nodes are
functioning correctly.
Use Cases:
o Paxos is used in distributed databases, replicated state machines, and other
systems where achieving consensus among nodes is critical.
2. Raft Algorithm
The Raft algorithm is a consensus algorithm designed to achieve consensus among a cluster
of nodes in a distributed system. It simplifies the complexities of traditional consensus
algorithms like Paxos while providing similar guarantees. Raft operates by electing a leader
among the nodes in a cluster, where the leader manages the replication of a log that contains
commands or operations to be executed.
Raft Algorithm
Key Concepts:
o Leader Election: Nodes elect a leader responsible for managing log replication
and handling client requests.
o Log Replication: Leader replicates its log entries to followers, ensuring
consistency across the cluster.
o Safety and Liveness: Raft guarantees safety (log entries are consistent) and
liveness (a leader is elected and log entries are eventually committed) under
normal operation.
Phases:
o Leader Election: Nodes participate in leader election based on a term number
and leader’s heartbeat.
o Log Replication: Leader sends AppendEntries messages to followers to replicate
log entries, ensuring consistency.
Use Cases:
o Raft is widely used in modern distributed systems such as key-value stores,
consensus-based replicated databases, and systems requiring strong consistency
guarantees.
Byzantine Fault Tolerance (BFT) algorithms are designed to address the challenges posed by
Byzantine faults in distributed systems, where nodes may fail in arbitrary ways, including
sending incorrect or conflicting information. These algorithms ensure that the system can
continue to operate correctly and reach consensus even when some nodes behave maliciously
or fail unexpectedly.
BFT Algorithm
Key Concepts:
o Byzantine Faults: Nodes may behave arbitrarily, including sending conflicting
messages or omitting messages.
o Redundancy and Voting: BFT algorithms typically require a 2/3 or more
agreement among nodes to determine the correct state or decision.
Examples:
o Practical Byzantine Fault Tolerance (PBFT): Used in systems where safety and
liveness are crucial, such as blockchain networks and distributed databases.
o Simplified Byzantine Fault Tolerance (SBFT): Provides a simpler approach to
achieving BFT with reduced complexity compared to PBFT.
Use Cases:
o BFT algorithms are essential in environments requiring high fault tolerance and
security, where nodes may not be fully trusted or may exhibit malicious behavior.
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. pBFT consensus rounds are broken into 4
phases.
The client sends a request to the primary(leader) node.
The primary(leader) node broadcasts the request to the all the secondary(backup) nodes.
The nodes(primary and secondaries) perform the service requested and then send back a
reply to the client.
The request is served successfully when the client receives ‘m+1’ replies from different
nodes in the network with the same result, where m is the maximum number of faulty
nodes allowed.
Network Partitions and Delays: Algorithms must handle network partitions and
communication delays, ensuring that nodes eventually reach consensus.
Scalability: As the number of nodes increases, achieving consensus becomes more
challenging due to increased communication overhead.
Performance: Consensus algorithms should be efficient to minimize latency and
maximize system throughput.
Understanding and Implementation: Many consensus algorithms, especially BFT
variants, are complex and require careful implementation to ensure correctness and
security.
In summary, distributed consensus algorithms are crucial for enabling cooperation and
coordination among nodes in distributed systems. They ensure that all nodes agree on a
consistent state or decision, providing reliability, fault tolerance, and consistency across
decentralized networks in various applications from distributed databases to blockchain
networks.
Each algorithm has its strengths and trade-offs, making them suitable for
different use cases depending on the system’s requirements for performance,
fault tolerance, and security
Practical Applications of Distributed Consensus in Distributed Systems
Below are some practical applications of distributed consensus in distributed systems:
Blockchain Technology:
o Use Case: Blockchain networks rely on distributed consensus to agree on the
validity and order of transactions across a decentralized ledger.
o Example: Bitcoin and Ethereum use consensus algorithms (like Proof of Work
and Proof of Stake) to achieve decentralized agreement among nodes.
Distributed Databases:
o Use Case: Consensus algorithms ensure that distributed databases maintain
consistency across nodes, ensuring that updates and transactions are applied
uniformly.
o Example: Google Spanner uses a variant of Paxos to replicate data and ensure
consistency across its globally distributed database.
Cloud Computing:
o Use Case: Cloud providers use distributed consensus to manage resource
allocation, load balancing, and fault tolerance across distributed data centers.
o Example: Amazon DynamoDB uses quorum-based techniques for replication and
consistency among its distributed database nodes.
Blockchain Distributed Consensus Mechanism
Blockchain uses a specific kind of distributed consensus to manage transactions and maintain
a secure, decentralized record (ledger). Key mechanism include:
Proof of Work (PoW):
o Concept: Computers (miners) solve difficult math puzzles to validate and add
new blocks of transactions to the blockchain.
o Consensus: The longest chain with the most computational effort is considered
the valid chain, ensuring agreement on the transaction history.
Proof of Stake (PoS):
o Concept: Validators are chosen based on the amount of cryptocurrency they hold
and stake in the network.
o Consensus: Validators are selected to propose and validate blocks of transactions
based on their stake, promoting fairness and security.
Practical Byzantine Fault Tolerance (PBFT):
o Concept: Nodes agree on the order of transactions through a voting process
where two-thirds of the nodes must agree.
o Consensus: Used in networks where participants are known and trusted, ensuring
fast transaction confirmation and high throughput.
Delegated Proof of Stake (DPoS):
o Concept: Token holders vote for delegates who are responsible for validating
transactions and producing blocks.
o Consensus: Delegates with the most votes perform block production, balancing
decentralization with efficiency and governance.
Challenges and Considerations for Scalabilty, Fault Tolerance and Resilience
1. Scalability Issues:
Scalability refers to a system’s ability to handle increasing amounts of work or users without
compromising performance or efficiency.
Challenge: As the number of nodes (computers) in a distributed system grows, achieving
consensus becomes more complex due to increased communication overhead and
potential delays.
Considerations:
o Sharding: Partitioning data into smaller subsets (shards) to distribute the
workload and reduce the burden on individual nodes.
o Optimized Protocols: Developing efficient communication protocols and
algorithms to minimize message exchanges and latency.
o Parallel Processing: Utilizing parallel processing techniques to handle multiple
tasks simultaneously, improving overall throughput.
Fault tolerance refers to a system’s ability to continue operating in the presence of hardware
or software failures, ensuring data integrity and availability.
Challenge: Nodes in a distributed system can fail unexpectedly or behave maliciously
(Byzantine faults), disrupting consensus and potentially compromising the system’s
reliability.
Considerations:
o Redundancy: Implementing redundant nodes or replicas to replicate data and
tasks across multiple nodes, ensuring continuity even if some nodes fail.
o Consensus Mechanisms: Using robust consensus algorithms (e.g., Practical
Byzantine Fault Tolerance – PBFT) that can tolerate a certain percentage of faulty
or malicious nodes.
o Monitoring and Recovery: Implementing monitoring systems to detect failures
promptly and automated recovery mechanisms to restore system integrity.
What Is Nakamoto Consensus?
Nakamoto Consensus, named after the pseudonymous creator of Bitcoin, Satoshi Nakamoto,
is a Byzantine Fault Tolerant (BFT) consensus mechanism that combines Proof-of-Work with
the "longest chain" rule to create a consensus protocol that adequately maintains the
authenticity of decentralized blockchain networks.
Because Nakamoto Consensus is what makes Bitcoin a Byzantine Fault Tolerant system, it’s
worth first exploring what that means.
BFT is basically a characteristic of distributed computer networks that can still work even
when some of their nodes are going rogue or acting unpredictably or maliciously. Since
blockchains are exactly that—distributed computer networks—they implement complex
protocols to achieve consensus in a “Byzantine Fault Tolerant” way.
As already mentioned, Nakamoto Consensus combines two novel ideas to achieve Byzantine
Fault Tolerance: Proof-of-Work, and the “longest chain” rule.
The process of validating blockchain transactions involves miners attempting to find a valid
solution to a cryptographic puzzle associated with a new block of transactions. The only way
for miners to find the solution to the Proof-of-Work puzzle is through trial and error, or by
making thousands of guesses per second until they find one answer that matches the
protocol's criteria. The first miner to find the correct answer gets to mine a new block (that,
once validated by all the other full nodes in the network, is appended to the blockchain) and,
in return, is rewarded with newly minted cryptocurrency.
Finding the Proof-of-Work solution, however, requires significant computing power and
energy consumption, meaning miners also have something to lose, not only gain. This means
that the Proof-of-Work algorithm relies on a robust incentive mechanism that (i) guarantees
adequate punishment for any individual entity trying to circumvent or cheat the protocol and
(ii) awards sufficient privileges to all distributed entities that follow the rules of the
agreement.
Colloquially, this is also known as the "carrot and stick" approach, where the stick is the
electrical energy required for computing complex problems that every mining node must do
to participate in the mining process (i.e., the process of validating transactions), and the carrot
is the block rewards in the form of newly minted bitcoin. In other words, the mining nodes
that follow the rules of the Proof-of-Work protocol get rewarded with newly minted bitcoins,
while cheating nodes are left with nothing but a hefty electrical bill for doing useless work.
This is how Proof-of-Work-based blockchains can achieve real-time consensus between all
participating nodes on the ledger's true state.
The longest chain rule, a key component of Nakamoto Consensus, states that in the event of
competing blockchain forks, the chain with the most accumulated computational work, as
measured by the number of blocks in the chain, is considered the correct and valid chain.
This means that miners are incentivized to extend the blockchain with the most accumulated
computational work because doing so increases the likelihood that their blocks will be added
to the correct chain and rewarded with cryptocurrency. In other words, the longest chain rule
encourages miners to work on the same chain and ensures that the blockchain is maintained
and extended by the majority of the network.
The longest chain rule helps prevent attacks on the network by making it extremely difficult
for an attacker to create a longer valid chain than the existing one. Any attacker attempting to
create a new, competing chain would need more computational power than the rest of the
network combined, which is currently infeasible for most blockchains due to the high cost of
acquiring and maintaining that much computational power.
Overall, the longest chain rule is a critical aspect of Nakamoto Consensus, as it provides a
simple and effective way for the network to converge on a single, valid version of the
blockchain, ensuring that the network operates securely and reliably.
Conclusion
By utilizing Proof-of-Work and the longest chain rule, Nakamoto Consensus ensures that
blockchains remain secure and resistant to attacks. While it has limitations, this consensus
mechanism has proven to be a powerful and reliable tool for maintaining the integrity of
blockchain networks.
For this reason, many cryptocurrencies beyond Bitcoin use different implementations of
Nakamoto Consensus in their protocols. For example, Nervos’ Layer 1, Common Knowledge
Base, uses Nakamoto Consensus Max (NC-Max), an improved version of the original
Nakamoto Consensus that provides better security and performance.
Sybil attack
It exploits the decentralized nature of blockchain networks by allowing a single entity to
impersonate multiple users, effectively controlling a larger portion of the network than
they legitimately deserve.
Working Principle:
The attacker registers numerous fake identities (Sybil nodes) on the blockchain
network.
These Sybil nodes are used to manipulate the network, for example, by voting in a
way that favors the attacker or overwhelming the network with fraudulent
transactions.
The goal is to gain control or influence over the network's decisions, potentially
leading to censorship, data manipulation, or even a 51% attack (where the attacker
controls more than half of the network's computing power).
Energy Utilization:
Blockchain makes transactions traceable, safe, and rapid. This technology encourages
the generation and consumption of 100% renewable energy by improving the green energy
supply's efficiency, flexibility, and transparency.
A dApp has a backend code running on a decentralized peer-to-peer network. It can also
have a frontend code and a user interface that can be written in any language just as it is
done for normal applications. The front end can be hosted on any decentralized server like
IPFS. dApps work in a manner similar to normal applications except for the few differences
that are discussed below:
The dApp working has the following features:
Decentralized: A dApp operates on Ethereum which is an open public decentralized
platform.
Deterministic: dApps perform the same function irrespective of the environment in
which they are executed.
Turing complete: dApps can perform any action given the required resources.
Isolated: dApps are executed in an Ethereum Virtual Machine which is a virtual
environment that ensures that even if there is a bug in the smart contract, it won’t
hamper the normal functioning of the blockchain network.
Open source: All the required are decided on the majority of the other nodes available
in the network.
Storage: As the name is decentralized data are stored on the decentralized blocks.
Validation: As the Application runs on the blockchain system, they use a cryptographic
token which is a need of the network.
In a centralized application, a
In a decentralized application, a file
minimum number of applications
Size resides on each of the client’s
and files reside on the client’s
workstations
system
Pros of dApp
Faster Adoption: A decentralized application provides freedom to the user to run the
app without having to trust any other party and thus results in faster adoption of the
application. The smart contract is deployed on the blockchain the network is whole and
will be able to serve clients that are looking to interact with the contracts.
Less pause: These applications are more flexible than the centralized ones as they do
not rely on a single server. So, enterprises can ensure minimum interruption and
downtime for continuity of the network, a single node working in a decentralized
network can stay available even though the performance of the network may be
downgraded.
Cost reduction: Unlike centralized systems which require a high installation cost of the
server and experts to manage and maintain the server. This decentralized application
eliminates the cost of the network.
Highly autonomous: These applications are considered to be more secure when
compared with traditional applications. These applications do not face any security
breaches as they do not have any central structure from which threats occur. The
decentralized application seems to be more secure as the creator also cannot the flow of
the network
No censorship: The coding used in this type of application is totally open source. The
absence of all corporations to govern the application is a major reason to provide
resistance to censorship
New opportunities: Since it is a new technology there are less number of users and this
gives a lot of opportunities for the early adopters. No single entity can block the other
user from submitting the transaction or reading the data from the blockchain.
Cons of dApp
Slow speed: In the decentralized system, it occurs in some transactions are delayed in
the process, this add lags time to the process which is executing in the network. This
becomes the sole reason for the business not to rely on decentralized applications. The
network can only process around 10-15 transactions per second.
Hard Maintenance: Dapps are as difficult as it is hard to modify the code and data
published on the blockchain. Once the Dapps are deployed developers also find it hard
to make changes even if the bug is identified.
Hard to use: It is as an end-user as the average end-user finds it too difficult to set up
the necessary stack to interact with the blockchain insecure manner. To make it
somewhere user-friendly one solution is to build a base layer on the top of the apps
which ended up as a centralized app.
End-user experience: Since Dapps is solving the major aspect of security and
efficiency the end-user experience is neglected. This may impact their digital
penetration rate and the rate at which people will adopt this technology.
Immutable: We have seen the Immutability of dApps as a benefit but it can have some
disadvantages also i.e. smart contracts are developed by humans and as human error is
unavoidable these dApps have a high potential to become a huge problem.
There are many Blockchain platforms created by various companies. While the most
popular and commonly heard one is Bitcoin, there are many others that are used to create
dApps. These Blockchain platforms are further used as a base to create dApps. So let’s see
some of these now:
1. Ethereum: Ethereum is the most popular decentralized, open-source blockchain in the
world currently. It is used as the base for many Blockchain projects, including more
than 2500 dApps. In fact, Ethereum is only second to Bitcoin in terms of its market
value. Ethereum also has a native cryptocurrency known as BTH which is their version
of Bitcoin. All in all, this is an excellent option for creating a dApp although it’s a bit
expensive.
2. NEO: NEO is also a decentralized, open-source blockchain that aims to create a smart
economy. It is also called the Chinese Ethereum and provides better options for
scalability in dApps as compared to other Blockchain platforms. NEO is currently less
popular than Ethereum with only about 100 dApps built using this technology. It’s also
quite expensive and can even charge higher fees than Ethereum in some cases.
3. TRON: TRON is a comparatively new Blockchain platform as compared to Ethereum
or NEO. However, it’s quite popular and may even become a competitor to Ethereum in
the future. TRON is particularly famous for gaming applications and gambling sites.
There are around 1500 dApps created using this platform which makes it an excellent
choice.
Advantages of dApps
Disadvantages of dApps
Conclusion
dApps are the continuation of Blockchain culture and a wonderful invention because of
their focus on security and transparency. While there are relatively few dApps in the market
as compared to conventional apps, that’s only because Blockchain is a new technology, and
dApps will become more and more popular when Blockchain becomes commonplace.