Skip to content

ziuus/Dynamic-Blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⛓️ Dynamic Interconnection Blockchain

A next-generation hybrid blockchain architecture that offloads high-frequency transactions from the main chain to dynamic, ephemeral peer-to-peer state channels β€” dramatically improving throughput while preserving on-chain security and finality.

Node.js License: MIT Architecture: Hybrid GitHub Sponsors PRs Welcome


🧠 The Problem

Traditional blockchains suffer from the scalability trilemma: as transaction volume grows, the network faces:

  • ⏱️ Congestion β€” mempool backlogs, slow confirmations
  • πŸ’Έ High fees β€” gas wars during peak load
  • πŸ“‰ Degraded throughput β€” Bitcoin ~7 TPS, Ethereum ~15–30 TPS

πŸ’‘ The Solution: Ephemeral Off-Chain Channels

This model introduces Dynamic Interconnection Channels β€” ephemeral, bilateral state channels that:

  1. Lock initial balances on-chain (one transaction)
  2. Transact off-chain at infinite speed with no fees
  3. Settle final state back on-chain (one transaction)

The result: ∞ TPS for channel participants, with on-chain security guarantees for final settlement.


πŸ“Š Benchmark Results

Main Chain (PoW, difficulty 2):     ~3,846 TPS
Ephemeral Channels (off-chain):         ∞ TPS
Settlement overhead:                    0 ms
On-chain footprint per channel:    2 txs (open + close)

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    REST API Layer                    β”‚
β”‚              Express HTTP (port 3000+)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Node Layer                        β”‚
β”‚         Identity Β· Peers Β· State Management          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Main Chain      β”‚  β”‚   Ephemeral Channel Layer    β”‚
β”‚  Block Β· PoW      β”‚  β”‚  Channel Β· ChannelManager    β”‚
β”‚  Merkle Β· Txs     β”‚  β”‚  Off-chain State Β· Settle    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  P2P Network Layer                  β”‚
β”‚            WebSocket Gossip Protocol                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Module Map

Path Responsibility
core/Block.js Block structure, PoW mining, Merkle root
core/Blockchain.js Chain management, validation, balance tracking
core/Transaction.js Transaction format, hashing, signature validation
ephemeral/Channel.js Bilateral off-chain state channel lifecycle
ephemeral/ChannelManager.js Multi-channel orchestration per node
network/Node.js Node identity, peer management, state
network/P2P.js WebSocket-based P2P gossip protocol
api/server.js REST API (blockchain, channels, mining, P2P)
simulation/runNetwork.js Multi-node network simulation
simulation/benchmark.js Throughput comparison benchmark

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (npm install -g pnpm)

Install

git clone https://github.com/ziuus/Dynamic-Blockchain.git
cd Dynamic-Blockchain
pnpm install

Run the API Server

pnpm start
# API available at http://localhost:3000

Run the Network Simulation (3 nodes)

pnpm simulate
# Spins up 3 nodes with P2P sync, channels, and mining

Run the Benchmark

pnpm benchmark
# Compares main chain TPS vs ephemeral channel TPS

πŸ”Œ REST API Reference

Blockchain

Method Endpoint Description
GET /api/blockchain Full chain state
GET /api/blockchain/height Current block height
GET /api/blockchain/valid Chain validity check
GET /api/block/:index Block by index

Transactions

Method Endpoint Description
POST /api/transactions Submit a transaction
GET /api/transactions/pending Mempool
GET /api/transactions/history/:address Address history
POST /api/mine Mine pending transactions
GET /api/balance/:address Address balance

Ephemeral Channels

Method Endpoint Description
POST /api/channels Open a new channel
GET /api/channels List all channels
GET /api/channels/:id Channel details
GET /api/channels/for/:address Channels for address
POST /api/channels/:id/transactions Off-chain transaction
POST /api/channels/:id/settle Settle channel on-chain
POST /api/channels/:id/close Force close channel
GET /api/channels/stats Channel statistics

