chore(systemd): remove obsolete systemd service files and update infrastructure documentation

- Remove 8 unused systemd service files from coordinator-api/systemd/
  - aitbc-adaptive-learning.service (port 8005)
  - aitbc-advanced-ai.service
  - aitbc-enterprise-api.service
  - aitbc-gpu-multimodal.service (port 8003)
  - aitbc-marketplace-enhanced.service (port 8006)
  - aitbc-modality-optimization.service (port 8004)
  - aitbc-multimodal.service (port 8002)
  - aitbc-openclaw-enhanced.service (port 8007
This commit is contained in:
oib
2026-03-04 12:16:50 +01:00
parent 581309369d
commit 50954a4b31
101 changed files with 1655 additions and 4871 deletions

View File

@@ -0,0 +1,43 @@
#!/bin/bash
echo "=== AITBC Bootstrap Genesis Setup ==="
echo ""
# Stop the blockchain node
echo "1. Stopping blockchain node..."
sudo systemctl stop aitbc-node
# Backup current data
echo "2. Backing up current blockchain data..."
sudo mv /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite.backup.$(date +%s) 2>/dev/null || true
# Copy new genesis
echo "3. Applying bootstrap genesis..."
sudo cp /root/aitbc/apps/blockchain-node/data/genesis_with_bootstrap.json /root/aitbc/apps/blockchain-node/data/devnet/genesis.json
# Reset database
echo "4. Resetting blockchain database..."
sudo rm -f /root/aitbc/apps/blockchain-node/data/devnet/db.sqlite
# Restart blockchain node
echo "5. Restarting blockchain node..."
sudo systemctl start aitbc-node
# Wait for node to start
echo "6. Waiting for node to initialize..."
sleep 5
# Verify treasury balance
echo "7. Verifying treasury balance..."
curl -s http://localhost:9080/rpc/getBalance/aitbcexchange00000000000000000000000000000000 | jq
echo ""
echo "=== Bootstrap Complete! ==="
echo "Treasury should now have 10,000,000 AITBC"
echo ""
echo "Initial Distribution:"
echo "- Exchange Treasury: 10,000,000 AITBC (47.6%)"
echo "- Community Faucet: 1,000,000 AITBC (4.8%)"
echo "- Team Fund: 2,000,000 AITBC (9.5%)"
echo "- Early Investors: 5,000,000 AITBC (23.8%)"
echo "- Ecosystem Fund: 3,000,000 AITBC (14.3%)"

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""
Script to assign a proposer to a block by polling for it
"""
import httpx
import json
# Configuration
COORDINATOR_URL = "http://localhost:8001"
MINER_API_KEY = "${MINER_API_KEY}"
MINER_ID = "localhost-gpu-miner"
def assign_proposer_to_latest_block():
"""Poll for the latest unassigned job to become the proposer"""
# First register the miner
print("📝 Registering miner...")
register_response = httpx.post(
f"{COORDINATOR_URL}/v1/miners/register?miner_id={MINER_ID}",
headers={
"Content-Type": "application/json",
"X-Api-Key": MINER_API_KEY
},
json={
"capabilities": {
"gpu": {"model": "RTX 4060 Ti", "memory_gb": 16}
}
}
)
if register_response.status_code != 200:
print(f"❌ Registration failed: {register_response.text}")
return
print("✅ Miner registered")
# Poll for a job
print("\n🔍 Polling for jobs...")
poll_response = httpx.post(
f"{COORDINATOR_URL}/v1/miners/poll",
headers={
"Content-Type": "application/json",
"X-Api-Key": MINER_API_KEY
},
json={"max_wait_seconds": 1}
)
if poll_response.status_code == 200:
job = poll_response.json()
print(f"✅ Received job: {job['job_id']}")
print(f" This job is now assigned to miner: {MINER_ID}")
# Check the block
print("\n📦 Checking block...")
blocks_response = httpx.get(f"{COORDINATOR_URL}/v1/explorer/blocks")
if blocks_response.status_code == 200:
blocks = blocks_response.json()
for block in blocks['items']:
if block['hash'] == job['job_id']:
print(f"✅ Block updated!")
print(f" Height: {block['height']}")
print(f" Hash: {block['hash']}")
print(f" Proposer: {block['proposer']}")
break
elif poll_response.status_code == 204:
print(" No jobs available to poll")
else:
print(f"❌ Poll failed: {poll_response.text}")
if __name__ == "__main__":
print("🎯 Assign Proposer to Latest Block")
print("=" * 40)
assign_proposer_to_latest_block()

View File

@@ -0,0 +1,323 @@
#!/bin/bash
# Blockchain Synchronization Optimization Script
# Fixes common sync issues and optimizes cross-site synchronization
set -e
echo "🔧 Blockchain Synchronization Optimization"
echo "=========================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
# Function to check if service is running
check_service() {
local service=$1
local host=$2
if [ -z "$host" ]; then
if systemctl is-active --quiet "$service"; then
return 0
else
return 1
fi
else
if ssh "$host" "systemctl is-active --quiet '$service'"; then
return 0
else
return 1
fi
fi
}
# Function to restart service
restart_service() {
local service=$1
local host=$2
if [ -z "$host" ]; then
sudo systemctl restart "$service"
else
ssh "$host" "sudo systemctl restart '$service'"
fi
}
# Function to get blockchain height
get_height() {
local url=$1
local host=$2
if [ -z "$host" ]; then
curl -s "$url/head" 2>/dev/null | grep -o '"height":[^,]*' | cut -d'"' -f2
else
ssh "$host" "curl -s '$url/head' 2>/dev/null | grep -o '\"height\":[^,]*' | cut -d'\"' -f2"
fi
}
echo ""
echo "📊 Current Sync Status Analysis"
echo "=============================="
# Get current heights
echo "Checking current blockchain heights..."
NODE1_HEIGHT=$(get_height "http://localhost:8082/rpc" "aitbc-cascade")
NODE2_HEIGHT=$(get_height "http://localhost:8081/rpc" "aitbc-cascade")
NODE3_HEIGHT=$(get_height "http://192.168.100.10:8082/rpc" "ns3-root")
echo "Node 1 (aitbc-cascade): $NODE1_HEIGHT"
echo "Node 2 (aitbc-cascade): $NODE2_HEIGHT"
echo "Node 3 (ns3): $NODE3_HEIGHT"
# Calculate height differences
if [ -n "$NODE1_HEIGHT" ] && [ -n "$NODE2_HEIGHT" ]; then
DIFF12=$((NODE2_HEIGHT - NODE1_HEIGHT))
echo "Height difference (Node2 - Node1): $DIFF12"
fi
if [ -n "$NODE2_HEIGHT" ] && [ -n "$NODE3_HEIGHT" ]; then
DIFF23=$((NODE2_HEIGHT - NODE3_HEIGHT))
echo "Height difference (Node2 - Node3): $DIFF23"
fi
echo ""
echo "🔧 Step 1: Fix Node 1 Endpoint Configuration"
echo "============================================="
# Check Node 1 config for wrong endpoint
echo "Checking Node 1 configuration..."
NODE1_CONFIG=$(ssh aitbc-cascade "grep -n 'aitbc.bubuit.net/rpc2' /opt/blockchain-node/src/aitbc_chain/config.py 2>/dev/null || true")
if [ -n "$NODE1_CONFIG" ]; then
print_warning "Found wrong endpoint /rpc2 in Node 1 config"
echo "Fixing endpoint configuration..."
# Backup original config
ssh aitbc-cascade "sudo cp /opt/blockchain-node/src/aitbc_chain/config.py /opt/blockchain-node/src/aitbc_chain/config.py.backup"
# Fix the endpoint
ssh aitbc-cascade "sudo sed -i 's|https://aitbc.bubuit.net/rpc2|https://aitbc.bubuit.net/rpc|g' /opt/blockchain-node/src/aitbc_chain/config.py"
print_status "Fixed Node 1 endpoint configuration"
# Restart Node 1
echo "Restarting Node 1 service..."
restart_service "aitbc-blockchain-node-1.service" "aitbc-cascade"
sleep 5
if check_service "aitbc-blockchain-node-1.service" "aitbc-cascade"; then
print_status "Node 1 service restarted successfully"
else
print_error "Node 1 service failed to restart"
fi
else
print_status "Node 1 endpoint configuration is correct"
fi
echo ""
echo "🔧 Step 2: Fix Node 3 Services"
echo "=============================="
# Check Node 3 service status
echo "Checking Node 3 services..."
NODE3_STATUS=$(ssh ns3-root "systemctl is-active blockchain-node-3.service 2>/dev/null || echo 'failed'")
if [ "$NODE3_STATUS" = "failed" ] || [ "$NODE3_STATUS" = "activating" ]; then
print_warning "Node 3 service is in $NODE3_STATUS state"
echo "Checking Node 3 service logs..."
ssh ns3-root "journalctl -u blockchain-node-3.service --no-pager -n 10"
echo "Attempting to fix Node 3 service..."
# Stop and restart Node 3
ssh ns3-root "sudo systemctl stop blockchain-node-3.service || true"
sleep 2
ssh ns3-root "sudo systemctl start blockchain-node-3.service"
sleep 5
# Check status again
NODE3_NEW_STATUS=$(ssh ns3-root "systemctl is-active blockchain-node-3.service 2>/dev/null || echo 'failed'")
if [ "$NODE3_NEW_STATUS" = "active" ]; then
print_status "Node 3 service fixed and running"
else
print_error "Node 3 service still not working: $NODE3_NEW_STATUS"
echo "Manual intervention required for Node 3"
fi
else
print_status "Node 3 service is running"
fi
echo ""
echo "🔧 Step 3: Optimize Sync Configuration"
echo "======================================"
# Function to optimize sync config
optimize_sync_config() {
local host=$1
local config_path=$2
echo "Optimizing sync configuration on $host..."
# Backup config
ssh "$host" "sudo cp '$config_path' '$config_path.backup' 2>/dev/null || true"
# Add/modify sync settings
ssh "$host" "sudo tee -a '$config_path' > /dev/null << 'EOF'
# Sync optimization settings
sync_interval_seconds: int = 5 # Reduced from 10s
sync_retry_attempts: int = 3
sync_retry_delay_seconds: int = 2
sync_timeout_seconds: int = 10
max_sync_height_diff: int = 1000 # Alert if difference exceeds this
EOF"
print_status "Sync configuration optimized on $host"
}
# Optimize sync configs
optimize_sync_config "aitbc-cascade" "/opt/blockchain-node/src/aitbc_chain/config.py"
optimize_sync_config "aitbc-cascade" "/opt/blockchain-node-2/src/aitbc_chain/config.py"
optimize_sync_config "ns3-root" "/opt/blockchain-node/src/aitbc_chain/config.py"
echo ""
echo "🔧 Step 4: Restart Services with New Config"
echo "=========================================="
# Restart all services
echo "Restarting blockchain services..."
for service in "aitbc-blockchain-node-1.service" "aitbc-blockchain-node-2.service"; do
echo "Restarting $service on aitbc-cascade..."
restart_service "$service" "aitbc-cascade"
sleep 3
done
for service in "blockchain-node-3.service"; do
echo "Restarting $service on ns3..."
restart_service "$service" "ns3-root"
sleep 3
done
echo ""
echo "📊 Step 5: Verify Sync Optimization"
echo "==================================="
# Wait for services to stabilize
echo "Waiting for services to stabilize..."
sleep 10
# Check new heights
echo "Checking new blockchain heights..."
NEW_NODE1_HEIGHT=$(get_height "http://localhost:8082/rpc" "aitbc-cascade")
NEW_NODE2_HEIGHT=$(get_height "http://localhost:8081/rpc" "aitbc-cascade")
NEW_NODE3_HEIGHT=$(get_height "http://192.168.100.10:8082/rpc" "ns3-root")
echo "New heights:"
echo "Node 1: $NEW_NODE1_HEIGHT"
echo "Node 2: $NEW_NODE2_HEIGHT"
echo "Node 3: $NEW_NODE3_HEIGHT"
# Calculate improvements
if [ -n "$NEW_NODE1_HEIGHT" ] && [ -n "$NEW_NODE2_HEIGHT" ] && [ -n "$NODE1_HEIGHT" ] && [ -n "$NODE2_HEIGHT" ]; then
OLD_DIFF=$((NODE2_HEIGHT - NODE1_HEIGHT))
NEW_DIFF=$((NEW_NODE2_HEIGHT - NEW_NODE1_HEIGHT))
echo "Height difference improvement:"
echo "Before: $OLD_DIFF"
echo "After: $NEW_DIFF"
if [ $NEW_DIFF -lt $OLD_DIFF ]; then
IMPROVEMENT=$((OLD_DIFF - NEW_DIFF))
print_status "Sync improved by $IMPROVEMENT blocks"
else
print_warning "Sync did not improve or got worse"
fi
fi
echo ""
echo "🔧 Step 6: Create Sync Monitoring Script"
echo "========================================="
# Create monitoring script
cat > /tmp/sync_monitor.sh << 'EOF'
#!/bin/bash
# Blockchain Sync Monitor
# Run this periodically to check sync health
echo "🔍 Blockchain Sync Monitor - $(date)"
echo "===================================="
# Get heights
NODE1=$(curl -s http://localhost:8082/rpc/head 2>/dev/null | grep -o '"height":[^,]*' | cut -d'"' -f2)
NODE2=$(curl -s http://localhost:8081/rpc/head 2>/dev/null | grep -o '"height":[^,]*' | cut -d'"' -f2)
NODE3=$(ssh ns3-root "curl -s http://192.168.100.10:8082/rpc/head 2>/dev/null | grep -o '\"height\":[^,]*' | cut -d'\"' -f2")
echo "Node 1: $NODE1"
echo "Node 2: $NODE2"
echo "Node 3: $NODE3"
# Check for issues
if [ -n "$NODE1" ] && [ -n "$NODE2" ]; then
DIFF=$((NODE2 - NODE1))
if [ $DIFF -gt 100 ]; then
echo "⚠️ WARNING: Node 1 and Node 2 height difference: $DIFF"
fi
fi
if [ -n "$NODE2" ] && [ -n "$NODE3" ]; then
DIFF=$((NODE2 - NODE3))
if [ $DIFF -gt 1000 ]; then
echo "⚠️ WARNING: Node 2 and Node 3 height difference: $DIFF"
fi
fi
echo "Sync check completed."
EOF
chmod +x /tmp/sync_monitor.sh
print_status "Created sync monitoring script: /tmp/sync_monitor.sh"
echo ""
echo "🎉 Sync Optimization Complete!"
echo "=============================="
echo ""
echo "📋 Summary of actions taken:"
echo "• Fixed Node 1 endpoint configuration"
echo "• Restarted problematic services"
echo "• Optimized sync intervals and retry logic"
echo "• Created monitoring script"
echo ""
echo "📊 Next steps:"
echo "1. Monitor sync performance with: /tmp/sync_monitor.sh"
echo "2. Set up cron job for periodic monitoring"
echo "3. Check logs for any remaining issues"
echo "4. Consider implementing P2P sync for better performance"
echo ""
echo "🔧 If issues persist:"
echo "• Check individual service logs: journalctl -u [service-name]"
echo "• Verify network connectivity between sites"
echo "• Consider manual block import for severely lagging nodes"
echo "• Review firewall and security group settings"
print_status "Blockchain synchronization optimization completed!"

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Script to return testnet Bitcoin
RETURN_ADDRESS="tb1qerzrlxcfu24davlur5sqmgzzgsal6wusda40er"
echo "Checking balance..."
BALANCE=$(bitcoin-cli -testnet -rpcwallet=aitbc_exchange getbalance)
if [ "$(echo "$BALANCE > 0" | bc)" -eq 1 ]; then
echo "Current balance: $BALANCE BTC"
echo "Sending to return address: $RETURN_ADDRESS"
# Calculate amount to send (balance minus small fee)
SEND_AMOUNT=$(echo "$BALANCE - 0.00001" | bc)
TXID=$(bitcoin-cli -testnet -rpcwallet=aitbc_exchange sendtoaddress "$RETURN_ADDRESS" "$SEND_AMOUNT")
echo "Transaction sent! TXID: $TXID"
echo "Explorer: https://blockstream.info/testnet/tx/$TXID"
else
echo "No Bitcoin to return. Current balance: $BALANCE BTC"
fi

View File

@@ -0,0 +1,87 @@
#!/bin/bash
# Start mock blockchain nodes for testing
# This script sets up the required mock servers on ports 8081 and 8082
set -e
echo "🚀 Starting Mock Blockchain Nodes for Testing"
echo "============================================="
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
# Check if required ports are available
check_port() {
local port=$1
if curl -s "http://127.0.0.1:$port/health" >/dev/null 2>&1; then
print_warning "Port $port is already in use"
return 1
fi
return 0
}
# Stop any existing mock servers
stop_existing_servers() {
print_status "Stopping existing mock servers..."
pkill -f "mock_blockchain_node.py" 2>/dev/null || true
sleep 1
}
# Start mock servers
start_mock_servers() {
print_status "Starting mock blockchain node on port 8081..."
cd "$(dirname "$0")/.."
python3 tests/mock_blockchain_node.py 8081 > /tmp/mock_node_8081.log 2>&1 &
local pid1=$!
print_status "Starting mock blockchain node on port 8082..."
python3 tests/mock_blockchain_node.py 8082 > /tmp/mock_node_8082.log 2>&1 &
local pid2=$!
# Wait for servers to start
sleep 2
# Verify servers are running
if curl -s "http://127.0.0.1:8081/health" >/dev/null 2>&1 && \
curl -s "http://127.0.0.1:8082/health" >/dev/null 2>&1; then
print_status "✅ Mock blockchain nodes are running!"
echo ""
echo "Node 1: http://127.0.0.1:8082"
echo "Node 2: http://127.0.0.1:8081"
echo ""
echo "To run tests:"
echo " python -m pytest tests/test_blockchain_nodes.py -v"
echo ""
echo "To stop servers:"
echo " pkill -f 'mock_blockchain_node.py'"
echo ""
echo "Log files:"
echo " Node 1: /tmp/mock_node_8082.log"
echo " Node 2: /tmp/mock_node_8081.log"
else
print_warning "❌ Failed to start mock servers"
echo "Check log files:"
echo " Node 1: /tmp/mock_node_8082.log"
echo " Node 2: /tmp/mock_node_8081.log"
exit 1
fi
}
# Main execution
main() {
stop_existing_servers
start_mock_servers
}
# Run main function
main "$@"