debug: Add detailed logging to BlockchainClient for vote submission

Add logging at each stage:
- Context manager entry/exit
- submit_vote() method entry
- Validator selection
- HTTP request details
- Response handling

This will help identify exactly where the vote submission is failing.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alexis Bruneteau 2025-11-07 16:48:19 +01:00
parent 6f43d75155
commit 64ad1e9fb6

View File

@ -84,8 +84,11 @@ class BlockchainClient:
async def __aenter__(self):
"""Async context manager entry"""
logger.info("[BlockchainClient.__aenter__] Creating AsyncClient")
self._client = httpx.AsyncClient(timeout=self.timeout)
logger.info("[BlockchainClient.__aenter__] Refreshing validator status")
await self.refresh_validator_status()
logger.info(f"[BlockchainClient.__aenter__] Ready with {len(self.healthy_validators)} healthy validators")
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
@ -172,10 +175,16 @@ class BlockchainClient:
Raises:
Exception: If all validators are unreachable
"""
logger.info(f"[BlockchainClient.submit_vote] CALLED with voter_id={voter_id}, election_id={election_id}")
logger.info(f"[BlockchainClient.submit_vote] healthy_validators count: {len(self.healthy_validators)}")
validator = self._get_healthy_validator()
if not validator:
logger.error("[BlockchainClient.submit_vote] No healthy validators available!")
raise Exception("No healthy validators available")
logger.info(f"[BlockchainClient.submit_vote] Selected validator: {validator.node_id}")
# Generate transaction ID if not provided
if not transaction_id:
import uuid
@ -215,17 +224,21 @@ class BlockchainClient:
"id": transaction_id
}
logger.info(f"Submitting vote to {validator.node_id}: tx_id={transaction_id}")
logger.info(f"[BlockchainClient.submit_vote] Submitting vote to {validator.node_id}: tx_id={transaction_id}")
logger.info(f"[BlockchainClient.submit_vote] RPC URL: {validator.rpc_url}/rpc")
try:
if not self._client:
logger.error("[BlockchainClient.submit_vote] AsyncClient not initialized!")
raise Exception("AsyncClient not initialized")
logger.info(f"[BlockchainClient.submit_vote] Sending POST request to {validator.rpc_url}/rpc")
response = await self._client.post(
f"{validator.rpc_url}/rpc",
json=rpc_request,
timeout=self.timeout
)
logger.info(f"[BlockchainClient.submit_vote] Response received: status={response.status_code}")
response.raise_for_status()
result = response.json()