aitbc1/blockchain-production #39

Merged
oib merged 5 commits from aitbc1/blockchain-production into main 2026-03-18 16:25:36 +01:00
8 changed files with 55 additions and 16 deletions
Showing only changes of commit 37e5e2d5cd - Show all commits

View File

@@ -1 +0,0 @@
GITEA_TOKEN=ffce3b62d583b761238ae00839dce7718acaad85

View File

@@ -3,12 +3,17 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
VENV_PYTHON="$ROOT_DIR/.venv/bin/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "[devnet] Virtualenv not found at $VENV_PYTHON. Please create it: python -m venv .venv && .venv/bin/pip install -r requirements.txt"
exit 1
fi
export PYTHONPATH="${ROOT_DIR}/src:${ROOT_DIR}/scripts:${PYTHONPATH:-}"
GENESIS_PATH="data/devnet/genesis.json"
ALLOCATIONS_PATH="data/devnet/allocations.json"
PROPOSER_ADDRESS="ait15v2cdlz5a3uy3wfurgh6m957kahnhhprdq7fy9m6eay05mvrv4jsyx4sks"
python "scripts/make_genesis.py" \
"$VENV_PYTHON" "scripts/make_genesis.py" \
--output "$GENESIS_PATH" \
--force \
--allocations "$ALLOCATIONS_PATH" \
@@ -42,18 +47,18 @@ cleanup() {
}
trap cleanup EXIT
python -m aitbc_chain.main &
"$VENV_PYTHON" -m aitbc_chain.main &
CHILD_PIDS+=($!)
echo "[devnet] Blockchain node started (PID ${CHILD_PIDS[-1]})"
sleep 1
python -m uvicorn aitbc_chain.app:app --host 127.0.0.1 --port 8026 --log-level info &
"$VENV_PYTHON" -m uvicorn aitbc_chain.app:app --host 127.0.0.1 --port 8026 --log-level info &
CHILD_PIDS+=($!)
echo "[devnet] RPC API serving at http://127.0.0.1:8026"
# Optional: mock coordinator for devnet only
# python -m uvicorn mock_coordinator:app --host 127.0.0.1 --port 8090 --log-level info &
# "$VENV_PYTHON" -m uvicorn mock_coordinator:app --host 127.0.0.1 --port 8090 --log-level info &
# CHILD_PIDS+=($!)
# echo "[devnet] Mock coordinator serving at http://127.0.0.1:8090"

View File

@@ -3,6 +3,11 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
VENV_PYTHON="$ROOT_DIR/.venv/bin/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "[mainnet] Virtualenv not found at $VENV_PYTHON. Please create it: python -m venv .venv && .venv/bin/pip install -r requirements.txt"
exit 1
fi
export PYTHONPATH="${ROOT_DIR}/src:${ROOT_DIR}/scripts:${PYTHONPATH:-}"
# Load production environment
@@ -67,13 +72,13 @@ cleanup() {
}
trap cleanup EXIT
python -m aitbc_chain.main &
"$VENV_PYTHON" -m aitbc_chain.main &
CHILD_PIDS+=($!)
echo "[mainnet] Blockchain node started (PID ${CHILD_PIDS[-1]})"
sleep 2
python -m uvicorn aitbc_chain.app:app --host 127.0.0.1 --port 8026 --log-level info &
"$VENV_PYTHON" -m uvicorn aitbc_chain.app:app --host 127.0.0.1 --port 8026 --log-level info &
CHILD_PIDS+=($!)
echo "[mainnet] RPC API serving at http://127.0.0.1:8026"

View File

@@ -16,7 +16,7 @@ from .mempool import init_mempool
from .metrics import metrics_registry
from .rpc.router import router as rpc_router
from .rpc.websocket import router as websocket_router
from .escrow_routes import router as escrow_router
# from .escrow_routes import router as escrow_router # Not yet implemented
_app_logger = get_logger("aitbc_chain.app")
@@ -132,7 +132,7 @@ def create_app() -> FastAPI:
# Include routers
app.include_router(rpc_router, prefix="/rpc", tags=["rpc"])
app.include_router(websocket_router, prefix="/rpc")
app.include_router(escrow_router, prefix="/rpc")
# app.include_router(escrow_router, prefix="/rpc") # Disabled until escrow routes are implemented
# Metrics and health endpoints
metrics_router = APIRouter()

View File

@@ -4,6 +4,7 @@ from sqlalchemy import func
import asyncio
import json
import time
from pathlib import Path
from typing import Any, Dict, Optional
from fastapi import APIRouter, HTTPException, status

View File

@@ -469,6 +469,6 @@ def create_app() -> FastAPI:
app = create_app()
# Register jobs router
from .routers import jobs as jobs_router
app.include_router(jobs_router.router)
# Register jobs router (disabled - legacy)
# from .routers import jobs as jobs_router
# app.include_router(jobs_router.router)

View File

@@ -11,11 +11,12 @@ router = APIRouter(tags=["blockchain"])
async def blockchain_status():
"""Get blockchain status."""
try:
# Try to get blockchain status from RPC
import httpx
from ..config import settings
rpc_url = settings.blockchain_rpc_url.rstrip('/')
async with httpx.AsyncClient() as client:
response = await client.get("http://localhost:8003/rpc/head", timeout=5.0)
response = await client.get(f"{rpc_url}/rpc/head", timeout=5.0)
if response.status_code == 200:
data = response.json()
return {
@@ -42,11 +43,12 @@ async def blockchain_status():
async def blockchain_sync_status():
"""Get blockchain synchronization status."""
try:
# Try to get sync status from RPC
import httpx
from ..config import settings
rpc_url = settings.blockchain_rpc_url.rstrip('/')
async with httpx.AsyncClient() as client:
response = await client.get("http://localhost:8003/rpc/sync", timeout=5.0)
response = await client.get(f"{rpc_url}/rpc/sync", timeout=5.0)
if response.status_code == 200:
data = response.json()
return {

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python3
import secrets
import string
import json
import os
def random_string(length=32):
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for _ in range(length))
def generate_production_keys():
client_key = f"client_prod_key_{random_string(24)}"
miner_key = f"miner_prod_key_{random_string(24)}"
admin_key = f"admin_prod_key_{random_string(24)}"
hmac_secret = random_string(64)
jwt_secret = random_string(64)
return {
"CLIENT_API_KEYS": [client_key],
"MINER_API_KEYS": [miner_key],
"ADMIN_API_KEYS": [admin_key],
"HMAC_SECRET": hmac_secret,
"JWT_SECRET": jwt_secret
}
if __name__ == "__main__":
keys = generate_production_keys()
print(json.dumps(keys, indent=2))