Skip to content

Fix rebroadcast capacity check with no peers#5055

Merged
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:network-check-capacity-zero
Mar 31, 2026
Merged

Fix rebroadcast capacity check with no peers#5055
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:network-check-capacity-zero

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

Treat an empty network as having available capacity so rebroadcasting does not fail early when no channels exist.

Relax the rebroadcaster test to accept multiple queued events instead of assuming the counter stays exactly at one.

Treat an empty network as having available capacity so
rebroadcasting does not fail early when no channels exist.

Relax the rebroadcaster test to accept multiple queued events
instead of assuming the counter stays exactly at one.
@pwojcikdev pwojcikdev force-pushed the network-check-capacity-zero branch from 10294fb to 8df578a Compare March 30, 2026 18:32
@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Mar 30, 2026

Test Results for Commit 8df578a

Pull Request 5055: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 117s)
  • 5n4pr_conf_10k_change: PASS (Duration: 204s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 144s)
  • 5n4pr_conf_change_independant: PASS (Duration: 137s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 127s)
  • 5n4pr_conf_send_independant: PASS (Duration: 132s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 118s)
  • 5n4pr_rocks_10k_change: FAIL (Duration: 278s)
  • Log

Last updated: 2026-03-30 21:55:27 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

Adjusts rebroadcast behavior so nodes with zero connected peers don’t get stuck behind a “no capacity” gate, and updates a flaky expectation in the rebroadcaster tests.

Changes:

  • Treat an empty network (no channels) as having available capacity in network::check_capacity().
  • Change when election::broadcast_block() queues blocks for the block_rebroadcaster.
  • Relax block_rebroadcaster test assertion to accept queued >= 1 instead of exactly 1.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
nano/node/network.cpp Makes capacity checks succeed when there are no channels.
nano/node/election.cpp Alters when blocks are queued for rebroadcast during election block broadcast.
nano/core_test/block_rebroadcaster.cpp Makes the basic rebroadcaster test tolerant to multiple queued events.
Comments suppressed due to low confidence (1)

nano/node/network.cpp:346

  • check_capacity() now returns true when the network has zero channels. This causes the block/vote rebroadcasters to drain their queues and call check_and_record() even though flood_* will send to 0 peers, meaning the item can enter the rebroadcast cooldown window without ever being transmitted. If a peer connects shortly after, subsequent pushes for the same block/vote can be suppressed for up to rebroadcast_cooldown (60s by default), delaying actual propagation. Consider treating an empty network as a special case where the rebroadcaster is allowed to run but does not record a rebroadcast attempt (or only records when sent > 0).
bool nano::network::check_capacity (nano::transport::traffic_type type, size_t target_count) const
{
	if (target_count == 0 || size () == 0)
	{
		return true;
	}
	auto channels = list (target_count, [type] (auto const & channel) {
		return !channel->max (type); // Only use channels that are not full for this traffic type
	});
	return !channels.empty () && channels.size () >= target_count / 2; // We need to have at least half of the target capacity available

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

Comment on lines 304 to +308
duration ().count ());
}

// Random flood for block propagation
node.block_rebroadcaster.push (status.winner);
// Random flood for block propagation
node.block_rebroadcaster.push (status.winner);
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This change moves node.block_rebroadcaster.push(status.winner) inside the if (!solicitor_a.broadcast(*this)) block. That makes rebroadcaster queuing contingent on confirmation_solicitor actually performing a directed broadcast (and stops it entirely once max_block_broadcasts is reached), which is a behavior change beyond the PR description. Please confirm this gating is intentional, and if so update the PR description (or add a targeted test) to reflect the new propagation behavior.

Copilot uses AI. Check for mistakes.
@pwojcikdev pwojcikdev merged commit 86c1278 into nanocurrency:develop Mar 31, 2026
33 checks passed
@pwojcikdev pwojcikdev deleted the network-check-capacity-zero branch March 31, 2026 12:02
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