Update Python version requirements and fix compatibility issues

- Bump minimum Python version from 3.11 to 3.13 across all apps
- Add Python 3.11-3.13 test matrix to CLI workflow
- Document Python 3.11+ requirement in .env.example
- Fix Starlette Broadcast removal with in-process fallback implementation
- Add _InProcessBroadcast class for tests when Starlette Broadcast is unavailable
- Refactor API key validators to read live settings instead of cached values
- Update database models with explicit
This commit is contained in:
oib
2026-02-24 18:41:08 +01:00
parent 24b3a37733
commit 825f157749
270 changed files with 66674 additions and 2027 deletions

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

@@ -1,8 +1,29 @@
#!/bin/bash
# Setup AITBC Systemd Services
# Requirements: Python 3.11+, systemd, sudo access
echo "🔧 Setting up AITBC systemd services..."
# Validate Python version
echo "🐍 Checking Python version..."
if ! python3.11 --version >/dev/null 2>&1; then
echo "❌ Error: Python 3.11+ is required but not found"
echo " Please install Python 3.11+ and try again"
exit 1
fi
PYTHON_VERSION=$(python3.11 --version | cut -d' ' -f2)
echo "✅ Found Python $PYTHON_VERSION"
# Validate systemctl is available
if ! command -v systemctl >/dev/null 2>&1; then
echo "❌ Error: systemctl not found. This script requires systemd."
exit 1
fi
echo "✅ Systemd available"
# Copy service files
echo "📁 Copying service files..."
sudo cp systemd/aitbc-*.service /etc/systemd/system/

357
scripts/test/deploy-agent-docs.sh Executable file
View File

