From 8be804f7c62c3e3829b28cbbfed5aac587aa7700 Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 7 Nov 2025 16:53:14 +0100 Subject: [PATCH] fix: Query PoA validators for blockchain state instead of local blockchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: The GET /api/votes/blockchain endpoint was returning the local blockchain manager data instead of querying the PoA validators where votes are actually being submitted. This caused votes to appear successfully submitted (with block_hash from validators) but not show up when querying the blockchain state, since the query was hitting the wrong data source. Solution: Update the /blockchain endpoint to: 1. First try to get blockchain state from PoA validators 2. Fall back to local blockchain manager if PoA unavailable 3. Add detailed logging for debugging This ensures the blockchain state matches where votes are actually being stored on the PoA network. 🤖 Generated with Claude Code Co-Authored-By: Claude --- e-voting-system/backend/routes/votes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/e-voting-system/backend/routes/votes.py b/e-voting-system/backend/routes/votes.py index 0422d57..9953b9c 100644 --- a/e-voting-system/backend/routes/votes.py +++ b/e-voting-system/backend/routes/votes.py @@ -480,6 +480,7 @@ async def get_blockchain( Récupérer l'état complet de la blockchain pour une élection. Retourne tous les blocs et l'état de vérification. + Requête d'abord aux validateurs PoA, puis fallback sur blockchain locale. """ # Vérifier que l'élection existe election = services.ElectionService.get_election(db, election_id) @@ -489,6 +490,18 @@ async def get_blockchain( detail="Election not found" ) + # Try to get blockchain state from PoA validators first + try: + async with BlockchainClient() as poa_client: + blockchain_data = await poa_client.get_blockchain_state(election_id) + if blockchain_data: + logger.info(f"Got blockchain state from PoA for election {election_id}") + return blockchain_data + except Exception as e: + logger.warning(f"Failed to get blockchain from PoA: {e}") + + # Fallback to local blockchain manager + logger.info(f"Falling back to local blockchain for election {election_id}") blockchain = blockchain_manager.get_or_create_blockchain(election_id) return blockchain.get_blockchain_data()