Tanguyvans / consensus_protocols

This repository serves as a simple yet comprehensive introduction to various consensus protocols. Explore basic implementations of consensus algorithms, gain insights into their workings, and use them as a foundation for understanding distributed systems.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python consensus protocols

Build Status Python Coverage License

This project aims to provide a simple way to visualize and interact with various consensus protocols implemented in Python. The included protocols are designed to facilitate understanding and exploration of their mechanisms. It's important to note that these implementations are intended for educational purposes and are not meant for direct production use.

Table of content

Installation

pip install -r requirements.txt

Protocols

As for now, I have create 1 consensus protocols. Moving forward, I'll do my best to implement new protocols regulally.

PBFT (Practical Byzantine Fault Tolerance) Protocol

The PBFT protocol is a consensus algorithm designed to achieve fault tolerance in distributed systems, particularly in the presence of malicious nodes or Byzantine faults. It is commonly used in permissioned blockchain networks where nodes are known and can be trusted.

How PBFT Works

  1. Request Phase:

    • A client initiates a request by sending a message to all nodes in the network.
    • Nodes receive the client's request and move to the pre-prepare phase.
  2. Pre-Prepare Phase:

    • The node that receives the client's request first becomes the primary node for this round.
    • The primary node creates a block containing the client's request and sends a "pre-prepare" message to all other nodes.
    • Other nodes receive the pre-prepare message, validate it, and move to the prepare phase.
  3. Prepare Phase:

    • Nodes broadcast "prepare" messages to all other nodes, indicating that they have validated the pre-prepare message.
    • Nodes wait for 2f + 1 prepare messages to move to the commit phase, where f is the maximum number of faulty nodes the system can tolerate.
  4. Commit Phase:

    • Once a node receives 2f + 1 prepare messages, it sends a "commit" message to all other nodes.
    • Nodes wait for 2f + 1 commit messages to finalize the consensus on the block.
    • Once a node has enough commit messages, it commits the block to its local blockchain.

Important Points to Note

  • Fault Tolerance: PBFT is designed to tolerate up to (n-1)/3 malicious or faulty nodes, where n is the total number of nodes in the network.
  • Deterministic Execution: PBFT ensures deterministic execution, meaning that all honest nodes will reach the same consensus state.
  • Performance: PBFT is suitable for scenarios where low-latency and high-throughput are essential, making it practical for permissioned blockchain networks.

Usage Considerations

It's important to understand that PBFT is most effective in scenarios where the majority of nodes are honest and the number of faulty nodes is within the specified tolerance limit. Additionally, PBFT is primarily designed for educational purposes and may require further customization for production use.

About

This repository serves as a simple yet comprehensive introduction to various consensus protocols. Explore basic implementations of consensus algorithms, gain insights into their workings, and use them as a foundation for understanding distributed systems.

License:MIT License


Languages

Language:Python 100.0%