Skip to content

pick_winner crashes when no validator has stake #8

@sueun-dev

Description

@sueun-dev

When a candidate block is present but no validator has a positive stake entry, the lottery pool is empty and pick_winner crashes.

Reproduction:

env PYTHONPATH=src .venv/bin/python - <<'PY'
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()))

asyncio.run(main())
PY

Observed output:

  • task_done= True
  • task_exception= IndexError('list index out of range')

Expected behavior:

  • The round should be skipped safely when no eligible validator exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions