Vote generator rework#5054
Conversation
Test Results for Commit 2c95091Pull Request 5054: Results Test Case Results
Last updated: 2026-03-31 21:32:01 UTC |
69fbfc8 to
1ac0e39
Compare
Introduce a configurable channel type and traits-based alive check for fair_queue. Add null_channel as the default, move transport-specific logic into fair_queue_traits, and update queue users and tests to pass transport channels explicitly.
When a final vote already exists for a qualified root, return a final vote permit for the recorded hash instead of rejecting the vote. This keeps normal vote eligibility aligned with the ledger's existing final vote state.
1ac0e39 to
2f907c3
Compare
There was a problem hiding this comment.
Pull request overview
This PR reworks vote generation to unify normal/final vote paths into a single pipeline with fair-queued request ingestion, batched verification, and capacity-aware broadcasting, reducing duplicated logic and adding backpressure awareness during vote flooding.
Changes:
- Consolidates normal and final vote generation into one
nano::vote_generatorwith separate verifier and broadcaster stages. - Updates
voting_policyto provide a unifiedvote()eligibility check that can upgrade normal requests to final when a final vote is already recorded. - Generalizes
fair_queueto use channel traits (instead of hard-codingtransport::channel) and updates call sites/tests accordingly.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| nano/secure/voting_policy.hpp | Adds vote_permit::dummy() for tests; replaces vote_normal() with unified vote() API. |
| nano/secure/voting_policy.cpp | Implements vote_permit::dummy() and voting_policy::vote() upgrade-to-final logic. |
| nano/node/vote_replier.hpp | Updates fair-queue include and instantiation to new channel-traits form. |
| nano/node/vote_processor.hpp | Updates fair-queue include and instantiation to new channel-traits form. |
| nano/node/vote_generator.hpp | Introduces new vote-generator pipeline classes (index/verifier/broadcaster) and unified generator API. |
| nano/node/vote_generator.cpp | Implements unified vote generator, staged threading, dedup indices, and capacity-gated broadcasting. |
| nano/node/transport/traffic_type.hpp | Adds vote_normal / vote_final traffic types for capacity and stats differentiation. |
| nano/node/node.hpp | Replaces separate generator members with a single vote_generator. |
| nano/node/node.cpp | Wires up unified vote_generator lifecycle and container info reporting. |
| nano/node/network.hpp | Extends vote flooding APIs to accept an optional traffic_type. |
| nano/node/network.cpp | Applies traffic_type to PR/non-PR vote flooding selection logic. |
| nano/node/message_processor.hpp | Updates fair-queue include and instantiation to new channel-traits form. |
| nano/node/fair_queue.hpp | Generalizes queue origin to support arbitrary channel types via fair_queue_traits. |
| nano/node/fair_queue_traits.hpp | Adds fair_queue_traits specialization for shared_ptr<transport::channel> liveness checks. |
| nano/node/election.hpp | Adds balance-bucket parameter/state to elections for upstream vote generator bucketing. |
| nano/node/election.cpp | Routes election vote broadcasts through unified generator and passes along bucket index. |
| nano/node/bootstrap/bootstrap_server.hpp | Updates fair-queue include and instantiation to new channel-traits form. |
| nano/node/block_processor.hpp | Updates fair-queue include and instantiation to new channel-traits form. |
| nano/node/active_elections.cpp | Passes bucket index into election construction. |
| nano/lib/thread_roles.hpp | Splits voting thread roles into normal/final processing vs broadcast roles. |
| nano/lib/thread_roles.cpp | Adds string mappings for new voting thread role names. |
| nano/lib/stats_enums.hpp | Adds stat detail enums for vote_normal / vote_final traffic types. |
| nano/lib/locks.hpp | Adds shared_locked<T> for safe shared ownership of locked<T> in callbacks/tests. |
| nano/core_test/voting.cpp | Removes/moves vote-generator tests and drops vote-spacing integration tests. |
| nano/core_test/voting_policy.cpp | Updates tests for voting_policy::vote() and adds upgrade-to-final coverage. |
| nano/core_test/vote_generator.cpp | Adds new unit tests for generator indices, verifier/broadcaster threading, and generator behavior. |
| nano/core_test/node.cpp | Updates vote bundling test to use vote_generator.vote_normal(). |
| nano/core_test/fair_queue.cpp | Updates tests for new fair-queue channel typing and default std::monostate channel. |
| nano/core_test/election.cpp | Updates election construction to include bucket argument. |
| nano/core_test/CMakeLists.txt | Adds new vote_generator.cpp test target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2f907c3 to
58f1607
Compare
Replace the separate normal and final generators with a single vote_generator that drives dedicated verifier and broadcaster workers. Add fair per-bucket deduplication, split normal/final traffic and thread roles, and cover the new queue behavior with core tests.
Use network fanout capacity checks for normal and final vote broadcasts, recording cooldown stats and rate-limited warnings when the network is saturated. Treat an empty network as available capacity so vote generation is not blocked before any peers are connected.
Add vote generator tests for basic broadcasts, multiple representatives, final vote upgrades, and missing block handling. Move the existing vote generator cases from `voting.cpp` into `vote_generator.cpp`.
58f1607 to
2c95091
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Setup representatives without wallet keys to avoid background voting during setup | ||
| nano::keypair key1, key2, key3; | ||
| auto const amount = 100 * nano::Knano_ratio; | ||
| auto rep1 = nano::test::setup_rep (system, node, amount, nano::dev::genesis_key); | ||
| auto rep2 = nano::test::setup_rep (system, node, amount, nano::dev::genesis_key); | ||
| auto rep3 = nano::test::setup_rep (system, node, amount, nano::dev::genesis_key); |
There was a problem hiding this comment.
nano::keypair key1, key2, key3; are declared but never used in this test. They should be removed (or actually used) to avoid unnecessary noise and potential unused-variable warnings in builds/tests with stricter warning settings.
The previous design ran two independent vote generator instances (normal and final) with separate queues, threads, and deduplication logic. This led to duplicated code, no coordination between normal and final vote paths, and no awareness of network backpressure.
This rework consolidates both into a single
vote_generatorwith separated verifier and broadcaster stages. Incoming vote requests are fair-queued by balance bucket with root-based deduplication, then verified and forwarded to broadcaster threads that gate output against network capacity. When a final vote has already been recorded for a given root, normal vote requests are automatically upgraded to final.