Files
aitbc/cli/commands/sync.py
aitbc 13371bd2e8 fix: update CLI default RPC port from 8006 to 8005
Fixed CLI blockchain connection timeout errors by updating default RPC URL
from port 8006 to port 8005 across all CLI modules.

Root cause:
- Port 8006 is for blockchain P2P protocol (not HTTP RPC)
- Port 8005 is the HTTP RPC API port
- CLI was trying to use HTTP on port 8006, causing timeouts

Updated files:
- cli/advanced_wallet.py: DEFAULT_RPC_URL
- cli/enterprise_cli.py: DEFAULT_RPC_URL
- cli/commands/blockchain.py: _get_node_endpoint()
- cli/core/main.py: default_rpc_url
- cli/commands/sync.py: source and import-url defaults
- cli/commands/marketplace.py: rpc_url config default
- cli/commands/blockchain_event_bridge.py: test mode config
- cli/handlers/bridge.py: test mode config
- cli/commands/deployment.py: service endpoints

This fixes the training script errors where CLI commands were timing out
when trying to connect to the blockchain node.
2026-05-04 09:14:46 +02:00

60 lines
2.0 KiB
Python

"""Sync management commands for AITBC."""
import asyncio
import os
import sys
from pathlib import Path
import click
from utils import success, error, run_subprocess
@click.group()
def sync():
"""Blockchain synchronization utilities."""
pass
@sync.command()
@click.option('--source', default=lambda: os.getenv('AITBC_SYNC_SOURCE_URL', 'http://127.0.0.1:8005'), help='Source RPC URL (leader)')
@click.option('--import-url', default='http://127.0.0.1:8005', help='Local RPC URL for import')
@click.option('--batch-size', type=int, default=100, help='Blocks per batch')
@click.option('--poll-interval', type=float, default=0.2, help='Seconds between batches')
def bulk(source, import_url, batch_size, poll_interval):
"""Bulk import blocks from a leader to catch up quickly."""
try:
# Resolve paths
blockchain_dir = Path(__file__).resolve().parents[3] / 'apps' / 'blockchain-node'
src_dir = blockchain_dir / 'src'
venv_python = blockchain_dir / '.venv' / 'bin' / 'python3'
sync_cli = src_dir / 'aitbc_chain' / 'sync_cli.py'
if not sync_cli.exists():
error("sync_cli.py not found. Ensure bulk sync feature is deployed.")
raise click.Abort()
cmd = [
str(venv_python),
str(sync_cli),
'--source', source,
'--import-url', import_url,
'--batch-size', str(batch_size),
'--poll-interval', str(poll_interval),
]
# Prepare environment
env = {
'PYTHONPATH': str(src_dir),
}
success(f"Running bulk sync from {source} to {import_url} (batch size: {batch_size})")
result = run_subprocess(cmd, env=env, capture_output=False)
if result.returncode != 0:
error("Bulk sync failed. Check logs for details.")
raise click.Abort()
success("Bulk sync completed.")
except Exception as e:
error(f"Error during bulk sync: {e}")
raise click.Abort()