Skip to content

Vote generator rework#5054

Merged
pwojcikdev merged 6 commits intonanocurrency:developfrom
pwojcikdev:vote-generator-rework-3
Apr 1, 2026
Merged

Vote generator rework#5054
pwojcikdev merged 6 commits intonanocurrency:developfrom
pwojcikdev:vote-generator-rework-3

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

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_generator with 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.

@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Mar 29, 2026

Test Results for Commit 2c95091

Pull Request 5054: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 120s)
  • 5n4pr_conf_10k_change: PASS (Duration: 146s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 114s)
  • 5n4pr_conf_change_independant: PASS (Duration: 115s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 121s)
  • 5n4pr_conf_send_independant: PASS (Duration: 113s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 124s)
  • 5n4pr_rocks_10k_change: FAIL (Duration: 288s)
  • Log

Last updated: 2026-03-31 21:32:01 UTC

@pwojcikdev pwojcikdev force-pushed the vote-generator-rework-3 branch from 69fbfc8 to 1ac0e39 Compare March 30, 2026 18:33
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.
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 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_generator with separate verifier and broadcaster stages.
  • Updates voting_policy to provide a unified vote() eligibility check that can upgrade normal requests to final when a final vote is already recorded.
  • Generalizes fair_queue to use channel traits (instead of hard-coding transport::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.

@pwojcikdev pwojcikdev force-pushed the vote-generator-rework-3 branch from 2f907c3 to 58f1607 Compare March 31, 2026 19:32
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`.
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 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.

Comment on lines +668 to +673
// 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);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@pwojcikdev pwojcikdev merged commit ccad7d2 into nanocurrency:develop Apr 1, 2026
31 of 33 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