Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ data/
node_output.log
server_output*.log
qbtc.log
/validator-rocks-db/
/liboqs/

# Docker
docker-compose.override.yml
Expand Down
19 changes: 18 additions & 1 deletion DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This creates a `wallet.json` file with your ML-DSA keypair. Keep it safe!
### Scenario 1: Local Test Network (3 Nodes)

Perfect for development and testing. Creates a complete network with:

- 1 Bootstrap node
- 2 Validator nodes
- Full monitoring stack (Prometheus + Grafana)
Expand Down Expand Up @@ -138,12 +139,14 @@ docker compose -f docker-compose.validator.yml logs -f validator
### Environment Variables

#### Common Variables

- `WALLET_PASSWORD` - Password for the wallet file (required)
- `WALLET_FILE` - Wallet filename (default: varies by node type)
- `ADMIN_ADDRESS` - Admin address for security features
- `USE_REDIS` - Enable Redis caching (default: true)

#### Security Configuration

- `RATE_LIMIT_ENABLED` - Enable rate limiting (default: false)
- `DDOS_PROTECTION_ENABLED` - Enable DDoS protection (default: true for production)
- `ATTACK_PATTERN_DETECTION` - Detect attack patterns (default: true for production)
Expand All @@ -152,6 +155,7 @@ docker compose -f docker-compose.validator.yml logs -f validator
- `SECURITY_LOGGING_ENABLED` - Enable security logging (default: true)

#### Monitoring Configuration

- `GRAFANA_ADMIN_USER` - Grafana admin username (default: admin)
- `GRAFANA_ADMIN_PASSWORD` - Grafana admin password (required for production)
- `GRAFANA_DOMAIN` - Domain for Grafana (required for production)
Expand Down Expand Up @@ -180,6 +184,7 @@ python3 main.py --external-ip YOUR_PUBLIC_IP
### Grafana Dashboards

All deployments include pre-configured Grafana dashboards:

- **Network Overview** - Peer connections, blockchain height, sync status
- **Performance Metrics** - CPU, memory, disk usage
- **Transaction Flow** - Mempool size, transaction throughput
Expand All @@ -188,6 +193,7 @@ All deployments include pre-configured Grafana dashboards:
### Prometheus Metrics

Key metrics exposed:

- `qbtc_connected_peers_total` - Number of connected peers
- `qbtc_blockchain_height` - Current blockchain height
- `qbtc_pending_transactions` - Mempool size
Expand Down Expand Up @@ -245,16 +251,19 @@ docker compose -f docker-compose.SCENARIO.yml logs -f SERVICE_NAME
### Connection Issues

1. Check if bootstrap is reachable:

```bash
curl http://api.bitcoinqs.org:8080/health
```

2. Verify ports are open:

```bash
netstat -tuln | grep -E "8001|8002|8080|8332"
```

3. Check Docker network:

```bash
docker network ls
docker network inspect qbtc-core_qbtc-network
Expand All @@ -263,34 +272,40 @@ docker network inspect qbtc-core_qbtc-network
### Wallet Issues

1. Verify wallet file exists:

```bash
ls -la wallet.json
```

2. Check wallet password in environment:

```bash
docker compose -f docker-compose.SCENARIO.yml config | grep WALLET
```

### Performance Issues

1. Check resource usage:

```bash
docker stats
```

2. View metrics in Grafana:

- http://localhost:3000 (test network)
- https://your-domain.com/grafana/ (production)

## Security Best Practices

1. **Wallet Security**

- Use strong passwords
- Backup wallet files securely
- Never commit wallets to git

2. **Network Security**

- Use firewalls to limit port access
- Enable SSL for production
- Regularly update Docker images
Expand All @@ -305,6 +320,7 @@ docker stats
### Custom Network Configuration

Create a `.env` file:

```bash
# Network settings
BOOTSTRAP_SERVER=api.bitcoinqs.org
Expand All @@ -324,6 +340,7 @@ MEMORY_LIMIT=2G
### Multi-Region Deployment

