Skip to content

High-performance Rust simulation comparing Monolithic vs. Sharded blockchain architectures. Features 2-Phase Commit and Cross-Shard Receipt routing.

License

Notifications You must be signed in to change notification settings

SemiuAdesina/rust-sharding-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 Rust Sharding Simulator (Advanced)

A high-performance blockchain architecture simulation comparing Traditional (Monolithic) vs. Sharded (Parallel) processing, written in Rust.

Project Origin: This project is an original implementation by Semiu Adesina. It converts the theoretical concepts of "Range Partitioning" and "Sharding" described in the book Rust For Blockchain Application Development by Akhil Sharma into actual, executable code. Note: The book provided the theory; this repository contains the custom Rust implementation of those ideas.

📖 Project Overview

This project simulates the architecture of a Layer 1 Blockchain to demonstrate scalability solutions. It benchmarks two approaches:

  1. Traditional Model: A sequential, single-threaded ledger (similar to Bitcoin/Ethereum 1.0).
  2. Sharded Model: A parallel, multi-threaded network using a Two-Phase Commit system to handle complex cross-shard transactions (similar to NEAR Protocol or Ethereum 2.0).

🚀 Key Features

  • Parallel Execution: Uses Rust threads to spawn independent Shard Validators.
  • Cross-Shard Communication: Implements a "Receipt" and "Settlement" system.
    • Phase 1: Debit Sender & Generate Receipt.
    • Phase 2: Route Receipt to Destination Shard & Credit Receiver.
  • Cryptographic Simulation: Transactions now require valid digital signatures to be processed.
  • Deterministic Routing: Uses ASCII modulo arithmetic to assign addresses to shards automatically.

📊 Benchmark Results

Results taken from a local run (MacBook M1/M2) with 100 Transactions:

Architecture Strategy Execution Time Notes
Traditional Single Thread ~626ms Linear bottleneck.
Sharded 4 Threads ~560ms Includes overhead for cross-shard settlement.

Analysis: The test scenario involved 100% Cross-Shard Transactions (Alice in Shard 1 sending to Charlie in Shard 3). This forces the Sharded network to perform double the work (Receipt Generation + Settlement). Despite this heavy overhead, the Sharded architecture still outperformed the Traditional one due to parallel execution.

🛠 How It Works (The Architecture)

🏛 Architecture Visualization

Here is the visualization of the Cross-Shard "Receipt" lifecycle simulated in this project:

sequenceDiagram
    participant Alice
    participant Shard1 as ⛓️ Shard 1 (Sender)
    participant Receipt as 📨 Receipt System
    participant Shard3 as ⛓️ Shard 3 (Receiver)
    participant Charlie

    Note over Alice, Shard1: Phase 1: Execution
    Alice->>Shard1: Send 10 Coins (Signed Tx)
    Shard1->>Shard1: 1. Verify Signature 🔐
    Shard1->>Shard1: 2. Debit Alice (-10)
    Shard1->>Receipt: 3. Generate Receipt

    Note over Receipt, Shard3: Phase 2: Settlement
    Receipt->>Shard3: Route Receipt to Dest
    Shard3->>Shard3: 4. Verify Receipt
    Shard3->>Charlie: 5. Credit Charlie (+10)
Loading

1. The Sharding Algorithm

Users are assigned to shards based on the first letter of their name (Range Partitioning):

// logical routing
let shard_id = (first_char as usize) % NUM_SHARDS;

About

High-performance Rust simulation comparing Monolithic vs. Sharded blockchain architectures. Features 2-Phase Commit and Cross-Shard Receipt routing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages