Skip to content

Latest commit

 

History

History
104 lines (75 loc) · 4.03 KB

File metadata and controls

104 lines (75 loc) · 4.03 KB

⛓️ Transaction Pool Simulator

A real-time blockchain transaction pool (mempool) simulator built with Python.

This simulator models:

  • ⛽ Gas fee prioritization
  • 🧮 Fairness scoring based on network congestion
  • ⌛ Transaction expiration
  • 🔁 Real-time updates under simulated market conditions

Designed as a lightweight and educational simulation of how unconfirmed transactions are handled in a blockchain network like Ethereum or Bitcoin.


💡 What This Project Simulates

This project simulates the mempool (memory pool) of a blockchain like Bitcoin or Ethereum — the place where transactions wait before being confirmed and added to a block by miners.

In a real blockchain:

  • Users submit transactions with fees to incentivize miners.
  • The mempool stores all pending transactions.
  • Miners choose which transactions to include in a block — usually those with the highest fees.
  • Transactions expire or get replaced if they wait too long or offer low fees in times of congestion.

This simulator:

  • Models a transaction pool with size limits.
  • Simulates random transactions with different fees and sizes.
  • Assigns fairness scores based on network congestion and fee-to-size ratio.
  • Updates the pool every second and removes expired transactions.

It’s a simplified but realistic system for learning how blockchains prioritize and process transactions under varying market conditions.


📦 Features

✅ Fee-based transaction prioritization
✅ Fairness score system (based on network congestion and fee-to-size ratio)
✅ Transaction expiration logic
✅ Randomized transaction generation
✅ Real-time pool updates every second
✅ Console-based visual display


🏗️ How It Works

  1. A transaction is created with:
    • Random fee (gas)
    • Size in bytes
    • Timestamp
    • Random ID
  2. Based on network congestion, each transaction is scored for fairness:
    • High congestion → High fee = possible front-running → penalized
    • Low congestion → Good fee-to-size ratio → rewarded
  3. Transactions expire after 30 seconds
  4. Only the top 100 transactions are kept in the pool
  5. Pool is updated and printed every second

🧪 Sample Output

Transaction Pool (Current Time: 2025-08-07 13:17:16.345998):
TxID:7710, Fee:100, Timestamp:1754552836.3459983, Size:140, Fairness:100, Expiry:1754552866.3459983
TxID:2018, Fee:5, Timestamp:1754552835.3308325, Size:260, Fairness:5, Expiry:1754552865.3308325
Transaction Pool (Current Time: 2025-08-07 13:17:17.354650):
TxID:7710, Fee:100, Timestamp:1754552836.3459983, Size:140, Fairness:100, Expiry:1754552866.3459983
TxID:7456, Fee:50, Timestamp:1754552837.35465, Size:177, Fairness:50, Expiry:1754552867.35465
TxID:2018, Fee:5, Timestamp:1754552835.3308325, Size:260, Fairness:5, Expiry:1754552865.3308325
Transaction Pool (Current Time: 2025-08-07 13:17:18.359505):
TxID:7710, Fee:100, Timestamp:1754552836.3459983, Size:140, Fairness:100, Expiry:1754552866.3459983
TxID:7456, Fee:50, Timestamp:1754552837.35465, Size:177, Fairness:50, Expiry:1754552867.35465
TxID:2018, Fee:5, Timestamp:1754552835.3308325, Size:260, Fairness:5, Expiry:1754552865.3308325
TxID:1668, Fee:1, Timestamp:1754552838.359506, Size:432, Fairness:0.5357813275830596, Expiry:1754552868.359506

🧠 Concepts Demonstrated

Concept Implementation
Priority Queues via heapq for fee-based transaction order
Fairness Metrics dynamically adjusted using congestion level
Mempool Simulation mimics how unconfirmed transactions are stored
Transaction Expiry removes transactions after 30 seconds
Market Conditions randomized congestion and gas price levels

git clone https://github.com/Devansh-567/Bitcoin-transaction-pool-simulator.git

cd Bitcoin-transaction-pool-simulator

pip install -r requirements.txt

python app.py