@@ -0,0 +1,357 @@
#!/bin/bash
# deploy-agent-docs.sh - Test deployment of AITBC agent documentation
set -e
echo "🚀 Starting AITBC Agent Documentation Deployment Test"
# Configuration
DOCS_DIR="docs/11_agents"
LIVE_SERVER="aitbc-cascade"
WEB_ROOT="/var/www/aitbc.bubuit.net/docs/agents"
TEST_DIR="/tmp/aitbc-agent-docs-test"
# 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}"
}
# Step 1: Validate local files
echo "📋 Step 1: Validating local documentation files..."
if [ ! -d "$DOCS_DIR" ]; then
print_error "Documentation directory not found: $DOCS_DIR"
exit 1
fi
# Check required files
required_files=(
"README.md"
"getting-started.md"
"agent-manifest.json"
"agent-quickstart.yaml"
"agent-api-spec.json"
"index.yaml"
"compute-provider.md"
"advanced-ai-agents.md"
"collaborative-agents.md"
"openclaw-integration.md"
"project-structure.md"
"MERGE_SUMMARY.md"
)
missing_files=()
for file in "${required_files[@]}"; do
if [ ! -f "$DOCS_DIR/$file" ]; then
missing_files+=("$file")
fi
done
if [ ${#missing_files[@]} -gt 0 ]; then
print_error "Required files missing:"
for file in "${missing_files[@]}"; do
echo " - $file"
done
exit 1
fi
print_status "All required files present ($(echo ${#required_files[@]} files)"
# Step 2: Validate JSON/YAML syntax
echo "🔍 Step 2: Validating JSON/YAML syntax..."
# Validate JSON files
json_files=("agent-manifest.json" "agent-api-spec.json")
for json_file in "${json_files[@]}"; do
if ! python3 -m json.tool "$DOCS_DIR/$json_file" > /dev/null 2>&1; then
print_error "Invalid JSON in $json_file"
exit 1
fi
print_status "JSON valid: $json_file"
done
# Validate YAML files
yaml_files=("agent-quickstart.yaml" "index.yaml")
for yaml_file in "${yaml_files[@]}"; do
if ! python3 -c "import yaml; yaml.safe_load(open('$DOCS_DIR/$yaml_file'))" 2>/dev/null; then
print_error "Invalid YAML in $yaml_file"
exit 1
fi
print_status "YAML valid: $yaml_file"
done
print_status "All JSON/YAML syntax valid"
# Step 3: Test documentation structure
echo "🏗️ Step 3: Testing documentation structure..."
# Create Python test script
cat > /tmp/test_docs_structure.py << 'EOF'
import json
import yaml
import os
import sys
def test_agent_manifest():
try:
with open('docs/11_agents/agent-manifest.json') as f:
manifest = json.load(f)
required_keys = ['aitbc_agent_manifest']
for key in required_keys:
if key not in manifest:
raise Exception(f"Missing key in manifest: {key}")
# Check agent types
agent_types = manifest['aitbc_agent_manifest'].get('agent_types', {})
required_agent_types = ['compute_provider', 'compute_consumer', 'platform_builder', 'swarm_coordinator']
for agent_type in required_agent_types:
if agent_type not in agent_types:
raise Exception(f"Missing agent type: {agent_type}")
print("✅ Agent manifest validation passed")
return True
except Exception as e:
print(f"❌ Agent manifest validation failed: {e}")
return False
def test_api_spec():
try:
with open('docs/11_agents/agent-api-spec.json') as f:
api_spec = json.load(f)
if 'aitbc_agent_api' not in api_spec:
raise Exception("Missing aitbc_agent_api key")
endpoints = api_spec['aitbc_agent_api'].get('endpoints', {})
required_endpoints = ['agent_registry', 'resource_marketplace', 'swarm_coordination', 'reputation_system']
for endpoint in required_endpoints:
if endpoint not in endpoints:
raise Exception(f"Missing endpoint: {endpoint}")
print("✅ API spec validation passed")
return True
except Exception as e:
print(f"❌ API spec validation failed: {e}")
return False
def test_quickstart():
try:
with open('docs/11_agents/agent-quickstart.yaml') as f:
quickstart = yaml.safe_load(f)
required_sections = ['network', 'agent_types', 'onboarding_workflow']
for section in required_sections:
if section not in quickstart:
raise Exception(f"Missing section: {section}")
print("✅ Quickstart validation passed")
return True
except Exception as e:
print(f"❌ Quickstart validation failed: {e}")
return False
def test_index_structure():
try:
with open('docs/11_agents/index.yaml') as f:
index = yaml.safe_load(f)
required_sections = ['network', 'agent_types', 'documentation_structure']
for section in required_sections:
if section not in index:
raise Exception(f"Missing section in index: {section}")
print("✅ Index structure validation passed")
return True
except Exception as e:
print(f"❌ Index structure validation failed: {e}")
return False
if __name__ == "__main__":
tests = [
test_agent_manifest,
test_api_spec,
test_quickstart,
test_index_structure
]
passed = 0
for test in tests:
if test():
passed += 1
else:
sys.exit(1)
print(f"✅ All {passed} documentation tests passed")
EOF
if ! python3 /tmp/test_docs_structure.py; then
print_error "Documentation structure validation failed"
rm -f /tmp/test_docs_structure.py
exit 1
fi
rm -f /tmp/test_docs_structure.py
print_status "Documentation structure validation passed"
# Step 4: Create test deployment
echo "📦 Step 4: Creating test deployment..."
# Clean up previous test
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
# Copy documentation files
cp -r "$DOCS_DIR"/* "$TEST_DIR/"
# Set proper permissions
find "$TEST_DIR" -type f -exec chmod 644 {} \;
find "$TEST_DIR" -type d -exec chmod 755 {} \;
# Calculate documentation size
doc_size=$(du -sm "$TEST_DIR" | cut -f1)
file_count=$(find "$TEST_DIR" -type f | wc -l)
json_count=$(find "$TEST_DIR" -name "*.json" | wc -l)
yaml_count=$(find "$TEST_DIR" -name "*.yaml" | wc -l)
md_count=$(find "$TEST_DIR" -name "*.md" | wc -l)
print_status "Test deployment created"
echo " 📊 Size: ${doc_size}MB"
echo " 📄 Files: $file_count total"
echo " 📋 JSON: $json_count files"
echo " 📋 YAML: $yaml_count files"
echo " 📋 Markdown: $md_count files"
# Step 5: Test file accessibility
echo "🔍 Step 5: Testing file accessibility..."
# Test key files can be read
test_files=(
"$TEST_DIR/README.md"
"$TEST_DIR/agent-manifest.json"
"$TEST_DIR/agent-quickstart.yaml"
"$TEST_DIR/agent-api-spec.json"
)
for file in "${test_files[@]}"; do
if [ ! -r "$file" ]; then
print_error "Cannot read file: $file"
exit 1
fi
done
print_status "All test files accessible"
# Step 6: Test content integrity
echo "🔐 Step 6: Testing content integrity..."
# Test JSON files can be parsed
for json_file in "$TEST_DIR"/*.json; do
if [ -f "$json_file" ]; then
if ! python3 -m json.tool "$json_file" > /dev/null 2>&1; then
print_error "JSON file corrupted: $(basename $json_file)"
exit 1
fi
fi
done
# Test YAML files can be parsed
for yaml_file in "$TEST_DIR"/*.yaml; do
if [ -f "$yaml_file" ]; then
if ! python3 -c "import yaml; yaml.safe_load(open('$yaml_file'))" 2>/dev/null; then
print_error "YAML file corrupted: $(basename $yaml_file)"
exit 1
fi
fi
done
print_status "Content integrity verified"
# Step 7: Generate deployment report
echo "📊 Step 7: Generating deployment report..."
report_file="$TEST_DIR/deployment-report.json"
cat > "$report_file" << EOF
{
"deployment_test": {
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"status": "passed",
"tests_completed": [
"file_structure_validation",
"json_yaml_syntax_validation",
"documentation_structure_testing",
"test_deployment_creation",
"file_accessibility_testing",
"content_integrity_verification"
],
"statistics": {
"total_files": $file_count,
"json_files": $json_count,
"yaml_files": $yaml_count,
"markdown_files": $md_count,
"total_size_mb": $doc_size
},
"required_files": {
"count": ${#required_files[@]},
"all_present": true
},
"ready_for_production": true,
"next_steps": [
"Deploy to live server",
"Update web server configuration",
"Test live URLs",
"Monitor performance"
]
}
}
EOF
print_status "Deployment report generated"
# Step 8: Cleanup
echo "🧹 Step 8: Cleanup..."
rm -rf "$TEST_DIR"
print_status "Test cleanup completed"
# Final summary
echo ""
echo "🎉 DEPLOYMENT TESTING COMPLETED SUCCESSFULLY!"
echo ""
echo "📋 TEST SUMMARY:"
echo " ✅ File structure validation"
echo " ✅ JSON/YAML syntax validation"
echo " ✅ Documentation structure testing"
echo " ✅ Test deployment creation"
echo " ✅ File accessibility testing"
echo " ✅ Content integrity verification"
echo ""
echo "📊 STATISTICS:"
echo " 📄 Total files: $file_count"
echo " 📋 JSON files: $json_count"
echo " 📋 YAML files: $yaml_count"
echo " 📋 Markdown files: $md_count"
echo " 💾 Total size: ${doc_size}MB"
echo ""
echo "🚀 READY FOR PRODUCTION DEPLOYMENT!"
echo ""
echo "Next steps:"
echo "1. Deploy to live server: ssh $LIVE_SERVER"
echo "2. Copy files to: $WEB_ROOT"
echo "3. Test live URLs"
echo "4. Monitor performance"