Skip to content

fix: ignore repeated getsporks requests - #7343

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
thepastaclaw:fix/getsporks-once
Jun 15, 2026
Merged

fix: ignore repeated getsporks requests#7343
PastaPastaPasta merged 1 commit into
dashpay:developfrom
thepastaclaw:fix/getsporks-once

Conversation

@thepastaclaw

Copy link
Copy Markdown

Pull request

Issue being fixed or feature implemented

getsporks currently responds to every request from a connected peer by
snapshotting active sporks and sending each stored spork message back. The active
spork set is small, so this is low impact, but repeated requests are unnecessary
resource use and keep being flagged by security-audit tooling.

This PR makes getsporks follow the existing getaddr pattern: answer once per
connection and ignore repeats.

What was done?

  • Added per-peer m_getsporks_recvd state.
  • Ignore repeated getsporks requests on the same connection after the first
    response.
  • Added a functional regression test in feature_sporks.py that sends
    getsporks twice and verifies only the first request returns spork messages.

How Has This Been Tested?

Tested on macOS arm64 using the existing depends prefix.

  • git diff --check
  • python3 -m py_compile test/functional/feature_sporks.py
  • make -j8 src/dashd
  • test/functional/feature_sporks.py --tmpdir=/Users/claw/.openclaw/workspace/tmp-dash-test-feature-sporks-rerun-79105

The focused functional test passed successfully.

Breaking Changes

None.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

✅ No Merge Conflicts Detected

This PR currently has no conflicts with other open PRs.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

PastaPastaPasta
PastaPastaPasta previously approved these changes Jun 8, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems reasonable to me; utACK 7c799761c80509e2293af700a6cf864cf6d5d263

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc3d0059-da9c-464c-b86b-09397dfd4b6b

📥 Commits

Reviewing files that changed from the base of the PR and between 59ac8d351908710f4e96213e53b0f375bd596021 and 60efd84.

📒 Files selected for processing (2)
  • src/net_processing.cpp
  • test/functional/feature_sporks.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/functional/feature_sporks.py
  • src/net_processing.cpp

Walkthrough

Per-peer GETSPORKS state is tracked and GETSPORKS responses are suppressed when the currently-active spork-hash set equals the last response sent to that connection. The change adds an include, two Peer fields (m_getsporks_recvd and m_getsporks_last_response), and updates the GETSPORKS handler to compute a sorted active-spork-hash list, compare it to the peer's cached list, early-return when identical, and refresh the cache when sending. A functional test sends GETSPORKS twice on one connection and asserts only one spork response was delivered; changing a spork causes a refreshed response.

Sequence Diagram(s)

sequenceDiagram
  participant PeerConn as Peer
  participant Handler as GETSPORKS_Handler
  participant SporkSet as ActiveSporkSet
  participant SporkSender as Spork_Response
  PeerConn->>Handler: GETSPORKS
  Handler->>SporkSet: Build sorted active spork hashes
  Handler->>PeerConn: Read m_getsporks_recvd & m_getsporks_last_response
  alt active set == last_response && m_getsporks_recvd == true
    Handler-->>PeerConn: Log + early return (no spork messages)
  else
    Handler->>PeerConn: Update m_getsporks_recvd = true and m_getsporks_last_response
    Handler->>SporkSender: Send active spork messages
    SporkSender-->>PeerConn: spork messages
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: ignore repeated getsporks requests' clearly summarizes the main change - implementing per-peer tracking to respond only once to getsporks requests, which is the primary objective of this PR.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the problem, solution, implementation details, and testing performed for the getsporks request optimization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/functional/feature_sporks.py`:
- Around line 91-96: The test records peer.message_count["spork"] too early
because wait_until only waits for the first spork; call peer.sync_with_ping()
immediately after wait_until (before reading spork_responses) to ensure all
spork messages from the first msg_getsporks() have been delivered; update the
block around peer.wait_until(...), peer.sync_with_ping(), and spork_responses so
spork_responses = peer.message_count["spork"] happens only after the
sync_with_ping() completes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5a4f030e-5dfd-401c-9e91-49f0b73dbdc8

📥 Commits

Reviewing files that changed from the base of the PR and between b965f90834ad71a7f76583819b3b1b38a529e004 and 59ac8d351908710f4e96213e53b0f375bd596021.

📒 Files selected for processing (2)
  • src/net_processing.cpp
  • test/functional/feature_sporks.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/net_processing.cpp

Comment thread test/functional/feature_sporks.py
@thepastaclaw

thepastaclaw commented Jun 8, 2026

Copy link
Copy Markdown
Author

✅ Review complete (commit 60efd84)

@thepastaclaw

Copy link
Copy Markdown
Author

Addressed CodeRabbit race concern in the functional test by syncing after the initial getsporks response before recording the baseline count. Validation: test/functional/feature_sporks.py.

@thepastaclaw

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw
thepastaclaw marked this pull request as ready for review June 9, 2026 03:07

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review

