Skip to content

test: wait for invalid-tx peers to be finalized in p2p_invalid_tx.py orphan checks - #8204

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/p2p-invalid-tx-orphan-flake
Nov 20, 2026
Merged

PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/p2p-invalid-tx-orphan-flake

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

p2p_invalid_tx.py --v1transport fails in test_orphan_tx_handling (first pass, line 248) with:

AssertionError: [node 0] Expected messages "['Erased 1 orphan tx included or conflicted by block']" does not partially match log
...
[txpackages] Erased 2 orphan tx included or conflicted by block

Every job where it appeared failed all 3 attempts: linux64_nowallet-test and linux64_sqlite-test on 2026-11-03, linux64_nowallet-test on 2026-11-11 (including #8078), on develop itself on 2026-11-16, and on #8079 on 2026-11-19 (job). None of those PRs touch the test or the orphanage.

The NonexistentInput template in the invalid-tx loop is stored as an orphan, and its second input spends block1's coinbase output 0. The node then disconnects that peer on SpendTooMuch, and erases the peer's orphans only when it finalizes the peer (FinalizeNode → EraseForPeer). For a peer it disconnected itself, DisconnectNodes lingers 100 ms before removing it, but getpeerinfo already hides fDisconnect peers, so reconnect_p2p() returns at once. On a fast runner the whole first-pass orphan section takes about 65 ms, so block_A arrives while the peer is still lingering. block_A's tx_withhold spends the same coinbase output, so EraseForBlock also erases the stale orphan as a conflict, giving "Erased 2". In the failing log, Cleared nodestate for that peer comes right after the block's EraseForBlock. The second pass restarts the node, so it is unaffected.

The check came in with #7551 (backport of bitcoin#19393). Upstream has no disconnect linger and has since stopped disconnecting peers over invalid txs, so there is no upstream fix to backport.

What was done?

Before the orphan checks, the test now waits until the debug log shows Cleared nodestate for peer=N for every peer from the invalid-tx loop, which means their orphans have been erased. There's no RPC that exposes either peer finalization or the orphanage, so the debug log is the only signal to wait on.

How Has This Been Tested?

  • Forced interleaving: a scratch dashd that always lingers 1.5 s on peers it disconnects itself. Unchanged test: 6 of 46 runs failed with the exact CI signature. Fixed test: 0 of 56.
  • Unmodified dashd, --v1transport, 8 runs in parallel: the unchanged test hit the CI failure once in about 280 runs on a heavily loaded host, where the orphan section rarely finishes within 100 ms. Fixed test: 0 of 160, plus 0 of 24 with --v2transport.
  • test/lint/lint-python.py (flake8) is clean for the file.

Breaking Changes

None, test only.

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

p2p_invalid_tx.py intermittently fails at "Erased 1 orphan tx included or
conflicted by block" because the node logs "Erased 2". The NonexistentInput
template leaves an orphan that spends block1's coinbase, and that orphan is
erased with its peer only when the node finalizes the peer. The node itself
disconnects that peer (on SpendTooMuch) and lingers 100 ms before removing
it, while getpeerinfo already hides it, so the test moves on at once. On a
fast runner the first-pass orphan section takes less than 100 ms, so block_A,
whose tx_withhold spends the same coinbase output, arrives first and erases
the stale orphan as a conflict too.

Wait until every peer from the invalid-tx loop has been finalized before
starting the orphan checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PastaPastaPasta PastaPastaPasta added this to the 24.1 milestone Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The functional test imports re and adds finalized_peer_ids() to extract peer IDs from debug-log entries that indicate nodestate cleanup. Before the orphan-handling checks, the test waits until every peer ID lower than the current minimum has been finalized.

Estimated code review effort: 2 (Simple) | ~8 minutes

Merge Risk: Minimal · up to adf47

This is a test-only change that makes an intermittent functional test more reliable. It does not affect production behavior, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change accurately: the test now waits for invalid-tx peers to be finalized before the orphan checks in p2p_invalid_tx.py. The diff adds a debug-log wait on 'Cleared nodestate for p…
Description check Passed The description explains the failing CI signature, the race between peer disconnection and orphan erasure, and the fix. It also lists the validation runs and the reason the debug log is the only wait …
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 change accurately: the test now waits for invalid-tx peers to be finalized before the orphan checks in p2p_invalid_tx.py. The diff adds a debug-log wait on 'Cleared nodestate for peer=N' lines before test_orphan_tx_handling's orphan assertions, so the title matches the main change.

Full details: Description check

Explanation

The description explains the failing CI signature, the race between peer disconnection and orphan erasure, and the fix. It also lists the validation runs and the reason the debug log is the only wait signal. It matches the changeset, which adds a debug-log wait in p2p_invalid_tx.py.

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: 1ce89727-a6f3-49b5-96d1-7ccc4e1399d0
Commits

Reviewing files that changed from the base of the PR and between 8f8526f and adf47a2.

Files selected for processing: 1

  • test/functional/p2p_invalid_tx.py

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

@thepastaclaw

thepastaclaw commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit adf47a2) · 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

The test-only change correctly waits for finalization of all peers from the invalid-transaction loop before performing aggregate orphan-erasure assertions. The finalization log is emitted after EraseForPeer, peer IDs are monotonic, and the wait excludes the newly created orphan-test peers. The ASAN failure is unrelated to this change and occurs in feature_llmq_data_recovery.py; relevant test jobs passed, while multiprocess and TSAN jobs were still pending in the snapshot.

Review provenance

Source: reviewer 1: glm-5.3-flash (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) — This is a small, well-contained functional-test synchronization fix that only waits for peer finalization before existing orphan checks and does not change production behavior.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 93% left, weekly 65% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • 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

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 19, 2026

@PastaPastaPasta PastaPastaPasta left a comment

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.

Approved

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.

2 participants