docs: Add voting setup troubleshooting guide
Documents the issue where elections are missing ElGamal encryption parameters which are required for the voting system to work. Provides 3 options to fix: 1. Database SQL update 2. Adminer UI 3. Fresh database reset Explains root cause and how to verify the fix worked.
This commit is contained in:
parent
d9b6b66813
commit
5652ff2c8a
136
e-voting-system/VOTING_SETUP_ISSUE.md
Normal file
136
e-voting-system/VOTING_SETUP_ISSUE.md
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
# Voting Setup Issue - Solution
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
|
||||||
|
Users cannot vote because:
|
||||||
|
1. Elections don't have ElGamal encryption keys (`elgamal_p`, `elgamal_g`)
|
||||||
|
2. The voting interface fails when trying to get public keys
|
||||||
|
|
||||||
|
## Root Cause
|
||||||
|
|
||||||
|
The database initialization script `docker/create_active_election.sql` didn't set the ElGamal parameters, even though the init.sql had `elgamal_p = 23, elgamal_g = 5`.
|
||||||
|
|
||||||
|
## Fix
|
||||||
|
|
||||||
|
### Option 1: Fix via Database (Recommended)
|
||||||
|
|
||||||
|
Connect to the database and update the elections with ElGamal parameters:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Connect to MariaDB
|
||||||
|
docker compose exec mariadb mariadb -u evoting_user -pevoting_pass123 evoting_db
|
||||||
|
|
||||||
|
# Run this SQL:
|
||||||
|
UPDATE elections SET elgamal_p = 23, elgamal_g = 5;
|
||||||
|
|
||||||
|
# Verify:
|
||||||
|
SELECT id, name, elgamal_p, elgamal_g FROM elections LIMIT 5;
|
||||||
|
|
||||||
|
# Exit
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 2: Use Adminer UI
|
||||||
|
|
||||||
|
1. Go to http://localhost:8081
|
||||||
|
2. Login:
|
||||||
|
- Server: `mariadb`
|
||||||
|
- User: `evoting_user`
|
||||||
|
- Password: `evoting_pass123`
|
||||||
|
- Database: `evoting_db`
|
||||||
|
3. Click on `elections` table
|
||||||
|
4. Edit each row and set:
|
||||||
|
- `elgamal_p` = 23
|
||||||
|
- `elgamal_g` = 5
|
||||||
|
|
||||||
|
### Option 3: Fresh Database Reset
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop and remove all data
|
||||||
|
docker compose down -v
|
||||||
|
|
||||||
|
# Start fresh
|
||||||
|
docker compose -f docker-compose.multinode.yml up -d
|
||||||
|
|
||||||
|
# Wait 40 seconds for initialization
|
||||||
|
sleep 40
|
||||||
|
|
||||||
|
# Verify elections have keys
|
||||||
|
curl http://localhost:8000/api/elections/debug/all | jq '.elections[0] | {id, name, elgamal_p, elgamal_g}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verify Fix Worked
|
||||||
|
|
||||||
|
After fixing, test:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check election keys are set
|
||||||
|
curl http://localhost:8000/api/elections/debug/all | jq '.elections[0] | {id, name, elgamal_p, elgamal_g}'
|
||||||
|
|
||||||
|
# Should show:
|
||||||
|
# {
|
||||||
|
# "id": 1,
|
||||||
|
# "name": "...",
|
||||||
|
# "elgamal_p": 23,
|
||||||
|
# "elgamal_g": 5
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Get public keys (should work now)
|
||||||
|
curl http://localhost:8000/api/votes/public-keys?election_id=1 | jq '.'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Why This Happened
|
||||||
|
|
||||||
|
The SQL scripts do this:
|
||||||
|
1. `docker/init.sql` - Creates elections with `elgamal_p = 23, elgamal_g = 5`
|
||||||
|
2. `docker/populate_past_elections.sql` - Inserts past elections (no ElGamal params)
|
||||||
|
3. `docker/create_active_election.sql` - **Updates** election 1 but lost the ElGamal params
|
||||||
|
|
||||||
|
The UPDATE statement in step 3 didn't preserve the ElGamal parameters. They should be:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
UPDATE elections
|
||||||
|
SET
|
||||||
|
is_active = TRUE,
|
||||||
|
start_date = DATE_SUB(NOW(), INTERVAL 1 HOUR),
|
||||||
|
end_date = DATE_ADD(NOW(), INTERVAL 7 DAY),
|
||||||
|
elgamal_p = 23,
|
||||||
|
elgamal_g = 5
|
||||||
|
WHERE id = 1;
|
||||||
|
```
|
||||||
|
|
||||||
|
## After Fix
|
||||||
|
|
||||||
|
Once elections have ElGamal keys:
|
||||||
|
|
||||||
|
1. Users can register normally
|
||||||
|
2. Users can see active elections
|
||||||
|
3. Frontend can fetch public keys for voting
|
||||||
|
4. Encrypted voting works
|
||||||
|
5. Blockchain records votes
|
||||||
|
|
||||||
|
## Testing After Fix
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Check keys are set
|
||||||
|
curl http://localhost:8000/api/votes/public-keys?election_id=1
|
||||||
|
|
||||||
|
# 2. Open frontend
|
||||||
|
http://localhost:3000
|
||||||
|
|
||||||
|
# 3. Register (if needed)
|
||||||
|
# 4. Login
|
||||||
|
# 5. Click "Participer" on an election
|
||||||
|
# 6. Select a candidate
|
||||||
|
# 7. Submit vote
|
||||||
|
|
||||||
|
# Should see success message with transaction ID
|
||||||
|
```
|
||||||
|
|
||||||
|
## If Still Not Working
|
||||||
|
|
||||||
|
1. Clear browser cache (Ctrl+Shift+Delete)
|
||||||
|
2. Restart frontend container: `docker compose restart frontend`
|
||||||
|
3. Rebuild frontend if config changed: `docker compose up -d --build frontend`
|
||||||
|
4. Check backend logs: `docker compose logs backend | grep -i error`
|
||||||
|
5. Check browser console for errors (F12)
|
||||||
Loading…
x
Reference in New Issue
Block a user