
Decentralized Blockchain System
A minimal decentralized blockchain prototype built from scratch in Node.js. Nodes communicate over WebSockets, synchronize state using a custom protocol, and converge using a Longest Valid Chain rule — demonstrating the mechanics of trust without a central server.
⚡ Engineering Challenge: Decentralized State Convergence
The challenge wasn’t “creating blocks”. The real challenge was state agreement. In a P2P network, nodes can start at different times, mine independently, or receive conflicting updates. The system must reconcile safely: validate integrity, compare chains, and converge deterministically.
Protocol-First P2P Determinism
Implemented explicit message types (HELLO, REQ_CHAIN, RES_CHAIN, NEW_BLOCK) to make sync predictable, debuggable, and repeatable under different node start orders.
Validation as a Gate Integrity
Every incoming block and chain must pass strict validation: previousHash linking, hash correctness, and difficulty rule. Invalid data is rejected before it can mutate local state.
🧠 Consensus & Sync Strategy
When a node joins the network, it broadcasts REQ_CHAIN. Peers respond with RES_CHAIN. If a longer valid chain is found, the node replaces its local chain. This models a practical consensus rule: Longest Valid Chain wins.
After mining a block, the node broadcasts NEW_BLOCK. Each peer validates and either: (1) appends the block, or (2) requests a full chain sync if it detects inconsistency.
🏗️ High-level Architecture
📸 System Evidence (Logs & Chain Snapshots)
Real screenshots from the project showing multi-node execution and chain state across peers.
The key takeaway: nodes remain consistent by enforcing validation and reconciling via chain replacement when needed.
