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
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
Combined blockchain node and P2P service launcher
|
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
|
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.main import BlockchainNode, _run as run_node
|
||||||
from aitbc_chain.config import settings
|
from aitbc_chain.config import settings
|
||||||
|
from aitbc_chain.app import create_app
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -21,20 +23,35 @@ logger = logging.getLogger(__name__)
|
|||||||
class CombinedService:
|
class CombinedService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._tasks = []
|
self._tasks = []
|
||||||
|
self._http_server = None
|
||||||
|
|
||||||
async def start(self):
|
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")
|
logger.info("Starting combined blockchain service")
|
||||||
|
|
||||||
# Start blockchain node in background
|
# Start blockchain node in background
|
||||||
node_task = asyncio.create_task(run_node())
|
node_task = asyncio.create_task(run_node())
|
||||||
self._tasks.append(node_task)
|
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:
|
try:
|
||||||
# Wait for the node task to complete
|
# Wait for any task to complete (should not happen in normal operation)
|
||||||
await node_task
|
await asyncio.gather(*self._tasks, return_exceptions=True)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info("Received keyboard interrupt")
|
||||||
finally:
|
finally:
|
||||||
await self.stop()
|
await self.stop()
|
||||||
|
|
||||||
@@ -42,6 +59,10 @@ class CombinedService:
|
|||||||
"""Stop all services"""
|
"""Stop all services"""
|
||||||
logger.info("Stopping combined blockchain service")
|
logger.info("Stopping combined blockchain service")
|
||||||
|
|
||||||
|
# Shutdown HTTP server if running
|
||||||
|
if self._http_server:
|
||||||
|
self._http_server.should_exit = True
|
||||||
|
|
||||||
# Cancel all tasks
|
# Cancel all tasks
|
||||||
for task in self._tasks:
|
for task in self._tasks:
|
||||||
if not task.done():
|
if not task.done():
|
||||||
|
|||||||
Reference in New Issue
Block a user