Fix RPC server startup in blockchain node service
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Integration Tests / test-service-integration (push) Failing after 9s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 26s
Security Scanning / security-scan (push) Failing after 44s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 10s
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Integration Tests / test-service-integration (push) Failing after 9s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 26s
Security Scanning / security-scan (push) Failing after 44s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 10s
- Modify combined_main.py to start HTTP RPC server alongside blockchain node - Use uvicorn.Server with asyncio to run both services concurrently - Fix shutdown code to properly stop HTTP server - eth_getLogs endpoint now accessible at http://localhost:8006/rpc/eth_getLogs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Combined blockchain node and P2P service launcher
|
||||
Runs both the main blockchain node and P2P placeholder service
|
||||
Runs both the main blockchain node, P2P placeholder service, and HTTP RPC server
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -14,6 +14,8 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from aitbc_chain.main import BlockchainNode, _run as run_node
|
||||
from aitbc_chain.config import settings
|
||||
from aitbc_chain.app import create_app
|
||||
import uvicorn
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -21,20 +23,35 @@ logger = logging.getLogger(__name__)
|
||||
class CombinedService:
|
||||
def __init__(self):
|
||||
self._tasks = []
|
||||
self._http_server = None
|
||||
|
||||
async def start(self):
|
||||
"""Start both blockchain node and P2P server"""
|
||||
"""Start both blockchain node and HTTP RPC server"""
|
||||
logger.info("Starting combined blockchain service")
|
||||
|
||||
# Start blockchain node in background
|
||||
node_task = asyncio.create_task(run_node())
|
||||
self._tasks.append(node_task)
|
||||
|
||||
logger.info(f"Combined service started - Node on mainnet")
|
||||
# Start HTTP RPC server in background
|
||||
app = create_app()
|
||||
config = uvicorn.Config(
|
||||
app,
|
||||
host="0.0.0.0",
|
||||
port=8006,
|
||||
log_level="info"
|
||||
)
|
||||
self._http_server = uvicorn.Server(config)
|
||||
http_task = asyncio.create_task(self._http_server.serve())
|
||||
self._tasks.append(http_task)
|
||||
|
||||
logger.info("Combined service started - Node on mainnet, RPC server on port 8006")
|
||||
|
||||
try:
|
||||
# Wait for the node task to complete
|
||||
await node_task
|
||||
# Wait for any task to complete (should not happen in normal operation)
|
||||
await asyncio.gather(*self._tasks, return_exceptions=True)
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Received keyboard interrupt")
|
||||
finally:
|
||||
await self.stop()
|
||||
|
||||
@@ -42,6 +59,10 @@ class CombinedService:
|
||||
"""Stop all services"""
|
||||
logger.info("Stopping combined blockchain service")
|
||||
|
||||
# Shutdown HTTP server if running
|
||||
if self._http_server:
|
||||
self._http_server.should_exit = True
|
||||
|
||||
# Cancel all tasks
|
||||
for task in self._tasks:
|
||||
if not task.done():
|
||||
|
||||
Reference in New Issue
Block a user