Verified the per-peer getsporks ignore logic in src/net_processing.cpp:5454-5481 and the functional test in test/functional/feature_sporks.py. The implementation correctly suppresses duplicate responses while still re-answering when the active spork hash set changes, and the test exercises both paths. Claude's three findings are all low-confidence nitpicks/meta observations that don't merit public review noise; Codex correctly found nothing to flag.

Note: GitHub does not allow the review bot account to approve its own PR, so this clean verification is posted as a comment review instead of an approval.

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK 60efd84

@PastaPastaPasta

Copy link
Copy Markdown
Member

@thepastaclaw I'm not fully sure this is worth it. Please review to confirm this makes sense to do holistically. provide justification which ever way you decide

@thepastaclaw

Copy link
Copy Markdown
Author

Reviewed this holistically and I still think it is worth keeping, with the caveat that it is a small hardening/cleanup rather than an urgent bug fix.

Why I think it makes sense:

  • getsporks is effectively a snapshot request; answering unchanged repeats on the same connection does not add useful protocol value.
  • This matches the existing getaddr anti-repeat shape and avoids leaving a low-cost request that can repeatedly trigger response fanout.
  • The implementation stays bounded: one boolean plus the last response hash set per peer, and it still re-answers on the same connection when the active spork set changes.
  • The behavior is covered by the focused functional test: first request gets sporks, unchanged repeat gets none, post-update request gets a fresh response.

Why it is not a high-priority fix:

  • The active spork set is small today, so the practical resource impact is low.
  • If maintainers prefer avoiding even small peer-state churn for marginal hardening, closing it would also be defensible.

My recommendation is to keep/merge it as a modest DoS-surface cleanup because it aligns with existing peer-request hygiene without breaking legitimate refreshed getsporks use.

@UdjinM6 UdjinM6 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

utACK 60efd84

@PastaPastaPasta
PastaPastaPasta merged commit 1444974 into dashpay:develop Jun 15, 2026
48 checks passed
@UdjinM6 UdjinM6 added this to the 24 milestone Jun 18, 2026
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jul 29, 2026
Backport of dashpay#7438 (upstream merge 4537f37, cherry-picked with -m1).

v23.1.x adaptations: (1) on this branch spork messages are deserialized in CSporkManager::ProcessSpork (src/spork.cpp), not in net_processing's SPORK handler as on develop - the same try/catch is applied there, reporting the failure as MisbehavingError{100, ...} through the existing MessageProcessingResult path (equivalent to develop's Misbehaving(*peer, 100, ...)). (2) The functional test's msg_spork_raw/SporkP2PInterface helpers come from dashpay#7343 (commit 60efd84), which is not on this branch; they are included verbatim, and the new test registers MESSAGEMAP[b"spork"] itself since dashpay#7343's test method (which did the registration on develop) is absent here. The spork.h LIMITED_VECTOR bound is unchanged from upstream.

(cherry picked from commit 4537f37d51d5b62be3aca4bfc9e40404db76ffc9)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jul 29, 2026
Backport of dashpay#7438 (upstream merge 4537f37, cherry-picked with -m1).

v23.1.x adaptations: (1) on this branch spork messages are deserialized in CSporkManager::ProcessSpork (src/spork.cpp), not in net_processing's SPORK handler as on develop - the same try/catch is applied there, reporting the failure as MisbehavingError{100, ...} through the existing MessageProcessingResult path (equivalent to develop's Misbehaving(*peer, 100, ...)). (2) The functional test's msg_spork_raw/SporkP2PInterface helpers come from dashpay#7343 (commit 60efd84), which is not on this branch; they are included verbatim, and the new test registers MESSAGEMAP[b"spork"] itself since dashpay#7343's test method (which did the registration on develop) is absent here. The spork.h LIMITED_VECTOR bound is unchanged from upstream.

(cherry picked from commit 4537f37d51d5b62be3aca4bfc9e40404db76ffc9)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jul 29, 2026
Backport of dashpay#7438 (upstream merge 4537f37, cherry-picked with -m1).

v23.1.x adaptations: (1) on this branch spork messages are deserialized in CSporkManager::ProcessSpork (src/spork.cpp), not in net_processing's SPORK handler as on develop - the same try/catch is applied there, reporting the failure as MisbehavingError{100, ...} through the existing MessageProcessingResult path (equivalent to develop's Misbehaving(*peer, 100, ...)). (2) The functional test's msg_spork_raw/SporkP2PInterface helpers come from dashpay#7343 (commit 60efd84), which is not on this branch; they are included verbatim, and the new test registers MESSAGEMAP[b"spork"] itself since dashpay#7343's test method (which did the registration on develop) is absent here. The spork.h LIMITED_VECTOR bound is unchanged from upstream.

(cherry picked from commit 4537f37d51d5b62be3aca4bfc9e40404db76ffc9)
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