Skip to content
Merged
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"crates/bitcell-economics",
"crates/bitcell-network",
"crates/bitcell-node",
"crates/bitcell-admin",
]
resolver = "2"

Expand Down
52 changes: 52 additions & 0 deletions crates/bitcell-admin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "bitcell-admin"
version = "0.1.0"
edition = "2021"
authors = ["BitCell Contributors"]
description = "Administrative console and dashboard for BitCell blockchain"

[dependencies]
# Web framework
axum = "0.7"
tower = "0.4"
tower-http = { version = "0.5", features = ["fs", "cors"] }

# Async runtime
tokio = { version = "1.0", features = ["full"] }

# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Templating
tera = "1.19"

# HTTP client (for calling node APIs)
reqwest = { version = "0.11", features = ["json"] }

# Metrics
prometheus-client = "0.22"

# Logging
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# Time
chrono = { version = "0.4", features = ["serde"] }

# Sync primitives
parking_lot = "0.12"

# BitCell dependencies
bitcell-node = { path = "../bitcell-node" }
bitcell-consensus = { path = "../bitcell-consensus" }
bitcell-state = { path = "../bitcell-state" }
bitcell-network = { path = "../bitcell-network" }
bitcell-crypto = { path = "../bitcell-crypto" }
bitcell-ca = { path = "../bitcell-ca" }

# Unix process management
[target.'cfg(unix)'.dependencies]
libc = "0.2"

[dev-dependencies]
221 changes: 221 additions & 0 deletions crates/bitcell-admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
# BitCell Admin Console

A comprehensive web-based administrative interface for managing and monitoring BitCell blockchain nodes.

## Features

### 🎛️ Node Management
- **Register and manage multiple nodes** (validators, miners, full nodes)
- **Start/stop nodes** remotely via web interface
- **Real-time status monitoring** with automatic updates
- **Node health checks** and diagnostics

### 📊 Metrics & Monitoring
- **Chain Metrics**: Block height, transactions, pending pool, block times
- **Network Metrics**: Peer connections, bandwidth usage, message throughput
- **EBSL Metrics**: Active miners, banned miners, trust scores, slashing events
- **System Metrics**: CPU usage, memory usage, disk usage, uptime

### 🚀 Deployment Management
- **Automated node deployment** with configurable parameters
- **Multi-node deployment** for testnets and production
- **Deployment status tracking** and history
- **Configuration management** with validation

### 🧪 Testing Utilities
- **Battle simulation testing** with custom glider patterns
- **Transaction testing** for stress testing and validation
- **Network connectivity testing** for peer discovery
- **Performance benchmarking** tools

### ⚙️ Configuration
- **Network configuration**: Listen addresses, bootstrap peers, max peers
- **Consensus configuration**: Battle steps, tournament rounds, block time
- **EBSL configuration**: Evidence thresholds, slash percentages, decay rates
- **Economics configuration**: Rewards, halving intervals, gas pricing

## Quick Start

### Running the Admin Console

```bash
# Start on default port (8080)
cargo run -p bitcell-admin

# Start on custom port
cargo run -p bitcell-admin -- 0.0.0.0:9999
```

### Access the Dashboard

Open your browser and navigate to:
```
http://localhost:8080
```

## API Endpoints

### Node Management
- `GET /api/nodes` - List all nodes
- `GET /api/nodes/:id` - Get node details
- `POST /api/nodes/:id/start` - Start a node
- `POST /api/nodes/:id/stop` - Stop a node

### Metrics
- `GET /api/metrics` - Get all metrics
- `GET /api/metrics/chain` - Chain-specific metrics
- `GET /api/metrics/network` - Network-specific metrics

### Deployment
- `POST /api/deployment/deploy` - Deploy new nodes
- `GET /api/deployment/status` - Get deployment status

### Configuration
- `GET /api/config` - Get current configuration
- `POST /api/config` - Update configuration

### Testing
- `POST /api/test/battle` - Run battle simulation
- `POST /api/test/transaction` - Send test transaction

## API Examples

### Deploy Validator Nodes

```bash
curl -X POST http://localhost:8080/api/deployment/deploy \
-H "Content-Type: application/json" \
-d '{
"node_type": "validator",
"count": 3,
"config": {
"network": "testnet",
"log_level": "info",
"port_start": 9000
}
}'
```

### Run Battle Test

```bash
curl -X POST http://localhost:8080/api/test/battle \
-H "Content-Type: application/json" \
-d '{
"glider_a": "Standard",
"glider_b": "Heavyweight",
"steps": 1000
}'
```

