Skip to content

Commit d57efd9

Browse files
authored
Merge pull request #3 from Steake/claude/add-admin-console-01GKYw8UuUjuFBWeMXUqJHgU
Admin console
2 parents 1aa5657 + 1654b42 commit d57efd9

23 files changed

Lines changed: 3655 additions & 11 deletions

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"crates/bitcell-economics",
1111
"crates/bitcell-network",
1212
"crates/bitcell-node",
13+
"crates/bitcell-admin",
1314
]
1415
resolver = "2"
1516

crates/bitcell-admin/Cargo.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[package]
2+
name = "bitcell-admin"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["BitCell Contributors"]
6+
description = "Administrative console and dashboard for BitCell blockchain"
7+
8+
[dependencies]
9+
# Web framework
10+
axum = "0.7"
11+
tower = "0.4"
12+
tower-http = { version = "0.5", features = ["fs", "cors"] }
13+
14+
# Async runtime
15+
tokio = { version = "1.0", features = ["full"] }
16+
17+
# Serialization
18+
serde = { version = "1.0", features = ["derive"] }
19+
serde_json = "1.0"
20+
21+
# Templating
22+
tera = "1.19"
23+
24+
# HTTP client (for calling node APIs)
25+
reqwest = { version = "0.11", features = ["json"] }
26+
27+
# Metrics
28+
prometheus-client = "0.22"
29+
30+
# Logging
31+
tracing = "0.1"
32+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
33+
34+
# Time
35+
chrono = { version = "0.4", features = ["serde"] }
36+
37+
# Sync primitives
38+
parking_lot = "0.12"
39+
40+
# BitCell dependencies
41+
bitcell-node = { path = "../bitcell-node" }
42+
bitcell-consensus = { path = "../bitcell-consensus" }
43+
bitcell-state = { path = "../bitcell-state" }
44+
bitcell-network = { path = "../bitcell-network" }
45+
bitcell-crypto = { path = "../bitcell-crypto" }
46+
bitcell-ca = { path = "../bitcell-ca" }
47+
48+
# Unix process management
49+
[target.'cfg(unix)'.dependencies]
50+
libc = "0.2"
51+
52+
[dev-dependencies]