Node & P2P

Method Endpoint Description
GET /api/node/status Node health & stats
GET /api/p2p/peers Connected peers
POST /api/p2p/connect Connect to peer
POST /api/p2p/sync Trigger sync
GET /api/health Health check

πŸ”¬ How Ephemeral Channels Work

Alice                    Channel Contract              Bob
  β”‚                           β”‚                         β”‚
  │──── open(1000, 1000) ────►│                         β”‚
  β”‚                           │◄── open(1000, 1000) ────│
  β”‚                           β”‚  [On-chain: 1 tx]        β”‚
  β”‚                                                      β”‚
  │◄──────────────── off-chain transactions ────────────►│
  │   (tx1: Alice→Bob 50)  (tx2: Bob→Alice 20)  ...     │
  β”‚   [Instant, zero fees, unlimited]                    β”‚
  β”‚                                                      β”‚
  │──── settle() ──────────────────────────────────────►│
  β”‚   [On-chain: 1 settlement tx with final balances]   β”‚

Security: All off-chain state is cryptographically signed. Either party can force-close using the latest agreed state at any time.


πŸ—ΊοΈ Roadmap

  • Core blockchain (PoW, Merkle, validation)
  • Ephemeral state channels
  • P2P WebSocket gossip
  • REST API
  • Simulation & benchmark suite
  • Dashboard UI (real-time network visualizer)
  • Proof-of-Stake consensus layer
  • Multi-hop channel routing (payment network)
  • RSA keypair-based transaction signing
  • Persistent storage (LevelDB)
  • Docker / multi-node devnet setup

πŸ“ Project Structure

Dynamic-Blockchain/
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ Block.js           # Block with PoW + Merkle root
β”‚   β”œβ”€β”€ Blockchain.js      # Main chain state machine
β”‚   └── Transaction.js     # Transaction format & validation
β”œβ”€β”€ ephemeral/
β”‚   β”œβ”€β”€ Channel.js         # Off-chain state channel
β”‚   └── ChannelManager.js  # Channel lifecycle manager
β”œβ”€β”€ network/
β”‚   β”œβ”€β”€ Node.js            # P2P node identity & state
β”‚   └── P2P.js             # WebSocket gossip protocol
β”œβ”€β”€ api/
β”‚   └── server.js          # Express REST API
β”œβ”€β”€ simulation/
β”‚   β”œβ”€β”€ runNetwork.js      # 3-node network simulator
β”‚   └── benchmark.js       # Throughput benchmarking
β”œβ”€β”€ docs/
β”‚   └── ARCHITECTURE.md    # Deep-dive architecture docs
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
└── README.md

🀝 Contributing

All contributions are welcome β€” from beginners to experts. You don't need to know everything about blockchain to help!

Ways to contribute:

Type How
πŸ› Bug report Open an issue
πŸ’‘ Feature idea Start a discussion
πŸ”§ Code Fork β†’ branch β†’ PR (see CONTRIBUTING.md)
πŸ“– Docs Fix typos, improve explanations, add examples
⭐ Star Helps the project get discovered β€” much appreciated!

πŸ’– Support the Project

This is an independent open-source project built and maintained in spare time. If it's useful to you β€” or you just want to see it grow β€” any support means a lot:

  • ⭐ Star the repo β€” it's free and helps enormously with discovery
  • 🐦 Share it β€” tweet it, post it, tell a friend
  • πŸ’° Sponsor β€” github.com/sponsors/ziuus
  • πŸ› οΈ Contribute β€” code, docs, tests, ideas β€” all welcome
  • πŸ› Report bugs β€” helps everyone using the project

Every star, share, and contribution directly funds time to work on the roadmap: PoS consensus Β· LevelDB storage Β· multi-hop routing Β· test suite Β· Docker devnet


πŸ“„ License

MIT Β© ziuus