Skip to content

Fix pick_winner crash on empty lottery pool#9

Open
sueun-dev wants to merge 1 commit intocsunny:masterfrom
sueun-dev:fix-pick-winner-empty-lottery-pool
Open

Fix pick_winner crash on empty lottery pool#9
sueun-dev wants to merge 1 commit intocsunny:masterfrom
sueun-dev:fix-pick-winner-empty-lottery-pool

Conversation

@sueun-dev
Copy link

Closes #8

This change prevents pick_winner from crashing when candidate blocks exist but no validator has positive stake. It now skips that round safely.

Step Before fix After fix
Reproduction command env PYTHONPATH=src .venv/bin/python repro_pick_winner.py (inline script used below) same command
Key output task_done= True, task_exception= IndexError('list index out of range') task_done= False, task_exception= None
Test result Manual reproduction shows crash (fail) sandbox-exec -f /tmp/no-network.sb env PYTHONPATH=src .venv/bin/pytest -q -> 2 passed (pass)

Reproduction script used:

import asyncio
from p2p import peer

async def main():
    peer.validators.clear()
    peer.tempblocks.clear()
    peer.tempblocks.append({"Validator": "missing", "Index": 1, "BPM": 60, "Timestamp": "t", "PrevHash": "h", "Hash": "h2"})
    q = asyncio.Queue()
    t = asyncio.create_task(peer.pick_winner(q))
    await asyncio.sleep(1.2)
    print('task_done=', t.done())
    print('task_exception=', repr(t.exception()) if t.done() else None)

asyncio.run(main())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pick_winner crashes when no validator has stake

1 participant