feat: add multi-chain support to agent daemon and improve fork detection logging
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 5s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 11s
Deploy to Testnet / deploy-testnet (push) Successful in 1m42s
Integration Tests / test-service-integration (push) Successful in 2m41s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 2s
Multi-Node Stress Testing / stress-test (push) Successful in 3s
Node Failover Simulation / failover-test (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 3s
Production Tests / Production Integration Tests (push) Successful in 23s
Python Tests / test-python (push) Successful in 33s
Security Scanning / security-scan (push) Successful in 48s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 5s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 11s
Deploy to Testnet / deploy-testnet (push) Successful in 1m42s
Integration Tests / test-service-integration (push) Successful in 2m41s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 2s
Multi-Node Stress Testing / stress-test (push) Successful in 3s
Node Failover Simulation / failover-test (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 3s
Production Tests / Production Integration Tests (push) Successful in 23s
Python Tests / test-python (push) Successful in 33s
Security Scanning / security-scan (push) Successful in 48s
- Add chain_id parameter to agent daemon with default "ait-mainnet" - Filter transactions by chain_id in daemon polling - Update agent daemon wrapper to support multiple chains via AGENT_DAEMON_CHAINS env var - Add chain_id validation in fork detection to reject incompatible chains - Improve logging in sync module with more detailed fork and import failure messages
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Wrapper script for aitbc-agent-daemon service
|
||||
Uses centralized aitbc utilities for path configuration
|
||||
Supports multichain by spawning daemon instances for each configured chain
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
# Add aitbc to path
|
||||
@@ -21,18 +22,62 @@ os.environ["PYTHONPATH"] = f"{REPO_DIR}:{REPO_DIR}/packages/py/aitbc-agent-sdk/s
|
||||
os.environ["DATA_DIR"] = str(DATA_DIR)
|
||||
os.environ["LOG_DIR"] = str(LOG_DIR)
|
||||
|
||||
# Execute the actual service
|
||||
exec_cmd = [
|
||||
"/opt/aitbc/venv/bin/python",
|
||||
f"{REPO_DIR}/apps/agent-coordinator/scripts/agent_daemon.py",
|
||||
# Get chain configuration from environment
|
||||
# Support both single chain (CHAIN_ID) and multiple chains (AGENT_DAEMON_CHAINS)
|
||||
chains_str = os.getenv("AGENT_DAEMON_CHAINS", "")
|
||||
if chains_str:
|
||||
chains = [c.strip() for c in chains_str.split(",")]
|
||||
else:
|
||||
chains = [os.getenv("CHAIN_ID", "ait-mainnet")]
|
||||
|
||||
# Spawn daemon processes for each chain
|
||||
daemon_script = f"{REPO_DIR}/apps/agent-coordinator/scripts/agent_daemon.py"
|
||||
base_args = [
|
||||
"--wallet", "temp-agent",
|
||||
"--address", "ait1d18e286fc0c12888aca94732b5507c8787af71a5",
|
||||
"--password-file", str(KEYSTORE_DIR / ".agent_daemon_password"),
|
||||
"--keystore-dir", str(KEYSTORE_DIR),
|
||||
"--db-path", "/var/lib/aitbc/data/chain.db",
|
||||
"--rpc-url", "http://localhost:8006",
|
||||
"--poll-interval", "2",
|
||||
"--reply-message", "pong",
|
||||
"--trigger-message", "ping"
|
||||
]
|
||||
os.execvp(exec_cmd[0], exec_cmd)
|
||||
|
||||
if len(chains) == 1:
|
||||
# Single chain: exec directly (replaces wrapper process)
|
||||
chain_id = chains[0]
|
||||
db_path = f"/var/lib/aitbc/data/{chain_id}/chain.db"
|
||||
exec_cmd = [
|
||||
"/opt/aitbc/venv/bin/python",
|
||||
daemon_script,
|
||||
*base_args,
|
||||
"--db-path", db_path,
|
||||
"--chain-id", chain_id
|
||||
]
|
||||
os.execvp(exec_cmd[0], exec_cmd)
|
||||
else:
|
||||
# Multiple chains: spawn subprocesses and wait
|
||||
processes = []
|
||||
for chain_id in chains:
|
||||
db_path = f"/var/lib/aitbc/data/{chain_id}/chain.db"
|
||||
cmd = [
|
||||
"/opt/aitbc/venv/bin/python",
|
||||
daemon_script,
|
||||
*base_args,
|
||||
"--db-path", db_path,
|
||||
"--chain-id", chain_id
|
||||
]
|
||||
print(f"Starting agent daemon for chain: {chain_id}")
|
||||
proc = subprocess.Popen(cmd)
|
||||
processes.append(proc)
|
||||
|
||||
# Wait for all processes
|
||||
try:
|
||||
for proc in processes:
|
||||
proc.wait()
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down agent daemons...")
|
||||
for proc in processes:
|
||||
proc.terminate()
|
||||
for proc in processes:
|
||||
proc.wait()
|
||||
|
||||
Reference in New Issue
Block a user