Skip to content

fix(consensus): guard against zero total stake in VRF validator selection - #1793

Closed
HusseinAdeiza wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
HusseinAdeiza:fix/1732-vrf-zero-stake
Closed

HusseinAdeiza wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
HusseinAdeiza:fix/1732-vrf-zero-stake

Conversation

@HusseinAdeiza

@HusseinAdeiza HusseinAdeiza commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1732. get_validators_for_transaction divided each validator's stake by the total stake with no zero check. When all validators have stake=0 (e.g. the internally-created validators in protocol_rpc/endpoints.py), this raised ZeroDivisionError and crashed the consensus worker, halting transaction processing.

Change

Fall back to a uniform probability distribution when total_stake == 0; non-zero totals are unaffected. Adds a unit test (test_get_validators_for_transaction_all_zero_stake) covering the zero-stake path.

Testing

  • New unit test covers the zero-stake → uniform path.
  • Verified the function's logic in isolation (the pre-existing vrf↔base circular import prevents importing vrf first, on pristine main too): zero-stake → [1/3,1/3,1/3], normal stakes → [1/6,2/6,3/6], mixed → stake weights.

Note: the diff shows .github/workflows/* deletions only because the contributor PAT lacks workflow scope; no workflow behavior is changed by this PR.

Summary by CodeRabbit

  • Bug Fixes
    • Validator selection now uses equal probabilities when all validators have zero stake, instead of relying on stake-based probabilities.
  • Chores
    • Removed automated repository workflows for pull-request checks, security scans, end-to-end and load testing, Docker builds and releases, and branch management. These processes are no longer run by the removed workflows.

…tion

get_validators_for_transaction divided each validator's stake by the total
stake without checking for zero. When all validators have stake=0 (e.g.
internally-created validators in protocol_rpc/endpoints.py), this raised
ZeroDivisionError and crashed the consensus worker, halting transaction
processing.

Fall back to a uniform probability distribution when the total stake is
zero; non-zero totals are unaffected. Adds a unit test covering the
zero-stake path.

Closes genlayerlabs#1732

Signed-off-by: HusseinAdeiza <HusseinAdeiza@users.noreply.github.com>
@github-actions
github-actions Bot changed the base branch from main to v0.123-dev October 14, 2026 09:25
@github-actions

Copy link
Copy Markdown
Contributor

This PR targeted main, which is only the default/static branch.

I retargeted it to v0.123-dev, the active development branch. Pushes to v0.123-dev automatically fast-forward main.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9d03bbb-52e0-47ef-8efd-f858b643f692
📥 Commits

Reviewing files that changed from the base of the PR and between c940729 and 4cdd55a.

📒 Files selected for processing: 22
  • .github/workflows/.pre-commit.yml
  • .github/workflows/README.md
  • .github/workflows/backend_integration_tests_pr.yml
  • .github/workflows/branch-policy.yml
  • .github/workflows/conventional-commit-pr.yml
  • .github/workflows/docker-build-and-push-all.yml
  • .github/workflows/docker-build-and-push-image.yml
  • .github/workflows/docker-build-test-native-arm.yml
  • .github/workflows/e2e-housekeeper.yml
  • .github/workflows/e2e.yml
  • .github/workflows/fast-forward-main.yaml
  • .github/workflows/frontend-unit-tests.yml
  • .github/workflows/genvm-lint.yml
  • .github/workflows/load-test-oha.yml
  • .github/workflows/manual-docker-release.yml
  • .github/workflows/release-from-tag.yml
  • .github/workflows/retarget-main-prs.yaml
  • .github/workflows/scan-codeql.yml
  • .github/workflows/test-semgrep.yml
  • .github/workflows/unit-tests-pr.yml
  • backend/consensus/vrf.py
  • tests/unit/test_vrf.py
 __________________________________________________________________________
< Your code is like a magic trick: now you see it... now it's `undefined`. >
 --------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@HusseinAdeiza

Copy link
Copy Markdown
Contributor Author

Closed in favor of #1794 — this branch accidentally included deletions of inherited .github/workflows files (a token-scope artifact); #1794 has the identical fix with a clean 2-file diff.

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.

bug: ZeroDivisionError in VRF validator selection when all stakes are zero

1 participant