For geo-distributed networks:

1. Deploy bootstrap servers in multiple regions
2. Use external IPs for NAT traversal
3. Configure monitoring aggregation
Expand All @@ -332,4 +349,4 @@ For geo-distributed networks:

- GitHub Issues: https://github.com/q-btc/qBTC-core/issues
- Documentation: https://qb.tc/docs
- Community: Discord/Telegram links
- Community: Discord/Telegram links
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ COPY . .
# ────────────────────────────────────────────────────────────────────────────────
ENV WALLET_PASSWORD=your_wallet_password
ENV ROCKSDB_PATH=/app/db
ENV RPC_PORT=8332
ENV GRAFANA=true
ENV GRAFANA_PORT=443

EXPOSE 8080/tcp 8332/tcp 8001/udp 8002/tcp

Expand All @@ -74,4 +77,4 @@ EXPOSE 8080/tcp 8332/tcp 8001/udp 8002/tcp
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

ENTRYPOINT ["/app/docker-entrypoint.sh"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

Built from the ground up in Python to demonstrate a proof-of-concept, qBTC introduces key innovations for the future of Bitcoin:

- **Post-Quantum Security** using the ML-DSA signature scheme
- **Decentralized validator discovery** via a Kademlia DHT
- **Fast, scalable propagation** through an asynchronous gossip network
- **Post-Quantum Security** using the ML-DSA signature scheme
- **Decentralized validator discovery** via a Kademlia DHT
- **Fast, scalable propagation** through an asynchronous gossip network

The cryptographic layer is modular, allowing ML-DSA to be replaced with other post-quantum algorithms as standards evolve.

Expand Down Expand Up @@ -109,6 +109,7 @@ usage: main.py [-h] [--bootstrap] [--bootstrap_server BOOTSTRAP_SERVER]
```

Optional arguments:

- `--bootstrap`: Run as bootstrap server
- `--bootstrap_server`: Bootstrap server host (default: api.bitcoinqs.org)
- `--bootstrap_port`: Bootstrap server port (default: 8001)
Expand Down Expand Up @@ -259,6 +260,7 @@ docker compose -f docker-compose.validator.yml logs -f validator
### Key Docker Features

All configurations include:

- **Automatic wallet generation** with secure passwords
- **Redis** for caching and rate limiting
- **Prometheus** metrics collection
Expand All @@ -270,6 +272,7 @@ All configurations include:
- **Security hardening** (no-new-privileges, read-only filesystems where possible)

Production configurations additionally include:

- **SSL/TLS encryption** via nginx
- **DDoS protection** and attack detection
- **Rate limiting** on API endpoints
Expand All @@ -285,6 +288,7 @@ You can simulate multiple validators by launching separate containers or Python
### Docker Multi-Node Network

The test network (`docker-compose.test.yml`) creates:

- 1 Bootstrap node (internal port 8080, accessed via nginx on 8080)
- 2 Validator nodes (ports 8081, 8082)
- Prometheus monitoring (port 9090)
Expand All @@ -298,21 +302,21 @@ All nodes automatically discover each other and maintain peer connections.

## 📜 Core Components

| Component | Description |
|---------------------|--------------------------------------------------|
| `main.py` | Entry point - starts web/RPC servers |
| `blockchain/` | Block, transaction, UTXO, Merkle logic |
| `chain_manager.py` | Manages blockchain state and fork resolution |
| `dht/` | Kademlia-based peer discovery |
| `gossip/` | Gossip protocol for block/tx propagation |
| `web/` | FastAPI web server with API endpoints |
| `rpc/` | Bitcoin-compatible RPC for mining |
| `wallet/` | Post-quantum key management (ML-DSA) |
| `database/` | RocksDB storage layer |
| `monitoring/` | Health checks and Prometheus metrics |
| `events/` | Event bus for internal communication |
| `security/` | Rate limiting and DDoS protection |
| `mempool/` | Transaction pool with conflict detection |
| Component | Description |
| ------------------ | -------------------------------------------- |
| `main.py` | Entry point - starts web/RPC servers |
| `blockchain/` | Block, transaction, UTXO, Merkle logic |
| `chain_manager.py` | Manages blockchain state and fork resolution |
| `dht/` | Kademlia-based peer discovery |
| `gossip/` | Gossip protocol for block/tx propagation |
| `web/` | FastAPI web server with API endpoints |
| `rpc/` | Bitcoin-compatible RPC for mining |
| `wallet/` | Post-quantum key management (ML-DSA) |
| `database/` | RocksDB storage layer |
| `monitoring/` | Health checks and Prometheus metrics |
| `events/` | Event bus for internal communication |
| `security/` | Rate limiting and DDoS protection |
| `mempool/` | Transaction pool with conflict detection |

---

Expand All @@ -331,6 +335,7 @@ python3 broadcast_tx_test_harness.py \
```

This sends 500 qBTC to the specified address using your signed wallet. The transaction includes:

- **Chain ID** for replay protection
- **Timestamp** for transaction expiration
- **ML-DSA signature** for post-quantum security
Expand All @@ -348,6 +353,7 @@ docker run --rm -it cpuminer-opt \
```

The RPC server automatically:

- Includes pending transactions from the mempool
- Creates proper coinbase transactions with fees
- Broadcasts mined blocks to all peers via gossip
Expand All @@ -368,6 +374,7 @@ The RPC server automatically:
### Prometheus Metrics (http://localhost:9090)

Key metrics include:

- `qbtc_connected_peers_total` - Number of connected peers
- `qbtc_blockchain_height` - Current blockchain height
- `qbtc_pending_transactions` - Mempool size
Expand All @@ -377,6 +384,7 @@ Key metrics include:
### Grafana Dashboards (http://localhost:3000)

Pre-configured dashboards show:

- Network topology and peer connections
- Blockchain growth and sync status
- Transaction throughput
Expand Down Expand Up @@ -405,6 +413,7 @@ Internal and external audits can be found in the `audits/` folder. We are active
### Peer Discovery

Nodes use Kademlia DHT for decentralized peer discovery:

1. Bootstrap nodes maintain the DHT network
2. New nodes query the DHT for active validators
3. Validators announce their presence with gossip endpoints
Expand All @@ -413,6 +422,7 @@ Nodes use Kademlia DHT for decentralized peer discovery:
### Block & Transaction Propagation

The gossip protocol ensures fast network-wide propagation:

1. Transactions are broadcast to all connected peers
2. Blocks are propagated immediately upon mining
3. Nodes sync missing blocks automatically
Expand All @@ -430,6 +440,7 @@ The gossip protocol ensures fast network-wide propagation:
## 📈 Roadmap

### Completed ✅

- Merkle Root validation
- Gossip protocol implementation
- Kademlia DHT integration
Expand All @@ -444,12 +455,14 @@ The gossip protocol ensures fast network-wide propagation:
- Event-driven architecture

### In Progress 🚧

- TLS encryption for all connections
- Peer authentication with ML-DSA
- Advanced fork choice rules
- State pruning optimizations

### Planned 📋

- Fee market implementation
- Smart contract support
- Light client protocol
Expand All @@ -468,11 +481,11 @@ MIT License. See [LICENSE](./LICENSE) for more information.

PRs and issues welcome! To contribute:

1. Fork the repo
2. Create your feature branch (`git checkout -b feature/foo`)
3. Commit your changes
4. Push to the branch
5. Open a PR
1. Fork the repo
2. Create your feature branch (`git checkout -b feature/foo`)
3. Commit your changes
4. Push to the branch
5. Open a PR

### Development Tips

Expand Down
Loading