crates/bitcell-admin/README.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# BitCell Admin Console
2+
3+
A comprehensive web-based administrative interface for managing and monitoring BitCell blockchain nodes.
4+
5+
## Features
6+
7+
### 🎛️ Node Management
8+
- **Register and manage multiple nodes** (validators, miners, full nodes)
9+
- **Start/stop nodes** remotely via web interface
10+
- **Real-time status monitoring** with automatic updates
11+
- **Node health checks** and diagnostics
12+
13+
### 📊 Metrics & Monitoring
14+
- **Chain Metrics**: Block height, transactions, pending pool, block times
15+
- **Network Metrics**: Peer connections, bandwidth usage, message throughput
16+
- **EBSL Metrics**: Active miners, banned miners, trust scores, slashing events
17+
- **System Metrics**: CPU usage, memory usage, disk usage, uptime
18+
19+
### 🚀 Deployment Management
20+
- **Automated node deployment** with configurable parameters
21+
- **Multi-node deployment** for testnets and production
22+
- **Deployment status tracking** and history
23+
- **Configuration management** with validation
24+
25+
### 🧪 Testing Utilities
26+
- **Battle simulation testing** with custom glider patterns
27+
- **Transaction testing** for stress testing and validation
28+
- **Network connectivity testing** for peer discovery
29+
- **Performance benchmarking** tools
30+
31+
### ⚙️ Configuration
32+
- **Network configuration**: Listen addresses, bootstrap peers, max peers
33+
- **Consensus configuration**: Battle steps, tournament rounds, block time
34+
- **EBSL configuration**: Evidence thresholds, slash percentages, decay rates
35+
- **Economics configuration**: Rewards, halving intervals, gas pricing
36+
37+
## Quick Start
38+
39+
### Running the Admin Console
40+
41+
```bash
42+
# Start on default port (8080)
43+
cargo run -p bitcell-admin
44+
45+
# Start on custom port
46+
cargo run -p bitcell-admin -- 0.0.0.0:9999
47+
```
48+
49+
### Access the Dashboard
50+
51+
Open your browser and navigate to:
52+
```
53+
http://localhost:8080
54+
```
55+
56+
## API Endpoints
57+
58+
### Node Management
59+
- `GET /api/nodes` - List all nodes
60+
- `GET /api/nodes/:id` - Get node details
61+
- `POST /api/nodes/:id/start` - Start a node
62+
- `POST /api/nodes/:id/stop` - Stop a node
63+
64+
### Metrics
65+
- `GET /api/metrics` - Get all metrics
66+
- `GET /api/metrics/chain` - Chain-specific metrics
67+
- `GET /api/metrics/network` - Network-specific metrics
68+
69+
### Deployment
70+
- `POST /api/deployment/deploy` - Deploy new nodes
71+
- `GET /api/deployment/status` - Get deployment status
72+
73+
### Configuration
74+
- `GET /api/config` - Get current configuration
75+
- `POST /api/config` - Update configuration
76+
77+
### Testing
78+
- `POST /api/test/battle` - Run battle simulation
79+
- `POST /api/test/transaction` - Send test transaction
80+
81+
## API Examples
82+
83+
### Deploy Validator Nodes
84+
85+
```bash
86+
curl -X POST http://localhost:8080/api/deployment/deploy \
87+
-H "Content-Type: application/json" \
88+
-d '{
89+
"node_type": "validator",
90+
"count": 3,
91+
"config": {
92+
"network": "testnet",
93+
"log_level": "info",
94+
"port_start": 9000
95+
}
96+
}'
97+
```
98+
99+
### Run Battle Test
100+
101+
```bash
102+
curl -X POST http://localhost:8080/api/test/battle \
103+
-H "Content-Type: application/json" \
104+
-d '{
105+
"glider_a": "Standard",
106+
"glider_b": "Heavyweight",
107+
"steps": 1000
108+
}'
109+
```
110+
111+
### Update Configuration
112+
113+
```bash
114+
curl -X POST http://localhost:8080/api/config \
115+
-H "Content-Type: application/json" \
116+
-d '{
117+
"network": {
118+
"listen_addr": "0.0.0.0:9000",
119+
"bootstrap_peers": ["127.0.0.1:9001"],
120+
"max_peers": 50
121+
},
122+
"consensus": {
123+
"battle_steps": 1000,
124+
"tournament_rounds": 5,
125+
"block_time": 6
126+
},
127+
"ebsl": {
128+
"evidence_threshold": 0.7,
129+
"slash_percentage": 0.1,
130+
"decay_rate": 0.95
131+
},
132+
"economics": {
133+
"initial_reward": 50000000,
134+
"halving_interval": 210000,
135+
"base_gas_price": 1000
136+
}
137+
}'
138+
```
139+
140+
## Architecture
141+
142+
```
143+
bitcell-admin/
144+
├── src/
145+
│ ├── lib.rs # Main library interface
146+
│ ├── main.rs # Binary entry point
147+
│ ├── api/ # REST API endpoints
148+
│ │ ├── mod.rs # API types and core
149+
│ │ ├── nodes.rs # Node management
150+
│ │ ├── metrics.rs # Metrics endpoints
151+
│ │ ├── deployment.rs # Deployment endpoints
152+
│ │ ├── config.rs # Configuration endpoints
153+
│ │ └── test.rs # Testing utilities
154+
│ ├── web/ # Web interface
155+
│ │ ├── mod.rs # Template engine setup
156+
│ │ └── dashboard.rs # Dashboard HTML/JS
157+
│ ├── deployment.rs # Deployment manager
158+
│ ├── config.rs # Configuration manager
159+
│ └── metrics.rs # Metrics collector
160+
└── static/ # Static assets (CSS, JS, images)
161+
```
162+
163+
## Security Considerations
164+
165+
⚠️ **CRITICAL SECURITY WARNING** ⚠️
166+
167+
**NO AUTHENTICATION IS CURRENTLY IMPLEMENTED**
168+
169+
The admin console currently allows **unrestricted access** to all endpoints. This is a **critical security vulnerability**.
170+
171+
**DO NOT expose this admin console to any network (including localhost) in production without implementing authentication first.**
172+
173+
For production deployments, you MUST:
174+
175+
1. **Implement authentication** before exposing to any network
176+
2. **Use HTTPS/TLS** for all communication (never HTTP in production)
177+
3. **Restrict network access** via firewall rules, VPN, or IP allowlisting
178+
4. **Use strong passwords** and rotate them regularly
179+
5. **Enable comprehensive audit logging** for all administrative actions
180+
6. **Implement API rate limiting** to prevent abuse
181+
7. **Run with least-privilege** user accounts (never as root)
182+
183+
## Development
184+
185+
### Building
186+
187+
```bash
188+
cargo build -p bitcell-admin
189+
```
190+
191+
### Testing
192+
193+
```bash
194+
cargo test -p bitcell-admin
195+
```
196+
197+
### Running in Development
198+
199+
```bash
200+
# With auto-reload (requires cargo-watch)
201+
cargo watch -x 'run -p bitcell-admin'
202+
```
203+
204+
## Future Enhancements
205+
206+
- [ ] Authentication and authorization (JWT tokens)
207+
- [ ] WebSocket support for real-time updates
208+
- [ ] Advanced charting and visualization
209+
- [ ] Log aggregation and search
210+
- [ ] Automated health checks and alerting
211+
- [ ] Backup and restore functionality
212+
- [ ] Multi-chain support
213+
- [ ] Mobile-responsive UI improvements
214+
215+
## License
216+
217+
Same as BitCell project
218+
219+
## Contributing
220+
221+
Contributions welcome! Please follow the BitCell contribution guidelines.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//! Configuration API endpoints
2+
3+
use axum::{
4+
extract::State,
5+
http::StatusCode,
6+
Json,
7+
};
8+
use serde::{Deserialize, Serialize};
9+
use std::sync::Arc;
10+
11+
use crate::AppState;
12+
13+
#[derive(Debug, Serialize, Deserialize, Clone)]
14+
pub struct Config {
15+
pub network: NetworkConfig,
16+
pub consensus: ConsensusConfig,
17+
pub ebsl: EbslConfig,
18+
pub economics: EconomicsConfig,
19+
}
20+
21+
#[derive(Debug, Serialize, Deserialize, Clone)]
22+
pub struct NetworkConfig {
23+
pub listen_addr: String,
24+
pub bootstrap_peers: Vec<String>,
25+
pub max_peers: usize,
26+
}
27+
28+
#[derive(Debug, Serialize, Deserialize, Clone)]
29+
pub struct ConsensusConfig {
30+
pub battle_steps: usize,
31+
pub tournament_rounds: usize,
32+
pub block_time: u64,
33+
}
34+
35+
#[derive(Debug, Serialize, Deserialize, Clone)]
36+
pub struct EbslConfig {
37+
pub evidence_threshold: f64,
38+
pub slash_percentage: f64,
39+
pub decay_rate: f64,
40+
}
41+
42+
#[derive(Debug, Serialize, Deserialize, Clone)]
43+
pub struct EconomicsConfig {
44+
pub initial_reward: u64,
45+
pub halving_interval: u64,
46+
pub base_gas_price: u64,
47+
}
48+
49+
/// Get current configuration
50+
pub async fn get_config(
51+
State(state): State<Arc<AppState>>,
52+
) -> Result<Json<Config>, (StatusCode, Json<String>)> {
53+
match state.config.get_config() {
54+
Ok(config) => Ok(Json(config)),
55+
Err(e) => Err((
56+
StatusCode::INTERNAL_SERVER_ERROR,
57+
Json(format!("Failed to get config: {}", e)),
58+
)),
59+
}
60+
}
61+
62+
/// Update configuration
63+
pub async fn update_config(
64+
State(state): State<Arc<AppState>>,
65+
Json(config): Json<Config>,
66+
) -> Result<Json<Config>, (StatusCode, Json<String>)> {
67+
match state.config.update_config(config.clone()) {
68+
Ok(_) => Ok(Json(config)),
69+
Err(e) => Err((
70+
StatusCode::INTERNAL_SERVER_ERROR,
71+
Json(format!("Failed to update config: {}", e)),
72+
)),
73+
}
74+
}

0 commit comments

Comments
 (0)