From 64ad1e9fb61e9f7ca6a5c6a8d5319bbb57f5742c Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 7 Nov 2025 16:48:19 +0100 Subject: [PATCH] debug: Add detailed logging to BlockchainClient for vote submission MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- e-voting-system/backend/blockchain_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/e-voting-system/backend/blockchain_client.py b/e-voting-system/backend/blockchain_client.py index 6e50701..74f0926 100644 --- a/e-voting-system/backend/blockchain_client.py +++ b/e-voting-system/backend/blockchain_client.py @@ -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()