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.
This project simulates the architecture of a Layer 1 Blockchain to demonstrate scalability solutions. It benchmarks two approaches:
- Traditional Model: A sequential, single-threaded ledger (similar to Bitcoin/Ethereum 1.0).
- 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).
- 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.
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.
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)
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;