### Update Configuration

```bash
curl -X POST http://localhost:8080/api/config \
-H "Content-Type: application/json" \
-d '{
"network": {
"listen_addr": "0.0.0.0:9000",
"bootstrap_peers": ["127.0.0.1:9001"],
"max_peers": 50
},
"consensus": {
"battle_steps": 1000,
"tournament_rounds": 5,
"block_time": 6
},
"ebsl": {
"evidence_threshold": 0.7,
"slash_percentage": 0.1,
"decay_rate": 0.95
},
"economics": {
"initial_reward": 50000000,
"halving_interval": 210000,
"base_gas_price": 1000
}
}'
```

## Architecture

```
bitcell-admin/
├── src/
│ ├── lib.rs # Main library interface
│ ├── main.rs # Binary entry point
│ ├── api/ # REST API endpoints
│ │ ├── mod.rs # API types and core
│ │ ├── nodes.rs # Node management
│ │ ├── metrics.rs # Metrics endpoints
│ │ ├── deployment.rs # Deployment endpoints
│ │ ├── config.rs # Configuration endpoints
│ │ └── test.rs # Testing utilities
│ ├── web/ # Web interface
│ │ ├── mod.rs # Template engine setup
│ │ └── dashboard.rs # Dashboard HTML/JS
│ ├── deployment.rs # Deployment manager
│ ├── config.rs # Configuration manager
│ └── metrics.rs # Metrics collector
└── static/ # Static assets (CSS, JS, images)
```

## Security Considerations

⚠️ **CRITICAL SECURITY WARNING** ⚠️

**NO AUTHENTICATION IS CURRENTLY IMPLEMENTED**

The admin console currently allows **unrestricted access** to all endpoints. This is a **critical security vulnerability**.

**DO NOT expose this admin console to any network (including localhost) in production without implementing authentication first.**

For production deployments, you MUST:

1. **Implement authentication** before exposing to any network
2. **Use HTTPS/TLS** for all communication (never HTTP in production)
3. **Restrict network access** via firewall rules, VPN, or IP allowlisting
4. **Use strong passwords** and rotate them regularly
5. **Enable comprehensive audit logging** for all administrative actions
6. **Implement API rate limiting** to prevent abuse
7. **Run with least-privilege** user accounts (never as root)

## Development

### Building

```bash
cargo build -p bitcell-admin
```

### Testing

```bash
cargo test -p bitcell-admin
```

### Running in Development

```bash
# With auto-reload (requires cargo-watch)
cargo watch -x 'run -p bitcell-admin'
```

## Future Enhancements

- [ ] Authentication and authorization (JWT tokens)
- [ ] WebSocket support for real-time updates
- [ ] Advanced charting and visualization
- [ ] Log aggregation and search
- [ ] Automated health checks and alerting
- [ ] Backup and restore functionality
- [ ] Multi-chain support
- [ ] Mobile-responsive UI improvements

## License

Same as BitCell project

## Contributing

Contributions welcome! Please follow the BitCell contribution guidelines.
74 changes: 74 additions & 0 deletions crates/bitcell-admin/src/api/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! Configuration API endpoints

use axum::{
extract::State,
http::StatusCode,
Json,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;

use crate::AppState;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Config {
pub network: NetworkConfig,
pub consensus: ConsensusConfig,
pub ebsl: EbslConfig,
pub economics: EconomicsConfig,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct NetworkConfig {
pub listen_addr: String,
pub bootstrap_peers: Vec<String>,
pub max_peers: usize,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ConsensusConfig {
pub battle_steps: usize,
pub tournament_rounds: usize,
pub block_time: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct EbslConfig {
pub evidence_threshold: f64,
pub slash_percentage: f64,
pub decay_rate: f64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct EconomicsConfig {
pub initial_reward: u64,
pub halving_interval: u64,
pub base_gas_price: u64,
}

/// Get current configuration
pub async fn get_config(
State(state): State<Arc<AppState>>,
) -> Result<Json<Config>, (StatusCode, Json<String>)> {
match state.config.get_config() {
Ok(config) => Ok(Json(config)),
Err(e) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
Json(format!("Failed to get config: {}", e)),
)),
}
}

/// Update configuration
pub async fn update_config(
State(state): State<Arc<AppState>>,
Json(config): Json<Config>,
) -> Result<Json<Config>, (StatusCode, Json<String>)> {
match state.config.update_config(config.clone()) {
Ok(_) => Ok(Json(config)),
Err(e) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
Json(format!("Failed to update config: {}", e)),
)),
}
}
Loading