Skip to content

fix(net): stop masternode connect opening probes and untangle the probe flag - #8051

Open
PastaPastaPasta wants to merge 3 commits into
dashpay:developfrom
PastaPastaPasta:fix/masternode-connect-probe-flag
Open

PastaPastaPasta wants to merge 3 commits into
dashpay:developfrom
PastaPastaPasta:fix/masternode-connect-probe-flag

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Since ef3f738 (the bitcoin#15759 merge, #4862, 2022), masternode connect opens a masternode probe rather than a masternode connection, and still reports success. That merge turned OpenMasternodeConnection(const CAddress&, bool probe = false) into an enum parameter whose default, MasternodeProbeConn::IsConnection, means "this is a probe". The RPC is the only caller that relies on the default. So we never send our MNAUTH on the connection, and we drop it as soon as the peer's MNAUTH arrives ("Masternode probe successful for …, disconnecting"), after the RPC has already returned "successfully connected".

Separately, CMNAuth reuses m_masternode_probe_connection to mark a verified inbound connection it gives up on in favour of another connection to the same masternode. One flag therefore means "outbound probe" in one direction and "superseded duplicate" in the other.

What was done?

  • fix(net): make masternode connect open a masternode connection, not a probe removes the default, so every caller states its intent, and the RPC passes MasternodeProbeConn::IsNotConnection. The only other caller, ThreadOpenMasternodeConnections, already passes its value explicitly. New rpc_masternode.py scenarios check two things:
    • masternode connect yields one connection that both ends have verified.
    • A second masternode connect, in the reverse direction, is settled by CMNAuth's duplicate resolution into one verified connection, seen from both ends. No functional test drove that logic with real MNAUTH messages before, because the regtest mnauth RPC bypasses CMNAuth::ProcessMessage. Which side logs the resolution depends on the order of the two proTxHashes, so the test accepts either side.
  • refactor(net): stop reusing the masternode probe flag to mark duplicate inbound legs does three things:
    • moves the duplicate mark into its own m_masternode_duplicate_inbound field, and has CMasternodeUtils::DoMaintenance check both fields;
    • adds Assume(!probe || !inbound);
    • corrects the field comments. The old m_masternode_connection comment named a function that no longer exists.

Why the refactor preserves behavior. The probe flag is written only by OpenNetworkConnection, which asserts that the connection is not inbound, and by CMNAuth, which writes it only on inbound connections. So on an inbound node the flag always was the duplicate mark. Only one reader of the flag could ever see that:

Reader Could it see the mark on an inbound connection?
VERACK handler (decides whether to send our MNAUTH) No. It runs once, before any MNAUTH from that peer is processed.
First post-VERACK message check No. It runs once, before CMNAuth handles that same message.
Probe-success disconnect in CMNAuth No. It applies only to outbound connections.
DNS-seed and extra-outbound peer counts No. Both are gated on IsFullOutboundConn().
v1 reconnect info No. Only initiating (outbound) connections reconnect.
DoMaintenance's non-masternode count No. The flag is read inside the !IsInboundConn() conjunct.
DoMaintenance's drop loop Yes. It now checks both fields.

The duplicate-resolution branches and their log strings are unchanged, and so are TryMarkVerified, the per-protx inbound cap, and DoMaintenance's gating and timing. One difference is reachable, through the regtest-only mnauth RPC. Suppose a connection is marked verified through that RPC before it has sent any post-VERACK message, and a real MNAUTH on another connection then marks it as a duplicate. It used to be dropped on its first message; now it waits for DoMaintenance. No test does this.

Behavior note. On a well-connected node, one with at least as many non-masternode peers as automatic outbound slots, DoMaintenance still closes a masternode connect link to a masternode that is not one of our quorum or relay members within about a minute. That was also the behavior before 2022. On nodes with fewer peers, including regtest, the link stays up.

How Has This Been Tested?

Built with --enable-debug --enable-werror. On develop's C++, the first new scenario fails: the node logs "Masternode probe successful for …, disconnecting", and the wait for a verified link times out. Both scenarios pass on the first commit alone and on the final head. The final head also passes evo_mnauth_tests, net_tests and denialofservice_tests in test_dash, plus rpc_mnauth.py, feature_llmq_connections.py, p2p_quorum_data.py and feature_llmq_simplepose.py (with and without --disable-spork23). The second scenario also passes before the refactor, as expected for a behavior-preserving change.

Breaking Changes

None. The only P2P difference is that masternode connect connections are ordinary masternode connections again, so we now send MNAUTH on them.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (if you have permission to set one)

🤖 Generated with Claude Code

@thepastaclaw

thepastaclaw commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 13975c7) · triage: low

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

