Skip to content

Re-enable voting power check in tally votes#409

Merged
Raneet10 merged 21 commits intodevelopfrom
raneet10/fix-vote-tally
Aug 8, 2025
Merged

Re-enable voting power check in tally votes#409
Raneet10 merged 21 commits intodevelopfrom
raneet10/fix-vote-tally

Conversation

@Raneet10
Copy link
Copy Markdown
Contributor

Description

This PR re-enables the clause to verify the voting power coming from the vote extensions doesn't exceed the total power of the validator set (stored in stake module) in tallyVotes. Since CometBFT takes 2 heights for validator set changes to take effect, heimdall needs to keep track of the penultimate valset to tally correctly.

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

Checklist

  • I have added at least two reviewers or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments — if any — by pushing each fix in a separate commit and linking the commit hash in the comment reply

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on the local environment
  • I have tested this code manually on a remote devnet using express-cli
  • I have tested this code manually on amoy/mumbai
  • I have created new e2e tests into express-cli

@pratikspatil024
Copy link
Copy Markdown
Member

Lets also uncomment and fix the failed to get validator issue in this PR?

@Raneet10 Raneet10 force-pushed the raneet10/fix-vote-tally branch from 239bd77 to 3d3f132 Compare July 31, 2025 05:09
@avalkov avalkov requested a review from Copilot August 1, 2025 13:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR re-enables voting power validation in the tallyVotes function by implementing proper validator set tracking to handle CometBFT's 2-block delay for validator set changes. The fix addresses a bug where voting power validation was disabled due to validator set synchronization issues.

Key changes:

  • Adds tracking of the penultimate (2 blocks ago) validator set to handle CometBFT's validator set change propagation delay
  • Re-enables voting power checks in tallyVotes with configurable height-based logic
  • Updates vote extension validation to use the appropriate validator set based on block height
  • Introduces height-based flags to control when validator checks should be enabled/disabled

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
x/stake/types/keys.go Adds key for storing penultimate block validator set
x/stake/keeper/validator.go Implements penultimate validator set storage and retrieval functions
x/stake/keeper/abci.go Updates EndBlocker to use SDK context for validator set updates
x/milestone/abci/abci.go Adds context parameter and conditional validator validation logic
x/milestone/abci/abci_test.go Updates test to provide required context parameter
x/chainmanager/types/keys.go Adds key for storing initial chain height
x/chainmanager/keeper/keeper.go Implements initial chain height storage and retrieval
x/chainmanager/keeper/genesis.go Sets initial chain height during genesis
helper/config.go Adds configuration for tally fix and validator check heights
bridge/broadcaster/broadcaster_test.go Sets chain configuration for test
app/vote_ext_utils_test.go Updates tests to use validator set instead of keeper
app/vote_ext_utils.go Refactors to use validator set parameter and re-enables voting power checks
app/abci_test.go Sets initial chain height for tests
app/abci.go Implements validator set selection logic based on block height

@Raneet10 Raneet10 requested a review from marcello33 August 4, 2025 10:04
Copy link
Copy Markdown
Contributor

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀🚀🚀

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 8, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@kamuikatsurgi kamuikatsurgi added the squash merge Use squash merge to merge this PR. label Aug 8, 2025
@kamuikatsurgi
Copy link
Copy Markdown
Member

Squash merge please.

@Raneet10 Raneet10 merged commit 2a50441 into develop Aug 8, 2025
10 of 11 checks passed
@Raneet10 Raneet10 deleted the raneet10/fix-vote-tally branch August 8, 2025 13:30
@marcello33 marcello33 restored the raneet10/fix-vote-tally branch August 21, 2025 11:15
marcello33 added a commit that referenced this pull request Sep 2, 2025
* Delete spans backfill

* Always vote NO on spans backfill

* Return type assertion for MsgBackfillSpan

* Merge pull request #413 from 0xPolygon/kamui/bump-kurtosis

chore: remove validator test case and bump kurtosis

* chore: side msg and abci handler metrics (#410)

* chore: add side msg metrics

* timer metrics for Pre, Begin, and End blocker funcs

* chore: nits

* abci handler metrics

* chore: use Namespace from metrics package

* misc: migrated from maticnetwork to 0xPolygon (#420)

* misc: migrated from maticnetwork to 0xPolygon

* misc: bump cosmos to v0.2.3-polygon

* misc: bump bor

* misc: addressed comments

* chore: bump kurtosis (#422)

* chore: bump kurtosis

* chore: add milestones test

* fix: test case name

* chore: update test_runner image

* Re-enable voting power check in tally votes (#409)

* app,helper,x/stake: add logic to store penultimate valset

* app: use correct valset in ValidateVoteExtensions

* app: fix if condition

* app: add condition for genesis

* app,x/chainmanager: track initial chain height for UTs

* app,helper,x/milestone: re-enable skipped validator not found errors

* app: fix some tests and refactor a bit

* app,bridge: fix more tests

* app,x/milestone: some cleanup

* app: dedup redundant stubs

* app: more cleanup

* app,helper,x/chainmanager: move setting of initial height outside of x/chainmanager

* app: improved error logging

* app,x/chainmanager: rm unused key + minor nit

* app: deterministically extract max hash and VP from non-rp VE

* x/stake: fix lint

* helper: refactoring

* app: add comment

* bump go to 1.24.6

* helper: rm unnecessary todo

* fix: build (#423)

* Fix generate-keystore command (#424)

* cmd: allow generate-keystore to accept private key

* cmd: add --generate-new flag

* update: cosmos-sdk (#425)

* helper: fix conflicts

* feat: bump kurtosis and migrate to pos-workflows (#431)

* feat: remove matic-cli e2e-tests (#432)

* bridge: improvements / app: improvements (#427)

* improve bridge, remove bridge cli, minor fixes

* validate bor_chain_id in checkpoints flow

* test fee-transfer events emissions

* remove test block

* logs on rest server being unresponsive

* improve initRootCmd

* don't return on ctx done / restServerTimeOutInMinutes to 1m for tests

* improve logs / restore restServerTimeOutInMinutes

* sort imports

* fix comment

* fix tests and linter issues

* bump cosmos-sdk dep

* move const outside of the func

* refactor StartWithCtx function

* address comments

* log anomaly if account not found with node being in sync

* Set voting power and valset check heights for amoy (#435)

* helper: set tallyFixHeight and disableVPCheckHeight for amoy

* helper: set disableValSetCheckHeight for amoy

* helper: set initialHeight for amoy

* api,proto,x/stake: add penultimate valset to genesis export + add some tests (#436)

* set tallyfix mainnet hf heights

---------

Co-authored-by: Angel Valkov <avalkov@polygon.technology>
Co-authored-by: Krishang Shah <109511742+kamuikatsurgi@users.noreply.github.com>
Co-authored-by: Pratik Patil <pratikspatil024@gmail.com>
Co-authored-by: Raneet Debnath <35629432+Raneet10@users.noreply.github.com>
Co-authored-by: Raneet Debnath <raneetdebnath10@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squash merge Use squash merge to merge this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants