Skip to content

Extract vote eligibility logic into voting_policy#5044

Merged
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:vote-policy-4
Mar 24, 2026
Merged

Extract vote eligibility logic into voting_policy#5044
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:vote-policy-4

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

Vote eligibility checks were previously scattered across vote_generator and request_aggregator, with each component independently deciding whether a block should receive a normal or final vote. This made it difficult to reason about vote safety as a whole, and easy to introduce inconsistencies when modifying one path but not the other.

This PR introduces a voting_policy class that serves as the single source of truth for all vote eligibility decisions and vote construction. The class exposes three eligibility methods (vote_normal, vote_final, reply_final) and a sign method that constructs and signs votes. A vote_permit type with a private constructor ensures that callers cannot bypass the policy.

The key safety invariants enforced by the policy are: normal votes require all block dependencies to be cemented and refuse to vote if a conflicting final vote record exists for the same root, final votes additionally claim a persistent slot via final_vote.put to prevent double-voting on forks, and the reply path (reply_final) is read-only and returns the recorded hash rather than the queried block's hash to avoid accidentally endorsing a fork during vote replies.

vote_generator and request_aggregator are updated to delegate all eligibility and signing decisions to voting_policy, removing their duplicated logic. The vote construction code that previously lived inside vote_generator::broadcast and vote_generator::reply is now handled by voting_policy::sign.

@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Mar 19, 2026

Test Results for Commit 52346f4

Pull Request 5044: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 120s)
  • 5n4pr_conf_10k_change: PASS (Duration: 134s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 130s)
  • 5n4pr_conf_change_independant: PASS (Duration: 136s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 133s)
  • 5n4pr_conf_send_independant: PASS (Duration: 133s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 123s)
  • 5n4pr_rocks_10k_change: FAIL (Duration: 146s)
  • Log

Last updated: 2026-03-24 16:45:21 UTC

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 centralizes vote eligibility checks and vote construction/signing behind a new nano::voting_policy, replacing duplicated logic previously split across vote_generator and request_aggregator. This improves consistency and makes vote-safety invariants (especially around final_vote and fork-safe replies) easier to reason about.

Changes:

  • Introduces nano::voting_policy and nano::vote_permit to unify normal/final/reply eligibility checks and vote signing.
  • Refactors vote_generator and request_aggregator to delegate eligibility decisions and signing to voting_policy.
  • Adds comprehensive unit tests covering eligibility, fork safety, and signing behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
nano/secure/voting_policy.hpp Declares vote_type, vote_permit, and voting_policy public API for eligibility + signing.
nano/secure/voting_policy.cpp Implements eligibility rules and centralized vote signing logic.
nano/secure/fwd.hpp Adds forward declarations for vote_permit, voting_policy, and vote_type.
nano/secure/CMakeLists.txt Adds new voting policy sources to the secure library target.
nano/node/vote_generator.hpp Updates generator interfaces/types to operate on vote_permit and use voting_policy.
nano/node/vote_generator.cpp Replaces internal eligibility/signing logic with voting_policy calls.
nano/node/request_aggregator.hpp Injects voting_policy dependency.
nano/node/request_aggregator.cpp Uses voting_policy::reply_final to decide final vote reply eligibility.
nano/node/node.hpp Stores/owns a voting_policy instance on the node.
nano/node/node.cpp Constructs/injects voting_policy into vote generators and request aggregator.
nano/core_test/voting_policy.cpp Adds extensive test coverage for eligibility, fork safety, and signing.
nano/core_test/CMakeLists.txt Adds voting_policy.cpp to the core test target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Consolidate vote eligibility checks previously scattered
across vote_generator and request_aggregator into a
dedicated voting_policy class. The vote_permit type ensures
callers cannot bypass the policy check.
@pwojcikdev pwojcikdev merged commit cc768f3 into nanocurrency:develop Mar 24, 2026
27 of 28 checks passed
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.

3 participants