fix: disable block production in RPC-only blockchain service
Some checks failed
CLI Tests / test-cli (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Blockchain Synchronization Verification / sync-verification (push) Has been cancelled
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Has been cancelled
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Has been cancelled
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been cancelled
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Has been cancelled
Cross-Chain Functionality Tests / aggregate-results (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Has been cancelled
Multi-Node Blockchain Health Monitoring / health-check (push) Has been cancelled
P2P Network Verification / p2p-verification (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Systemd Sync / sync-systemd (push) Successful in 22s

Prevented RPC service from producing blocks by:
- Added AITBC_FORCE_ENABLE_BLOCK_PRODUCTION environment variable (highest priority)
- Updated _env_value() helper to check multiple env var names in priority order
- Set all block production env vars to false in RPC wrapper script
- Added AITBC_FORCE_ENABLE_BLOCK_PRODUCTION=false to systemd service file
- Fixed CLI get_balance() to use requests library instead of AITBCHTTPClient
- Added 404 handling in
This commit is contained in:
aitbc
2026-05-04 11:05:32 +02:00
parent eb5750a04b
commit 7a0054b53d
4 changed files with 32 additions and 6 deletions

View File

@@ -23,6 +23,14 @@ from .rpc.websocket import router as websocket_router
_app_logger = get_logger("aitbc_chain.app")
def _env_value(*names: str) -> str | None:
for name in names:
value = os.getenv(name)
if value is not None:
return value
return None
class RateLimitMiddleware(BaseHTTPMiddleware):
"""Simple in-memory rate limiter per client IP."""
@@ -105,9 +113,11 @@ async def lifespan(app: FastAPI):
await gossip_broker.set_backend(backend)
_app_logger.info("Gossip backend initialized successfully")
proposers = []
block_production_override = os.getenv("enable_block_production")
if block_production_override is None:
block_production_override = os.getenv("ENABLE_BLOCK_PRODUCTION")
block_production_override = _env_value(
"AITBC_FORCE_ENABLE_BLOCK_PRODUCTION",
"ENABLE_BLOCK_PRODUCTION",
"enable_block_production",
)
block_production_enabled = settings.enable_block_production
if block_production_override is not None:
block_production_enabled = block_production_override.strip().lower() in {"1", "true", "yes", "on"}

View File

@@ -760,15 +760,27 @@ def get_balance(wallet_name: str, rpc_url: str = DEFAULT_RPC_URL, chain_id_overr
# Get account info from RPC
try:
http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30)
account_info = http_client.get(f"/rpc/account/{address}?chain_id={chain_id}")
response = requests.get(
f"{rpc_url.rstrip('/')}/rpc/account/{address}",
params={"chain_id": chain_id},
timeout=10,
)
if response.status_code == 404:
return {
"wallet_name": wallet_name,
"address": address,
"balance": 0,
"nonce": 0
}
response.raise_for_status()
account_info = response.json()
return {
"wallet_name": wallet_name,
"address": address,
"balance": account_info["balance"],
"nonce": account_info["nonce"]
}
except NetworkError as e:
except requests.RequestException as e:
print(f"Error getting balance: {e}")
return None
except Exception as e:

View File

@@ -20,6 +20,9 @@ os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE)
os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-node/src:{REPO_DIR}/apps/blockchain-node/scripts"
os.environ["DATA_DIR"] = str(DATA_DIR)
os.environ["LOG_DIR"] = str(LOG_DIR)
os.environ["AITBC_FORCE_ENABLE_BLOCK_PRODUCTION"] = "false"
os.environ["ENABLE_BLOCK_PRODUCTION"] = "false"
os.environ["enable_block_production"] = "false"
# Get RPC configuration from environment or use defaults
rpc_host = os.getenv("rpc_bind_host", "0.0.0.0")

View File

@@ -12,6 +12,7 @@ ExecStartPre=/opt/aitbc/scripts/utils/load-keystore-secrets.sh
EnvironmentFile=/run/aitbc/secrets/.env
EnvironmentFile=/etc/aitbc/.env
EnvironmentFile=/etc/aitbc/node.env
Environment=AITBC_FORCE_ENABLE_BLOCK_PRODUCTION=false
Environment=enable_block_production=false
ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-rpc-wrapper.py
Restart=always