Skip to content

feat: add flags to enable broadcast blocks and transactions to all peers #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

yiweichi
Copy link
Member

@yiweichi yiweichi commented Jul 7, 2025

1. Purpose or design rationale of this PR

This PR is a part of project reduce transaction latency.
It adds a 2 flags gossip.enablebroadcasttoall to enable node to broadcast transactions/blocks to all peers. and gossip.broadcasttoallcap to set the maximum number of peers for broadcasting, preventing network congestion.

Meanwhile changed existing flag names from txgossip.disablebroadcast and txgossip.disablereceiving to gossip.disabletxbroadcast and gossip.disabletxreceiving for consistency of flag name.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added command-line flags to enable broadcasting transactions and blocks to all peers with a configurable maximum cap.
  • Refactor

    • Renamed existing transaction gossiping flags and configuration options for improved clarity and consistency.
    • Updated help documentation and configuration fields to reflect the new flag names and options.

Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

This change renames two transaction gossip-related flags and associated configuration fields, adopting a unified "gossip" prefix. It also introduces new flags and configuration options to enable broadcasting blocks and transactions to all peers, updating the handler logic to support this wider broadcast when the new flag is set.

Changes

File(s) Change Summary
cmd/geth/main.go, cmd/geth/usage.go Replaced old gossip flags with renamed versions and added new broadcast-to-all flags in CLI/groups.
cmd/utils/flags.go Renamed gossip flags, introduced new broadcast-to-all flags, updated SetEthConfig to use new fields.
eth/ethconfig/config.go Renamed config fields for gossip flags, added new boolean and int fields for broadcast-to-all.
eth/backend.go Updated handlerConfig to use renamed gossip flag names and added new broadcast-to-all fields.
eth/handler.go Added broadcast-to-all flags to handlerConfig and handler structs, updated broadcast logic accordingly.
params/version.go Bumped patch version from 65 to 66.

Sequence Diagram(s)

sequenceDiagram
    participant CLI
    participant Config
    participant Handler

    CLI->>Config: Parse gossip flags (disable broadcast, disable receiving, enable broadcast to all)
    Config->>Handler: Pass GossipTxBroadcastDisabled, GossipTxReceivingDisabled, GossipBroadcastToAllEnabled, BroadcastToAllCap
    Handler->>Handler: On BroadcastBlock/BroadcastTransactions
    alt GossipBroadcastToAllEnabled is true
        Handler->>Peers: Broadcast to all peers (capped by BroadcastToAllCap)
    else
        Handler->>Peers: Broadcast to sqrt(total peers)
    end
Loading

Possibly related PRs

Suggested reviewers

  • yiweichi
  • georgehao
  • colinlyguo

Poem

🐇 In the network's bustling glade,
New flags bring changes well displayed.
Broadcast to all, no peer left behind,
Gossip spreads, swift and kind.
From root to leaf, the messages flow,
As bunnies code and watchers know! 🌿


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 794836f and 70b1ec3.

📒 Files selected for processing (1)
  • params/version.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • params/version.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
eth/handler.go (1)

483-487: Implementation looks correct but consider the performance implications.

The logic correctly implements broadcasting to all peers (capped at 100) when the flag is enabled, replacing the previous sqrt-based approach. This will significantly increase network traffic for nodes with many peers but provides the intended broadcast coverage.

The 100-peer cap is a sensible safeguard against resource exhaustion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1043f66 and 7a023b6.

📒 Files selected for processing (6)
  • cmd/geth/main.go (1 hunks)
  • cmd/geth/usage.go (1 hunks)
  • cmd/utils/flags.go (2 hunks)
  • eth/backend.go (1 hunks)
  • eth/ethconfig/config.go (1 hunks)
  • eth/handler.go (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
cmd/geth/usage.go (1)
cmd/utils/flags.go (3)
  • GossipTxBroadcastDisabledFlag (897-900)
  • GossipTxReceivingDisabledFlag (901-904)
  • GossipBroadcastToAllEnabledFlag (905-908)
cmd/geth/main.go (1)
cmd/utils/flags.go (3)
  • GossipTxBroadcastDisabledFlag (897-900)
  • GossipTxReceivingDisabledFlag (901-904)
  • GossipBroadcastToAllEnabledFlag (905-908)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: check
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (go)
🔇 Additional comments (9)
cmd/geth/usage.go (1)

251-253: LGTM! Consistent flag naming and clear new feature addition.

The renaming adopts a unified "Gossip" prefix for all gossip-related flags, improving consistency. The new GossipBroadcastToAllEnabledFlag clearly indicates the broadcast-to-all feature.

eth/backend.go (1)

286-288: LGTM! Proper configuration propagation.

The field renaming maintains consistency with the config changes, and the new EnableBroadcastToAll field correctly propagates the new feature flag to the handler configuration.

eth/ethconfig/config.go (1)

234-236: LGTM! Clean configuration structure with consistent naming.

The renaming establishes a unified "Gossip" prefix for all gossip-related configuration fields. The new GossipBroadcastToAllEnabled field defaults to false, ensuring backward compatibility.

cmd/geth/main.go (1)

179-181: LGTM! Consistent CLI flag registration.

The flag changes align perfectly with the usage.go updates, ensuring the renamed and new gossip flags are properly registered for the main geth command.

eth/handler.go (4)

97-99: LGTM! Configuration structure properly updated.

The handlerConfig struct correctly incorporates the renamed fields and the new EnableBroadcastToAll flag.


138-141: LGTM! Handler struct properly updated.

The handler struct fields are consistently renamed and the new enableBroadcastToAll field is added to support the feature.


161-163: LGTM! Proper configuration initialization.

The handler initialization correctly maps the configuration values to the handler fields, maintaining the renamed field consistency and enabling the new feature.


529-532: Transaction broadcast logic correctly mirrors block broadcast behavior.

The implementation maintains consistency with the block broadcast approach, broadcasting transactions to all peers (up to 100) when the flag is enabled instead of the sqrt-based subset.

cmd/utils/flags.go (1)

896-908: LGTM! Flag definitions follow good naming conventions.

The gossip-related flags are well-structured with consistent naming and clear descriptions.

@@ -477,7 +480,12 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
return
}
// Send the block to a subset of our peers
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
numDirect := int(math.Sqrt(float64(len(peers))))
// If enableBroadcastToAll is true, broadcast blocks directly to all peers (capped at 100).
Copy link
Member

Choose a reason for hiding this comment

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

A gut feeling is 20 to 30 might be sufficient. But for robustness, this can also be added to the configuration, enabled together with enableBroadcastToAll.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice advise, added this with a default cap 30.

Choose a reason for hiding this comment

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

Based on the chart of bootnode-0 provided by @colinlyguo it looks like it has a max peers of 163. For bootnodes and other nodes operated by Scroll, will we be setting this value higher to include all 163 peers?

colinlyguo
colinlyguo previously approved these changes Jul 8, 2025
@yiweichi yiweichi changed the title feat: add flag to enable broadcast blocks and transactions to all peers feat: add flags to enable broadcast blocks and transactions to all peers Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants