Skip to content

feat(p2p): implement --disable-relay-tx flag#888

Open
RossKU wants to merge 2 commits intokaspanet:masterfrom
RossKU:disable-relay-tx-228
Open

feat(p2p): implement --disable-relay-tx flag#888
RossKU wants to merge 2 commits intokaspanet:masterfrom
RossKU:disable-relay-tx-228

Conversation

@RossKU
Copy link

@RossKU RossKU commented Feb 26, 2026

Summary

Closes #228.

Implements the --disable-relay-tx CLI flag, allowing API-only nodes to opt out of transaction relay, reducing mempool overhead and bandwidth.

What it does

  • Adds --disable-relay-tx CLI flag (also configurable via KASPAD_DISABLE_RELAY_TX env var or config file)
  • Sets disableRelayTx in the version handshake message so peers know not to send us transactions
  • Filters outbound tx broadcasts to skip peers that have set disable_relay_tx in their version handshake
  • Drains incoming tx inv messages without acting on them when our node has relay disabled

Changes by file

  • kaspad/src/args.rs — CLI arg, Args struct field, parsing, apply_to_config
  • consensus/core/src/config/mod.rs — Config struct field + default
  • protocol/flows/src/flow_context.rs — Populate disable_relay_tx in version message (resolves the TODO at line 716)
  • protocol/flows/src/flowcontext/transactions.rs — Use broadcast_filtered / broadcast_to_some_peers_filtered to skip disable_relay_tx peers
  • protocol/p2p/src/core/hub.rs — Add broadcast_filtered() and broadcast_to_some_peers_filtered() methods
  • protocol/flows/src/v7/txrelay/flow.rs — Drain inbound tx inv when relay is disabled (v8 reuses v7 txrelay, so both versions are covered)

Design decisions

  • Both directions: We don't broadcast tx inv to peers who set the flag, AND we don't request txs if we set the flag ourselves
  • Drain, don't unregister: The relay flow is still registered (to avoid breaking protocol expectations) but drains inv messages without requesting transactions
  • Mining safe: Mining uses RPC + mempool, not P2P relay. Nodes with --disable-relay-tx can still accept transactions via RPC

Out of scope: starvation mitigation

As noted by @coderofstuff in #228, if a node wants txs but all its peers have disable_relay_tx=true, no transactions arrive. Mitigation (peer eviction + reconnection logic) is deferred to a follow-up issue — in practice, disable_relay_tx nodes will be a small minority (API-only), so this scenario is unlikely.

Test plan

  • cargo check --workspace passes
  • cargo test --workspace passes (all tests)
  • Manual: start kaspad with --disable-relay-tx, verify no tx inv messages are processed
  • Manual: connect two nodes, one with flag set, verify txs are not relayed to it

🤖 Generated with Claude Code

Add CLI flag to disable transaction relay, allowing API-only nodes to
skip mempool overhead and bandwidth from tx propagation.

Changes:
- Add --disable-relay-tx to CLI args and Config
- Populate disable_relay_tx in version handshake message
- Filter tx broadcasts to skip peers with disable_relay_tx set
- Drain incoming tx inv messages when our node has relay disabled

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderofstuff
Copy link
Collaborator

wdyt about the possible starvation issue @someone235 @michaelsutton?

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Implement disable_relay_tx

2 participants