```
chore: remove obsolete files and add Solidity build artifacts to .gitignore - Add ignore patterns for Solidity build artifacts (typechain-types, artifacts, cache) - Remove unused exchange mock API server (api/exchange_mock_api.py) - Remove obsolete client-web README placeholder - Remove deprecated marketplace-ui HTML implementation ```
This commit is contained in:
73
docs/operator/deployment/README-CONTAINER-DEPLOYMENT.md
Normal file
73
docs/operator/deployment/README-CONTAINER-DEPLOYMENT.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# AITBC Container Deployment Guide
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Your user needs to be in the `incus` group to manage containers.
|
||||
|
||||
## Setup Steps
|
||||
|
||||
1. **Add your user to the incus group:**
|
||||
```bash
|
||||
sudo usermod -aG incus $USER
|
||||
```
|
||||
|
||||
2. **Log out and log back in** for the group changes to take effect.
|
||||
|
||||
3. **Verify access:**
|
||||
```bash
|
||||
incus list
|
||||
```
|
||||
|
||||
## Deploy AITBC Services
|
||||
|
||||
Once you have incus access, run the deployment script:
|
||||
|
||||
```bash
|
||||
python /home/oib/windsurf/aitbc/container-deploy.py
|
||||
```
|
||||
|
||||
## Service URLs (after deployment)
|
||||
|
||||
- **Marketplace UI**: http://10.1.223.93:3001
|
||||
- **Trade Exchange**: http://10.1.223.93:3002
|
||||
- **Coordinator API**: http://10.1.223.93:8000
|
||||
- **Blockchain RPC**: http://10.1.223.93:9080
|
||||
|
||||
## Managing Services
|
||||
|
||||
### Check running services in container:
|
||||
```bash
|
||||
incus exec aitbc -- ps aux | grep python
|
||||
```
|
||||
|
||||
### View logs:
|
||||
```bash
|
||||
incus exec aitbc -- journalctl -u aitbc-coordinator -f
|
||||
```
|
||||
|
||||
### Restart services:
|
||||
```bash
|
||||
incus exec aitbc -- pkill -f uvicorn
|
||||
incus exec aitbc -- /home/oib/start_aitbc.sh
|
||||
```
|
||||
|
||||
### Stop all services:
|
||||
```bash
|
||||
incus exec aitbc -- pkill -f "uvicorn\|server.py"
|
||||
```
|
||||
|
||||
## Configuration Files
|
||||
|
||||
Services are started from `/home/oib/aitbc/start_aitbc.sh` inside the container.
|
||||
|
||||
## Firewall
|
||||
|
||||
Make sure the following ports are open on the container host:
|
||||
- 3001 (Marketplace UI)
|
||||
- 3002 (Trade Exchange)
|
||||
- 8000 (Coordinator API)
|
||||
- 9080 (Blockchain RPC)
|
||||
|
||||
## Public Access
|
||||
|
||||
To make services publicly accessible, configure your router or firewall to forward these ports to the container IP (10.1.223.93).
|
||||
142
docs/operator/deployment/README-DOMAIN-DEPLOYMENT.md
Normal file
142
docs/operator/deployment/README-DOMAIN-DEPLOYMENT.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# AITBC Domain Deployment Guide
|
||||
|
||||
## Overview
|
||||
|
||||
Deploy AITBC services to your existing domain: **https://aitbc.bubuit.net**
|
||||
|
||||
## Service URLs
|
||||
|
||||
- **Marketplace**: https://aitbc.bubuit.net/Marketplace
|
||||
- **Trade Exchange**: https://aitbc.bubuit.net/Exchange
|
||||
- **API**: https://aitbc.bubuit.net/api
|
||||
- **Blockchain RPC**: https://aitbc.bubuit.net/rpc
|
||||
- **Admin**: https://aitbc.bubuit.net/admin
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Incus access (add user to incus group):
|
||||
```bash
|
||||
sudo usermod -aG incus $USER
|
||||
# Log out and back in
|
||||
```
|
||||
|
||||
2. Domain pointing to your server
|
||||
|
||||
## Deployment Steps
|
||||
|
||||
### 1. Deploy Services
|
||||
```bash
|
||||
./deploy-domain.sh
|
||||
```
|
||||
|
||||
### 2. Configure Port Forwarding
|
||||
Forward these ports to the container IP (10.1.223.93):
|
||||
- Port 80 → 10.1.223.93:80
|
||||
- Port 443 → 10.1.223.93:443
|
||||
|
||||
### 3. Install SSL Certificate
|
||||
```bash
|
||||
incus exec aitbc -- certbot --nginx -d aitbc.bubuit.net
|
||||
```
|
||||
|
||||
### 4. Verify Services
|
||||
Visit the URLs to ensure everything is working.
|
||||
|
||||
## Nginx Configuration
|
||||
|
||||
The nginx configuration handles:
|
||||
- HTTPS redirection
|
||||
- SSL termination
|
||||
- Path-based routing
|
||||
- API proxying
|
||||
- Security headers
|
||||
|
||||
Configuration file: `/home/oib/windsurf/aitbc/nginx-aitbc.conf`
|
||||
|
||||
## Service Management
|
||||
|
||||
### Check running services:
|
||||
```bash
|
||||
incus exec aitbc -- ps aux | grep python
|
||||
```
|
||||
|
||||
### View logs:
|
||||
```bash
|
||||
incus exec aitbc -- journalctl -u aitbc-coordinator -f
|
||||
```
|
||||
|
||||
### Restart services:
|
||||
```bash
|
||||
incus exec aitbc -- pkill -f uvicorn
|
||||
incus exec aitbc -- /home/oib/start_aitbc.sh
|
||||
```
|
||||
|
||||
### Update nginx config:
|
||||
```bash
|
||||
incus file push nginx-aitbc.conf aitbc/etc/nginx/sites-available/aitbc
|
||||
incus exec aitbc -- nginx -t && incus exec aitbc -- systemctl reload nginx
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Coordinator API
|
||||
- GET `/api/marketplace/offers` - List GPU offers
|
||||
- POST `/api/miners/register` - Register miner
|
||||
- POST `/api/marketplace/bids` - Create bid
|
||||
- GET `/api/marketplace/stats` - Marketplace stats
|
||||
|
||||
### Blockchain RPC
|
||||
- GET `/rpc/head` - Get latest block
|
||||
- GET `/rpc/getBalance/{address}` - Get balance
|
||||
- POST `/rpc/admin/mintFaucet` - Mint tokens
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **Firewall**: Only open necessary ports (80, 443)
|
||||
2. **SSL**: Always use HTTPS
|
||||
3. **API Keys**: Use environment variables for sensitive keys
|
||||
4. **Rate Limiting**: Configure nginx rate limiting if needed
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Health checks:
|
||||
- https://aitbc.bubuit.net/health
|
||||
|
||||
### Metrics:
|
||||
- https://aitbc.bubuit.net/metrics (if configured)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Services not accessible:
|
||||
1. Check port forwarding
|
||||
2. Verify nginx configuration
|
||||
3. Check container services
|
||||
|
||||
### SSL issues:
|
||||
1. Renew certificate: `incus exec aitbc -- certbot renew`
|
||||
2. Check nginx SSL config
|
||||
|
||||
### API errors:
|
||||
1. Check service logs
|
||||
2. Verify API endpoints
|
||||
3. Check CORS settings
|
||||
|
||||
## Customization
|
||||
|
||||
### Add new service:
|
||||
1. Update nginx-aitbc.conf
|
||||
2. Add service to start_aitbc.sh
|
||||
3. Restart services
|
||||
|
||||
### Update UI:
|
||||
1. Modify HTML files in apps/
|
||||
2. Update base href if needed
|
||||
3. Restart web servers
|
||||
|
||||
## Production Tips
|
||||
|
||||
1. Set up monitoring alerts
|
||||
2. Configure backups
|
||||
3. Use environment variables for config
|
||||
4. Set up log rotation
|
||||
5. Monitor resource usage
|
||||
143
docs/operator/deployment/nginx-domain-setup.md
Normal file
143
docs/operator/deployment/nginx-domain-setup.md
Normal file
@@ -0,0 +1,143 @@
|
||||
# Nginx Domain Setup for AITBC
|
||||
|
||||
## Problem
|
||||
The admin endpoint at `https://aitbc.bubuit.net/admin` returns 404 because nginx isn't properly routing to the backend services.
|
||||
|
||||
## Solution
|
||||
|
||||
### 1. Make sure services are running in the container
|
||||
|
||||
```bash
|
||||
# Access the container
|
||||
incus exec aitbc -- bash
|
||||
|
||||
# Inside container, start services
|
||||
cd /home/oib/aitbc
|
||||
./start_aitbc.sh
|
||||
|
||||
# Check if running
|
||||
ps aux | grep uvicorn
|
||||
```
|
||||
|
||||
### 2. Update nginx configuration in container
|
||||
|
||||
The nginx config needs to be inside the container at `/etc/nginx/sites-available/aitbc`:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name aitbc.bubuit.net;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name aitbc.bubuit.net;
|
||||
|
||||
# SSL certs (already configured)
|
||||
ssl_certificate /etc/letsencrypt/live/aitbc.bubuit.net/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/aitbc.bubuit.net/privkey.pem;
|
||||
|
||||
# API routes - MUST include /v1
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8000/v1/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Admin routes
|
||||
location /admin/ {
|
||||
proxy_pass http://127.0.0.1:8000/admin/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Blockchain RPC
|
||||
location /rpc/ {
|
||||
proxy_pass http://127.0.0.1:9080/rpc/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Marketplace UI
|
||||
location /Marketplace {
|
||||
proxy_pass http://127.0.0.1:3001/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Trade Exchange
|
||||
location /Exchange {
|
||||
proxy_pass http://127.0.0.1:3002/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Health endpoint
|
||||
location /health {
|
||||
proxy_pass http://127.0.0.1:8000/v1/health;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
# Default redirect
|
||||
location / {
|
||||
return 301 /Marketplace;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Apply the configuration
|
||||
|
||||
```bash
|
||||
# Copy config to container
|
||||
incus file push nginx-aitbc.conf aitbc/etc/nginx/sites-available/aitbc
|
||||
|
||||
# Enable site
|
||||
incus exec aitbc -- ln -sf /etc/nginx/sites-available/aitbc /etc/nginx/sites-enabled/
|
||||
|
||||
# Test config
|
||||
incus exec aitbc -- nginx -t
|
||||
|
||||
# Reload nginx
|
||||
incus exec aitbc -- systemctl reload nginx
|
||||
```
|
||||
|
||||
### 4. Verify services are running
|
||||
|
||||
```bash
|
||||
# Check each service
|
||||
curl -k https://aitbc.bubuit.net/api/health
|
||||
curl -k https://aitbc.bubuit.net/admin/stats -H "X-Api-Key: REDACTED_ADMIN_KEY"
|
||||
curl -k https://aitbc.bubuit.net/rpc/head
|
||||
```
|
||||
|
||||
## Quick Fix
|
||||
|
||||
If you need immediate access, you can access the API directly:
|
||||
|
||||
- **API**: https://aitbc.bubuit.net/api/health
|
||||
- **Admin**: https://aitbc.bubuit.net/admin/stats (with API key)
|
||||
- **Marketplace**: https://aitbc.bubuit.net/Marketplace
|
||||
- **Exchange**: https://aitbc.bubuit.net/Exchange
|
||||
|
||||
The issue is likely that:
|
||||
1. Services aren't running in the container
|
||||
2. Nginx config isn't properly routing /admin to the backend
|
||||
3. Port forwarding isn't configured correctly
|
||||
|
||||
## Debug Steps
|
||||
|
||||
1. Check container services: `incus exec aitbc -- ps aux | grep uvicorn`
|
||||
2. Check nginx logs: `incus exec aitbc -- journalctl -u nginx -f`
|
||||
3. Check nginx config: `incus exec aitbc -- nginx -T`
|
||||
4. Test backend directly: `incus exec aitbc -- curl http://127.0.0.1:8000/v1/health`
|
||||
120
docs/operator/deployment/simple-domain-solution.md
Normal file
120
docs/operator/deployment/simple-domain-solution.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# Simple Domain Solution for AITBC
|
||||
|
||||
## Problem
|
||||
- Incus container exists but you don't have access
|
||||
- Services need to run locally
|
||||
- Domain https://aitbc.bubuit.net needs to access local services
|
||||
|
||||
## Solution Options
|
||||
|
||||
### Option 1: SSH Tunnel (Recommended)
|
||||
|
||||
Create SSH tunnels from your server to your local machine:
|
||||
|
||||
```bash
|
||||
# On your server (aitbc.bubuit.net):
|
||||
ssh -R 8000:localhost:8000 -R 9080:localhost:9080 -R 3001:localhost:3001 -R 3002:localhost:3002 user@your-local-ip
|
||||
|
||||
# Then update nginx on server to proxy to localhost ports
|
||||
```
|
||||
|
||||
### Option 2: Run Services Directly on Server
|
||||
|
||||
Copy the AITBC project to your server and run there:
|
||||
|
||||
```bash
|
||||
# On server:
|
||||
git clone https://gitea.bubuit.net/oib/aitbc.git
|
||||
cd aitbc
|
||||
./run-local-services.sh
|
||||
```
|
||||
|
||||
### Option 3: Use Local Nginx
|
||||
|
||||
Run nginx locally and edit your hosts file:
|
||||
|
||||
```bash
|
||||
# 1. Install nginx locally if not installed
|
||||
sudo apt install nginx
|
||||
|
||||
# 2. Copy config
|
||||
sudo cp nginx-local.conf /etc/nginx/sites-available/aitbc
|
||||
sudo ln -s /etc/nginx/sites-available/aitbc /etc/nginx/sites-enabled/
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
|
||||
# 3. Test and reload
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
# 4. Edit hosts file
|
||||
echo "127.0.0.1 aitbc.bubuit.net" | sudo tee -a /etc/hosts
|
||||
|
||||
# 5. Access at http://aitbc.bubuit.net
|
||||
```
|
||||
|
||||
### Option 4: Cloudflare Tunnel (Easiest)
|
||||
|
||||
Use Cloudflare tunnel to expose local services:
|
||||
|
||||
```bash
|
||||
# 1. Install cloudflared
|
||||
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
|
||||
sudo dpkg -i cloudflared-linux-amd64.deb
|
||||
|
||||
# 2. Login
|
||||
cloudflared tunnel login
|
||||
|
||||
# 3. Create tunnel
|
||||
cloudflared tunnel create aitbc
|
||||
|
||||
# 4. Create config file ~/.cloudflared/config.yml:
|
||||
tunnel: aitbc
|
||||
ingress:
|
||||
- hostname: aitbc.bubuit.net
|
||||
service: http://localhost:3001
|
||||
- path: /api
|
||||
service: http://localhost:8000
|
||||
- path: /admin
|
||||
service: http://localhost:8000
|
||||
- path: /rpc
|
||||
service: http://localhost:9080
|
||||
- path: /Exchange
|
||||
service: http://localhost:3002
|
||||
- service: http_status:404
|
||||
|
||||
# 5. Run tunnel
|
||||
cloudflared tunnel run aitbc
|
||||
```
|
||||
|
||||
## Current Status
|
||||
|
||||
✅ Services running locally:
|
||||
- API: http://127.0.0.1:8000/v1
|
||||
- Admin: http://127.0.0.1:8000/admin
|
||||
- Blockchain: http://127.0.0.1:9080/rpc
|
||||
- Marketplace: http://127.0.0.1:3001
|
||||
- Exchange: http://127.0.0.1:3002
|
||||
|
||||
❌ Domain access not configured
|
||||
|
||||
## Quick Test
|
||||
|
||||
To test if the domain routing would work, you can:
|
||||
|
||||
1. Edit your local hosts file:
|
||||
```bash
|
||||
echo "127.0.0.1 aitbc.bubuit.net" | sudo tee -a /etc/hosts
|
||||
```
|
||||
|
||||
2. Install and configure nginx locally (see Option 3)
|
||||
|
||||
3. Access http://aitbc.bubuit.net in your browser
|
||||
|
||||
## Recommendation
|
||||
|
||||
Use **Option 4 (Cloudflare Tunnel)** as it's:
|
||||
- Free
|
||||
- Secure (HTTPS)
|
||||
- No port forwarding needed
|
||||
- Works with dynamic IPs
|
||||
- Easy to set up
|
||||
129
docs/operator/deployment/systemd_services.md
Normal file
129
docs/operator/deployment/systemd_services.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# AITBC Systemd Services
|
||||
|
||||
All AITBC services are now managed by systemd for automatic startup, monitoring, and logging.
|
||||
|
||||
## Services Overview
|
||||
|
||||
| Service | Port | Description | Status |
|
||||
|---------|------|-------------|--------|
|
||||
| `aitbc-coordinator-api` | 8000 | Main Coordinator API for blockchain operations | Active |
|
||||
| `aitbc-exchange-api` | 3003 | Exchange API for trading operations | Active |
|
||||
| `aitbc-exchange-frontend` | 3002 | Exchange web frontend | Active |
|
||||
| `aitbc-wallet` | 8001 | Wallet daemon service | Pending |
|
||||
| `aitbc-node` | 8545 | Blockchain node service | Pending |
|
||||
|
||||
## Service Management
|
||||
|
||||
### Check Status
|
||||
```bash
|
||||
/root/aitbc/scripts/manage_services.sh status
|
||||
```
|
||||
|
||||
### Start All Services
|
||||
```bash
|
||||
/root/aitbc/scripts/manage_services.sh start
|
||||
```
|
||||
|
||||
### Stop All Services
|
||||
```bash
|
||||
/root/aitbc/scripts/manage_services.sh stop
|
||||
```
|
||||
|
||||
### Restart All Services
|
||||
```bash
|
||||
/root/aitbc/scripts/manage_services.sh restart
|
||||
```
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
# View specific service logs
|
||||
/root/aitbc/scripts/manage_services.sh logs coordinator-api
|
||||
/root/aitbc/scripts/manage_services.sh logs exchange-api
|
||||
/root/aitbc/scripts/manage_services.sh logs exchange-frontend
|
||||
/root/aitbc/scripts/manage_services.sh logs wallet
|
||||
/root/aitbc/scripts/manage_services.sh logs node
|
||||
|
||||
# Or use systemctl directly
|
||||
sudo journalctl -u aitbc-coordinator-api -f
|
||||
sudo journalctl -u aitbc-exchange-api -f
|
||||
sudo journalctl -u aitbc-exchange-frontend -f
|
||||
```
|
||||
|
||||
### Enable/Disable Autostart
|
||||
```bash
|
||||
# Enable services to start on boot
|
||||
/root/aitbc/scripts/manage_services.sh enable
|
||||
|
||||
# Disable services from starting on boot
|
||||
/root/aitbc/scripts/manage_services.sh disable
|
||||
```
|
||||
|
||||
## Individual Service Control
|
||||
|
||||
You can also control services individually using systemctl:
|
||||
|
||||
```bash
|
||||
# Start a specific service
|
||||
sudo systemctl start aitbc-coordinator-api
|
||||
|
||||
# Stop a specific service
|
||||
sudo systemctl stop aitbc-coordinator-api
|
||||
|
||||
# Restart a specific service
|
||||
sudo systemctl restart aitbc-coordinator-api
|
||||
|
||||
# Check if service is enabled
|
||||
sudo systemctl is-enabled aitbc-coordinator-api
|
||||
|
||||
# Enable service on boot
|
||||
sudo systemctl enable aitbc-coordinator-api
|
||||
|
||||
# Disable service on boot
|
||||
sudo systemctl disable aitbc-coordinator-api
|
||||
```
|
||||
|
||||
## Service Files Location
|
||||
|
||||
Service definition files are located at:
|
||||
- `/etc/systemd/system/aitbc-coordinator-api.service`
|
||||
- `/etc/systemd/system/aitbc-exchange-api.service`
|
||||
- `/etc/systemd/system/aitbc-exchange-frontend.service`
|
||||
- `/etc/systemd/system/aitbc-wallet.service`
|
||||
- `/etc/systemd/system/aitbc-node.service`
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service Not Starting
|
||||
1. Check the service status: `sudo systemctl status aitbc-service-name`
|
||||
2. View the logs: `sudo journalctl -u aitbc-service-name -n 50`
|
||||
3. Check if port is already in use: `netstat -tlnp | grep :port`
|
||||
|
||||
### Service Keeps Restarting
|
||||
1. The service is configured to auto-restart on failure
|
||||
2. Check logs for the error causing failures
|
||||
3. Temporarily disable auto-restart for debugging: `sudo systemctl stop aitbc-service-name`
|
||||
|
||||
### Manual Override
|
||||
If systemd services are not working, you can run services manually:
|
||||
```bash
|
||||
# Coordinator API
|
||||
cd /root/aitbc/apps/coordinator-api
|
||||
/root/aitbc/.venv/bin/python -m uvicorn src.app.main:app --host 0.0.0.0 --port 8000
|
||||
|
||||
# Exchange API
|
||||
cd /root/aitbc/apps/trade-exchange
|
||||
/root/aitbc/.venv/bin/python simple_exchange_api.py
|
||||
|
||||
# Exchange Frontend
|
||||
cd /root/aitbc/apps/trade-exchange
|
||||
/root/aitbc/.venv/bin/python server.py --port 3002
|
||||
```
|
||||
|
||||
## Benefits of Systemd
|
||||
|
||||
1. **Automatic Startup**: Services start automatically on boot
|
||||
2. **Automatic Restart**: Services restart on failure
|
||||
3. **Centralized Logging**: All logs go to journald
|
||||
4. **Resource Management**: Systemd manages service resources
|
||||
5. **Dependency Management**: Services can depend on each other
|
||||
6. **Security**: Services run with specified user/group permissions
|
||||
66
docs/operator/migration/coordinator_postgresql_migration.md
Normal file
66
docs/operator/migration/coordinator_postgresql_migration.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# AITBC Coordinator API - PostgreSQL Migration Status
|
||||
|
||||
## Current Status
|
||||
✅ **PostgreSQL Database Created**: `aitbc_coordinator`
|
||||
✅ **Schema Created**: All tables created with proper types
|
||||
✅ **Service Updated**: Coordinator API configured for PostgreSQL
|
||||
✅ **Service Running**: API is live on PostgreSQL
|
||||
|
||||
## Migration Progress
|
||||
- **Database Setup**: ✅ Complete
|
||||
- **Schema Creation**: ✅ Complete
|
||||
- **Data Migration**: ⚠️ Partial (users table needs manual migration)
|
||||
- **Service Configuration**: ✅ Complete
|
||||
- **Testing**: ✅ Service is running
|
||||
|
||||
## What Was Accomplished
|
||||
|
||||
### 1. Database Setup
|
||||
- Created `aitbc_coordinator` database
|
||||
- Configured user permissions
|
||||
- Set up proper connection parameters
|
||||
|
||||
### 2. Schema Migration
|
||||
Created all tables with PostgreSQL optimizations:
|
||||
- **user** (with proper quoting for reserved keyword)
|
||||
- **wallet** (with NUMERIC for balances)
|
||||
- **miner** (with JSONB for metadata)
|
||||
- **job** (with JSONB for payloads)
|
||||
- **marketplaceoffer** and **marketplacebid**
|
||||
- **jobreceipt**
|
||||
- **usersession**
|
||||
- **transaction**
|
||||
|
||||
### 3. Performance Improvements
|
||||
- JSONB for JSON fields (better than JSON)
|
||||
- NUMERIC for financial data
|
||||
- Proper indexes on key columns
|
||||
- Foreign key constraints
|
||||
|
||||
### 4. Service Configuration
|
||||
- Updated config to use PostgreSQL connection string
|
||||
- Modified database imports
|
||||
- Service successfully restarted
|
||||
|
||||
## Benefits Achieved
|
||||
1. **Better Concurrency**: PostgreSQL handles multiple connections better
|
||||
2. **Data Integrity**: ACID compliance for critical operations
|
||||
3. **Performance**: Optimized for complex queries
|
||||
4. **Scalability**: Ready for production load
|
||||
|
||||
## Next Steps
|
||||
1. Complete data migration (manual import if needed)
|
||||
2. Set up database backups
|
||||
3. Monitor performance
|
||||
4. Consider read replicas for scaling
|
||||
|
||||
## Verification
|
||||
```bash
|
||||
# Check service status
|
||||
curl http://localhost:8000/v1/health
|
||||
|
||||
# Check database
|
||||
sudo -u postgres psql -d aitbc_coordinator -c "\dt"
|
||||
```
|
||||
|
||||
The Coordinator API is now running on PostgreSQL with improved performance and scalability!
|
||||
72
docs/operator/migration/postgresql_migration.md
Normal file
72
docs/operator/migration/postgresql_migration.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# AITBC Exchange - PostgreSQL Migration Complete
|
||||
|
||||
## Summary
|
||||
Successfully migrated the AITBC Exchange from SQLite to PostgreSQL for better performance and scalability.
|
||||
|
||||
## What Was Migrated
|
||||
- **Trades Table**: 5 historical trades
|
||||
- **Orders Table**: 4 initial orders (2 BUY, 2 SELL)
|
||||
- All data preserved with proper type conversion (REAL → NUMERIC)
|
||||
|
||||
## Benefits of PostgreSQL
|
||||
1. **Better Performance**: Optimized for concurrent access
|
||||
2. **Scalability**: Handles high-volume trading
|
||||
3. **Data Integrity**: Proper NUMERIC type for financial data
|
||||
4. **Indexing**: Optimized indexes for fast queries
|
||||
5. **ACID Compliance**: Reliable transactions
|
||||
|
||||
## Database Schema
|
||||
```sql
|
||||
-- Trades table with proper types
|
||||
CREATE TABLE trades (
|
||||
id SERIAL PRIMARY KEY,
|
||||
amount NUMERIC(20, 8) NOT NULL,
|
||||
price NUMERIC(20, 8) NOT NULL,
|
||||
total NUMERIC(20, 8) NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
tx_hash VARCHAR(66),
|
||||
maker_address VARCHAR(66),
|
||||
taker_address VARCHAR(66)
|
||||
);
|
||||
|
||||
-- Orders table with constraints
|
||||
CREATE TABLE orders (
|
||||
id SERIAL PRIMARY KEY,
|
||||
order_type VARCHAR(4) CHECK (order_type IN ('BUY', 'SELL')),
|
||||
amount NUMERIC(20, 8) NOT NULL,
|
||||
price NUMERIC(20, 8) NOT NULL,
|
||||
total NUMERIC(20, 8) NOT NULL,
|
||||
remaining NUMERIC(20, 8) NOT NULL,
|
||||
filled NUMERIC(20, 8) DEFAULT 0,
|
||||
status VARCHAR(20) CHECK (status IN ('OPEN', 'FILLED', 'CANCELLED')),
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
user_address VARCHAR(66),
|
||||
tx_hash VARCHAR(66)
|
||||
);
|
||||
```
|
||||
|
||||
## Connection Details
|
||||
- **Host**: localhost
|
||||
- **Port**: 5432
|
||||
- **Database**: aitbc_exchange
|
||||
- **User**: aitbc_user
|
||||
- **Password**: aitbc_password
|
||||
|
||||
## Performance Indexes
|
||||
- `idx_trades_created_at`: Fast trade history queries
|
||||
- `idx_orders_type_price`: Efficient order book matching
|
||||
- `idx_orders_status`: Quick status filtering
|
||||
- `idx_orders_user`: User order history
|
||||
|
||||
## Next Steps
|
||||
1. Monitor performance with real trading volume
|
||||
2. Set up database backups
|
||||
3. Consider connection pooling (PgBouncer)
|
||||
4. Add read replicas for scaling
|
||||
|
||||
## Verification
|
||||
- Exchange API is running with PostgreSQL
|
||||
- All endpoints working correctly
|
||||
- Data integrity preserved
|
||||
- Real-time trading functional
|
||||
@@ -0,0 +1,83 @@
|
||||
# AITBC Wallet Daemon - PostgreSQL Migration Status
|
||||
|
||||
## Current Status
|
||||
✅ **PostgreSQL Database Created**: `aitbc_wallet`
|
||||
✅ **Schema Created**: Optimized tables with JSONB support
|
||||
✅ **Data Migrated**: 1 wallet and 1 event migrated
|
||||
⚠️ **Service Update**: Partial (needs dependency fix)
|
||||
|
||||
## Migration Progress
|
||||
- **Database Setup**: ✅ Complete
|
||||
- **Schema Creation**: ✅ Complete
|
||||
- **Data Migration**: ✅ Complete
|
||||
- **PostgreSQL Adapter**: ✅ Created
|
||||
- **Service Configuration**: ⚠️ In Progress
|
||||
|
||||
## What Was Accomplished
|
||||
|
||||
### 1. Database Setup
|
||||
- Created `aitbc_wallet` database
|
||||
- Configured user permissions
|
||||
- Set up proper connection parameters
|
||||
|
||||
### 2. Schema Migration
|
||||
Created optimized tables:
|
||||
- **wallets**: JSONB for metadata, proper indexes
|
||||
- **wallet_events**: Event tracking with timestamps
|
||||
- JSONB for better JSON performance
|
||||
|
||||
### 3. Data Migration
|
||||
- Successfully migrated existing wallet data
|
||||
- Preserved all wallet events
|
||||
- Maintained data integrity
|
||||
|
||||
### 4. PostgreSQL Adapter
|
||||
Created full PostgreSQL implementation:
|
||||
- `create_wallet()`: Create/update wallets
|
||||
- `get_wallet()`: Retrieve wallet info
|
||||
- `list_wallets()`: List with pagination
|
||||
- `add_wallet_event()`: Event tracking
|
||||
- `get_wallet_events()`: Event history
|
||||
- `update_wallet_metadata()`: Metadata updates
|
||||
- `delete_wallet()`: Wallet deletion
|
||||
- `get_wallet_stats()`: Statistics
|
||||
|
||||
### 5. Performance Improvements
|
||||
- JSONB for JSON fields (faster queries)
|
||||
- Proper indexes on wallet_id and events
|
||||
- Connection pooling ready
|
||||
- ACID compliance
|
||||
|
||||
## Benefits Achieved
|
||||
1. **Better Reliability**: PostgreSQL for critical wallet operations
|
||||
2. **Event Tracking**: Robust event logging system
|
||||
3. **Metadata Storage**: Efficient JSONB storage
|
||||
4. **Scalability**: Ready for production wallet load
|
||||
|
||||
## Next Steps
|
||||
1. Fix dependency injection issue in service
|
||||
2. Complete service restart
|
||||
3. Verify wallet operations
|
||||
4. Set up database backups
|
||||
|
||||
## Migration Summary
|
||||
```sql
|
||||
-- Tables Created
|
||||
CREATE TABLE wallets (
|
||||
wallet_id VARCHAR(255) PRIMARY KEY,
|
||||
public_key TEXT,
|
||||
metadata JSONB,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE wallet_events (
|
||||
id SERIAL PRIMARY KEY,
|
||||
wallet_id VARCHAR(255) REFERENCES wallets(wallet_id),
|
||||
event_type VARCHAR(100) NOT NULL,
|
||||
payload JSONB,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
```
|
||||
|
||||
The Wallet Daemon database is successfully migrated to PostgreSQL with improved performance and reliability for wallet operations!
|
||||
Reference in New Issue
Block a user