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()