Replace hardcoded IPs with environment variables
Fixed hardcoded IP addresses in production code by replacing them with environment variables or config settings: - apps/blockchain-node/src/aitbc_chain/sync_cli.py: Use AITBC_SYNC_SOURCE and AITBC_SYNC_IMPORT_URL env vars for RPC URLs - apps/blockchain-node/src/aitbc_chain/app.py: Use AITBC_TRUSTED_IPS env var for rate limiting bypass - apps/coordinator-api/src/app/routers/client.py: Use settings.blockchain_rpc_url for RPC endpoint - dev/scripts/dev_heartbeat.py: Use AITBC_LOCAL_RPC and AITBC_GENESIS_RPC env vars for RPC URLs - cli/aitbc_cli.py: Use AITBC_FOLLOWER_HOST and AITBC_FOLLOWER_PORT env vars for network peer display This makes the codebase more portable and configurable for different deployment environments.
This commit is contained in:
@@ -35,7 +35,8 @@ class RateLimitMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
client_ip = request.client.host if request.client else "unknown"
|
||||
# Bypass rate limiting for localhost and internal network (sync/health internal traffic)
|
||||
if client_ip in {"127.0.0.1", "::1", "10.1.223.93", "10.1.223.40"}:
|
||||
trusted_ips = os.getenv("AITBC_TRUSTED_IPS", "127.0.0.1,::1").split(",")
|
||||
if client_ip in trusted_ips:
|
||||
return await call_next(request)
|
||||
now = time.time()
|
||||
# Clean old entries
|
||||
|
||||
@@ -6,6 +6,7 @@ Usage: python -m aitbc_chain.sync_cli --source http://10.1.223.40:8006 [--batch-
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -19,8 +20,8 @@ from aitbc_chain.sync import ChainSync
|
||||
|
||||
async def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Bulk import blocks from a leader to catch up quickly")
|
||||
parser.add_argument("--source", default="http://10.1.223.40:8006", help="Source RPC URL")
|
||||
parser.add_argument("--import-url", default="http://127.0.0.1:8006", help="Local RPC URL for import")
|
||||
parser.add_argument("--source", default=os.getenv("AITBC_SYNC_SOURCE", "http://127.0.0.1:8006"), help="Source RPC URL")
|
||||
parser.add_argument("--import-url", default=os.getenv("AITBC_SYNC_IMPORT_URL", "http://127.0.0.1:8006"), help="Local RPC URL for import")
|
||||
parser.add_argument("--batch-size", type=int, default=100, help="Blocks per batch")
|
||||
parser.add_argument("--poll-interval", type=float, default=0.2, help="Seconds between batches")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -230,7 +230,7 @@ async def get_blocks(
|
||||
client = AITBCHTTPClient(timeout=5.0)
|
||||
try:
|
||||
blocks_data = client.get(
|
||||
"http://10.1.223.93:8082/rpc/blocks-range", params={"start": offset, "end": offset + limit}
|
||||
f"{settings.blockchain_rpc_url}/rpc/blocks-range", params={"start": offset, "end": offset + limit}
|
||||
)
|
||||
return {
|
||||
"blocks": blocks_data.get("blocks", []),
|
||||
|
||||
@@ -2849,7 +2849,9 @@ def legacy_main():
|
||||
elif args.network_action == "peers":
|
||||
print("Network peers:")
|
||||
print(" - genesis (localhost:8006) - Connected")
|
||||
print(" - aitbc1 (10.1.223.40:8007) - Connected")
|
||||
follower_host = os.getenv("AITBC_FOLLOWER_HOST", "aitbc1")
|
||||
follower_port = os.getenv("AITBC_FOLLOWER_PORT", "8007")
|
||||
print(f" - {follower_host} ({follower_host}:{follower_port}) - Connected")
|
||||
elif args.network_action == "sync":
|
||||
if args.status:
|
||||
print("Network sync status:")
|
||||
|
||||
@@ -14,8 +14,8 @@ REPO_ROOT = Path("/opt/aitbc")
|
||||
LOGS_DIR = REPO_ROOT / "logs"
|
||||
|
||||
# AITBC blockchain config
|
||||
LOCAL_RPC = "http://localhost:8006"
|
||||
GENESIS_RPC = "http://10.1.223.93:8006"
|
||||
LOCAL_RPC = os.getenv("AITBC_LOCAL_RPC", "http://localhost:8006")
|
||||
GENESIS_RPC = os.getenv("AITBC_GENESIS_RPC", "http://localhost:8006")
|
||||
MAX_HEIGHT_DIFF = 10 # acceptable block height difference between nodes
|
||||
|
||||
def sh(cmd, cwd=REPO_ROOT):
|
||||
|
||||
Reference in New Issue
Block a user