At head 7f5349a, the explicit non-probe argument fixes the RPC regression, and the separate duplicate-inbound flag preserves production connection handling; no blocking correctness issues were found. One non-blocking release-note suggestion remains. This was a static review: current CI checks all passed or were skipped, and the supplied base-drift evidence reports no conflicts or intervening changes to the modified files.

🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The small, contained diff corrects an explicit connection-type argument, separates two flag meanings while preserving duplicate-resolution logic, and adds focused functional tests without intricate changes to a critical surface.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 98% left, weekly 58% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/rpc/masternode.cpp`:
- [SUGGESTION] src/rpc/masternode.cpp:78-79: User-visible behavior change deserves a release note (doc/release-notes-8051.md)
  Add doc/release-notes-8051.md describing the restored `masternode connect` behavior. The RPC now opens a non-probe connection, allowing a masternode caller to send MNAUTH and establish a mutually authenticated link instead of disconnecting when the peer's MNAUTH arrives. This is an observable RPC fix, and doc/developer-notes.md requests release notes for significant bug fixes and visible end-user changes. Include the existing maintenance caveat: the link is not guaranteed to remain open when the node has enough non-masternode peers and the target is not a required quorum or relay peer. Keep the note focused on authentication and connection lifetime; the helper already set m_masternode_connection before this PR, so relay suppression is not newly introduced by this change.

Comment thread src/rpc/masternode.cpp
Comment on lines +78 to +79
connman.OpenMasternodeConnection(CAddress(addr.value(), NODE_NETWORK), use_v2transport,
CConnman::MasternodeProbeConn::IsNotConnection);

@thepastaclaw thepastaclaw Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Resolved at 40194422; see the replies below.

🟡 Suggestion: User-visible behavior change deserves a release note (doc/release-notes-8051.md)

Add doc/release-notes-8051.md describing the restored masternode connect behavior. The RPC now opens a non-probe connection, allowing a masternode caller to send MNAUTH and establish a mutually authenticated link instead of disconnecting when the peer's MNAUTH arrives. This is an observable RPC fix, and doc/developer-notes.md requests release notes for significant bug fixes and visible end-user changes. Include the existing maintenance caveat: the link is not guaranteed to remain open when the node has enough non-masternode peers and the target is not a required quorum or relay peer. Keep the note focused on authentication and connection lifetime; the helper already set m_masternode_connection before this PR, so relay suppression is not newly introduced by this change.

source: glm-5.3-flash (phase1-reviewer: general)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added doc/release-notes-8051.md in 4019442. It describes the restored masternode connect behaviour and the existing maintenance caveat: once the node has enough non-masternode peers, the connection is closed unless the peer is a quorum or quorum relay peer. It doesn't claim relay suppression as new.


🤖 Posted autonomously by Claude on behalf of pasta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 40194422): Verified your added doc/release-notes-8051.md at 4019442: it describes restored MNAUTH authentication and the existing maintenance-based connection lifetime caveat. It does not present relay suppression as newly introduced behavior, so the requested release note is complete.

@thepastaclaw thepastaclaw added pastaclaw:commented thepastaclaw's latest review was comment-only and removed pastaclaw:commented thepastaclaw's latest review was comment-only labels Nov 5, 2026
thepastaclaw
thepastaclaw previously approved these changes Nov 5, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

Independently reviewed the complete diff at 4019442: the RPC now explicitly opens a non-probe masternode connection, and the inbound-duplicate flag split preserves normal authentication and maintenance behavior; no actionable issues were found. The added release note resolves the prior documentation finding. This was a static review only; current CI checks for this head show successful builds, linting, and test jobs, including sanitizer and multiprocess configurations, with no checks pending or failing.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, contained connection-intent fix and flag separation with focused regression tests, without intricate changes or changes to a qualifying critical surface.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 96% left, weekly 56% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 5, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

PastaPastaPasta and others added 3 commits November 27, 2026 16:43
… probe

ef3f738 (the bitcoin#15759 merge) turned OpenMasternodeConnection's
`bool probe = false` into `MasternodeProbeConn probe =
MasternodeProbeConn::IsConnection`, flipping the default. The
`masternode connect` RPC relies on that default, so since then it opens a
probe: we never send our MNAUTH on it and drop it as soon as the peer's
MNAUTH arrives, while the RPC still reports "successfully connected".

Drop the default so every caller has to state its intent, and have the
RPC ask for a regular masternode connection again.

The new rpc_masternode.py scenarios check that the connection gets
verified by both ends, and that a second connection between the same
pair is settled by CMNAuth's duplicate resolution, which no functional
test drove with real MNAUTH messages before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te inbound legs

When CMNAuth finds a second verified connection to the same masternode
and decides to keep the other one, it marks the inbound leg it gives up
on by setting m_masternode_probe_connection, so that
CMasternodeUtils::DoMaintenance disconnects it later. That gives one flag
two meanings: an outbound reachability probe, and a superseded inbound
duplicate.

Give the duplicate mark its own field. The probe flag is only ever set on
outbound connections, so on an inbound one it was always the duplicate
mark, and of the flag's readers only the DoMaintenance drop loop could
ever see that: the VERACK and first-message checks run before an MNAUTH
can set it, and the others only look at outbound connections. That loop
now checks both fields, so behavior is unchanged. State that probes are
outbound only with an Assume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/masternode-connect-probe-flag branch from 4019442 to 13975c7 Compare November 27, 2026 16:57
@PastaPastaPasta PastaPastaPasta added this to the 24.1 milestone Nov 27, 2026
@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 27, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

New on this head: The rebase picks up the base branch’s lock annotation and include changes without altering the masternode connect authentication fix, duplicate-inbound cleanup, or release note. GitHub reports no merge conflicts with develop; lint, ClangFormat, and Cppcheck passed, and source builds including Linux and ASan are still pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The diff makes a small, contained change to the RPC’s connection mode and separates the duplicate-inbound marker from the probe flag without changing authentication or duplicate-selection rules.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (zai below 15% reserve: 5h 100% left, weekly 0% left)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 27, 2026
@PastaPastaPasta
PastaPastaPasta marked this pull request as ready for review November 27, 2026 18:22
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

masternode_connect now opens an ordinary masternode connection instead of a probe. Duplicate inbound connections are marked separately and share the probe grace period before maintenance can disconnect them. The functional test checks that nodes verify each other, resolves a reverse-connection duplicate, and retains a verified link. The release note describes the authentication and connection-closing behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant MasternodeRPC
  participant CConnman
  participant Peer
  Operator->>MasternodeRPC: Call masternode_connect
  MasternodeRPC->>CConnman: OpenMasternodeConnection with IsNotConnection
  CConnman->>Peer: Open ordinary masternode connection
  Peer-->>CConnman: Complete authenticated connection
Loading

Suggested reviewers: kwvg

Merge Risk: Minimal · up to 13975

The change makes the masternode connect RPC open a regular authenticated connection, as intended, and separates the duplicate-connection marker from the probe flag. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: masternode connect was opening a probe instead of a masternode connection. It also names the probe-flag cleanup, which is a second part of the changeset. It is specifi…
Description check Passed The description explains the bug (masternode connect opens a probe and reports success), the removal of the enum default, the RPC change, the new functional tests, the separate duplicate-inbound flag …
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.
Full details: Title check

Explanation

The title names the main change: masternode connect was opening a probe instead of a masternode connection. It also names the probe-flag cleanup, which is a second part of the changeset. It is specific and matches the diff and the objectives.

Full details: Description check

Explanation

The description explains the bug (masternode connect opens a probe and reports success), the removal of the enum default, the RPC change, the new functional tests, the separate duplicate-inbound flag refactor, the testing done, and the behavior note. It matches the changeset closely.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d61e4982-82fd-4829-a9a2-9a874ea28e3c
Commits

Reviewing files that changed from the base of the PR and between da48f84 and 13975c7.

Files selected for processing: 6

  • doc/release-notes-8051.md
  • src/evo/mnauth.cpp
  • src/masternode/utils.cpp
  • src/net.h
  • src/rpc/masternode.cpp
  • test/functional/rpc_masternode.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@github-actions

Copy link
Copy Markdown

Potential PR merge conflicts

This is advisory only. It does not block CI. This PR and each open PR below change the same files and cannot be merged together cleanly, so whichever of the two merges second will likely need a rebase:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pastaclaw:approved thepastaclaw's latest review approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants