fix: Query PoA validators for blockchain state instead of local blockchain

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 <noreply@anthropic.com>
This commit is contained in:
Alexis Bruneteau 2025-11-07 16:53:14 +01:00
parent 64ad1e9fb6
commit 8be804f7c6

View File

@ -480,6 +480,7 @@ async def get_blockchain(
Récupérer l'état complet de la blockchain pour une élection. Récupérer l'état complet de la blockchain pour une élection.
Retourne tous les blocs et l'état de vérification. 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 # Vérifier que l'élection existe
election = services.ElectionService.get_election(db, election_id) election = services.ElectionService.get_election(db, election_id)
@ -489,6 +490,18 @@ async def get_blockchain(
detail="Election not found" 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) blockchain = blockchain_manager.get_or_create_blockchain(election_id)
return blockchain.get_blockchain_data() return blockchain.get_blockchain_data()