Files
aitbc/scripts/utils/run_production_node.py
aitbc1 bfe6f94b75
Some checks failed
AITBC CI/CD Pipeline / lint-and-test (3.11) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.12) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.13) (push) Has been cancelled
AITBC CI/CD Pipeline / test-cli (push) Has been cancelled
AITBC CI/CD Pipeline / test-services (push) Has been cancelled
AITBC CI/CD Pipeline / test-production-services (push) Has been cancelled
AITBC CI/CD Pipeline / security-scan (push) Has been cancelled
AITBC CI/CD Pipeline / build (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-staging (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-production (push) Has been cancelled
AITBC CI/CD Pipeline / performance-test (push) Has been cancelled
AITBC CI/CD Pipeline / docs (push) Has been cancelled
AITBC CI/CD Pipeline / release (push) Has been cancelled
AITBC CI/CD Pipeline / notify (push) Has been cancelled
Security Scanning / Bandit Security Scan (apps/coordinator-api/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (cli/aitbc_cli) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-core/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-crypto/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-sdk/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (tests) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (javascript) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (python) (push) Has been cancelled
Security Scanning / Dependency Security Scan (push) Has been cancelled
Security Scanning / Container Security Scan (push) Has been cancelled
Security Scanning / OSSF Scorecard (push) Has been cancelled
Security Scanning / Security Summary Report (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.11) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.12) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.13) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-summary (push) Has been cancelled
chore: remove outdated documentation and reference files
- Remove debugging service documentation (DEBUgging_SERVICES.md)
- Remove development logs policy and quick reference guides
- Remove E2E test creation summary
- Remove gift certificate example file
- Remove GitHub pull summary documentation
2026-03-25 12:56:07 +01:00

69 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
Production launcher for AITBC blockchain node.
Sets up environment, initializes genesis if needed, and starts the node.
"""
from __future__ import annotations
import os
import sys
import subprocess
from pathlib import Path
# Configuration
CHAIN_ID = "ait-mainnet"
DATA_DIR = Path("/opt/aitbc/data/ait-mainnet")
DB_PATH = DATA_DIR / "chain.db"
KEYS_DIR = Path("/opt/aitbc/keystore")
# Check for proposer key in keystore
PROPOSER_KEY_FILE = KEYS_DIR / "aitbc1genesis.json"
if not PROPOSER_KEY_FILE.exists():
print(f"[!] Proposer keystore not found at {PROPOSER_KEY_FILE}")
print(" Run scripts/keystore.py to generate it first.")
sys.exit(1)
# Set environment variables
os.environ["CHAIN_ID"] = CHAIN_ID
os.environ["SUPPORTED_CHAINS"] = CHAIN_ID
os.environ["DB_PATH"] = str(DB_PATH)
os.environ["PROPOSER_ID"] = "aitbc1genesis"
# PROPOSER_KEY will be read from keystore by the node? Currently .env expects hex directly.
# We can read the keystore, decrypt, and set PROPOSER_KEY, but the node doesn't support that out of box.
# So we require that PROPOSER_KEY is set in .env file manually after key generation.
# This script will check for PROPOSER_KEY env var or fail with instructions.
if not os.getenv("PROPOSER_KEY"):
print("[!] PROPOSER_KEY environment variable not set.")
print(" Please edit /opt/aitbc/apps/blockchain-node/.env and set PROPOSER_KEY to the hex private key of aitbc1genesis.")
sys.exit(1)
# Ensure data directory
DATA_DIR.mkdir(parents=True, exist_ok=True)
# Optionally initialize genesis if DB doesn't exist
if not DB_PATH.exists():
print("[*] Database not found. Initializing production genesis...")
result = subprocess.run([
sys.executable,
"/opt/aitbc/scripts/init_production_genesis.py",
"--chain-id", CHAIN_ID,
"--db-path", str(DB_PATH)
], check=False)
if result.returncode != 0:
print("[!] Genesis initialization failed. Aborting.")
sys.exit(1)
# Start the node
print(f"[*] Starting blockchain node for chain {CHAIN_ID}...")
# Change to the blockchain-node directory (since .env and uvicorn expect relative paths)
os.chdir("/opt/aitbc/apps/blockchain-node")
# Use the virtualenv Python
venv_python = Path("/opt/aitbc/apps/blockchain-node/.venv/bin/python")
if not venv_python.exists():
print(f"[!] Virtualenv not found at {venv_python}")
sys.exit(1)
# Exec uvicorn
os.execv(str(venv_python), [str(venv_python), "-m", "uvicorn", "aitbc_chain.app:app", "--host", "127.0.0.1", "--port", "8006"])