Skip to content

Merge bitcoin/bitcoin#27675: p2p: Drop m_recently_announced_invs bloom filter#899

Closed
DashCoreAutoGuix wants to merge 1 commit intobackport-0.26-batch-647from
backport-0.26-batch-647-pr-27675
Closed

Merge bitcoin/bitcoin#27675: p2p: Drop m_recently_announced_invs bloom filter#899
DashCoreAutoGuix wants to merge 1 commit intobackport-0.26-batch-647from
backport-0.26-batch-647-pr-27675

Conversation

@DashCoreAutoGuix
Copy link
Owner

@DashCoreAutoGuix DashCoreAutoGuix commented Aug 2, 2025

Summary

This PR backports Bitcoin Core PR bitcoin#27675 which replaces the m_recently_announced_invs bloom filter with a simple sequence number tracking the mempool state when we last considered sending an INV message to a node. This saves 33kB per peer.

Changes

  • Adds mempool entry sequence number tracking to CTxMemPoolEntry
  • Removes the m_recently_announced_invs bloom filter from net_processing
  • Adds info_for_relay method to CTxMemPool for checking transaction relay eligibility
  • Updates validation to set sequence to 0 for bypass_limits transactions (from reorgs)
  • Adds test_reorg_relay test to verify immediate relay of reorg transactions

Bitcoin PR Description

The philosophy here is that we consider the rate limiting on INV messages to only be about saving bandwidth and not protecting privacy, and therefore after you receive an INV message, it's immediately fair game to request any transaction that was in the mempool at the time the INV message was sent. Given that philosophy, tracking the timestamp of the last INV message and comparing that against the mempool entry time allows removal of each of m_recently_announced_invs, m_last_mempool_req and UNCONDITIONAL_RELAY_DELAY and associated logic.

Test plan

[Checklist for testing the pull request]

  • Unit tests pass
  • Functional test mempool_reorg.py passes
  • P2P transaction relay behavior is maintained

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved transaction relay logic to use a mempool sequence number, enhancing the accuracy of transaction announcements and requests.
    • Added a new test to verify that transactions from disconnected blocks are relayed correctly after a blockchain reorganization.
  • Bug Fixes

    • Ensured that transaction relay behavior after a reorg is consistent and immediate for previously confirmed transactions.
  • Tests

    • Introduced a functional test covering relay behavior during chain reorganizations.
  • Refactor

    • Simplified and updated internal transaction relay tracking, removing time-based delays and bloom filters in favor of sequence numbers.

fb02ba3 mempool_entry: improve struct packing (Anthony Towns)
1a11806 net_processing: Clean up INVENTORY_BROADCAST_MAX constants (Anthony Towns)
6fa4993 test: Check tx from disconnected block is immediately requestable (glozow)
e4ffabb net_processing: don't add txids to m_tx_inventory_known_filter (Anthony Towns)
6ec1809 net_processing: drop m_recently_announced_invs bloom filter (Anthony Towns)
a70beaf validation: when adding txs due to a block reorg, allow immediate relay (Anthony Towns)
1e9684f mempool_entry: add mempool entry sequence number (Anthony Towns)

Pull request description:

  This PR replaces the `m_recently_announced_invs` bloom filter with a simple sequence number tracking the mempool state when we last considered sending an INV message to a node. This saves 33kB per peer (or more if we raise the rate at which we relay transactions over the network, in which case we would need to increase the size of the bloom filter proportionally).

  The philosophy here (compare with bitcoin#18861 and bitcoin#19109) is that we consider the rate limiting on INV messages to only be about saving bandwidth and not protecting privacy, and therefore after you receive an INV message, it's immediately fair game to request any transaction that was in the mempool at the time the INV message was sent. We likewise consider the BIP 133 feefilter and BIP 37 bloom filters to be bandwidth optimisations here, and treat transactions as requestable if they would have been announced without those filters. Given that philosophy, tracking the timestamp of the last INV message and comparing that against the mempool entry time allows removal of each of `m_recently_announced_invs`, `m_last_mempool_req` and `UNCONDITIONAL_RELAY_DELAY` and associated logic.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Aug 2, 2025

Walkthrough

This change introduces a transaction sequence number to mempool entries and updates relay logic to use this sequence for transaction announcements and requests. The codebase is refactored to pass and track this sequence number throughout mempool entry creation, relay filtering, and peer management. Associated tests and utilities are updated to reflect the new constructor signatures and relay behavior.

Changes

Cohort / File(s) Change Summary
Mempool Entry Sequence Refactor
src/txmempool.cpp, src/txmempool.h, src/validation.cpp, src/node/interfaces.cpp, src/test/util/setup_common.cpp, src/bench/mempool_eviction.cpp, src/bench/mempool_stress.cpp, src/bench/rpc_mempool.cpp
Adds a uint64_t entry_sequence member to CTxMemPoolEntry, updates its constructor and all instantiations to include this parameter, and provides a getter. Updates tests and benchmarks to use the new constructor signature.
Relay Logic Overhaul
src/net_processing.cpp, src/txmempool.cpp, src/txmempool.h
Removes time-based unconditional relay delay and bloom filter tracking for recently announced transactions. Introduces sequence-based relay filtering using the new info_for_relay method and m_last_inv_sequence tracking. Updates peer management and transaction announcement logic accordingly.
Functional Test Enhancement
test/functional/mempool_reorg.py
Adds a test to verify correct relay behavior after a blockchain reorganization, ensuring transactions from disconnected blocks are handled and relayed according to the new sequence-based logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

  • The changes span core mempool data structures, peer relay logic, and multiple test and utility updates.
  • The relay logic overhaul and new sequence-based filtering require careful review for correctness and security.
  • Moderate complexity in adapting all constructor calls and ensuring backward compatibility in tests and benchmarks.
  • The new functional test introduces additional review for test coverage and correctness.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch backport-0.26-batch-647-pr-27675

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 generate unit tests to generate unit tests for 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.

@DashCoreAutoGuix
Copy link
Owner Author

❌ Backport Verification - Issues Detected

Original Bitcoin commit: 1f352cf2fd7
Reviewed commit hash: d35ee94413c-verify-1754127927

Critical Issues Found:

🚨 Massive Scope Explosion (1282% vs Expected 80-150%)

  • Bitcoin commit: 1 file, 17 changes (13 additions, 4 deletions)
  • Your PR: 10 files, 218 changes (142 additions, 76 deletions)
  • Size ratio: 1282.4% (should be 80-150%)

🚨 Fundamental Implementation Mismatch

What Bitcoin Did: Modified only test/functional/p2p_filter.py test file
What Your PR Does:

  • Completely reimplements mempool functionality across 10 core files
  • Modifies src/txmempool.cpp, src/net_processing.cpp, validation, benchmarks
  • Missing the actual Bitcoin test file test/functional/p2p_filter.py

🚨 CI Status: CRITICAL

  • 2 build failures: mac-build, lint failures
  • Critical CI status indicates implementation issues

Reviewer Feedback Analysis:

PastaPastaPasta comments reviewed: 0
Other human comments reviewed: 0

No reviewer feedback to address at this time.

Fundamental Problem:

This PR appears to be a completely different implementation that coincidentally shares the same title as Bitcoin PR bitcoin#27675. The actual Bitcoin commit 1f352cf2fd7 only extends a P2P filter test, but this Dash PR reimplements core mempool functionality.

Recommended Actions:

  1. Review the actual Bitcoin commit: git show 1f352cf2fd7 in Bitcoin repository
  2. Verify PR intent: Check if this is meant to be p2p: Drop m_recently_announced_invs bloom filter bitcoin/bitcoin#27675 or a different feature
  3. If p2p: Drop m_recently_announced_invs bloom filter bitcoin/bitcoin#27675: Start over with only the test file changes from Bitcoin
  4. If different feature: Update PR title and description to reflect actual changes
  5. Fix CI failures: Address mac-build and lint issues
  6. Size discipline: Any faithful backport should be ~17 lines, not 218 lines

This is not a faithful Bitcoin backport - it represents a fundamental implementation difference requiring complete rewrite or clarification of intent.

@DashCoreAutoGuix DashCoreAutoGuix added the needs-fixes Requires manual fixes to address verification issues label Aug 2, 2025
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: 5

🔭 Outside diff range comments (1)
src/net_processing.cpp (1)

2653-2674: Scope creep in transaction relay logic needs to be reverted

The changes in src/net_processing.cpp (lines 2653–2674) introduce a brand-new info_for_relay() call and sequence-number-based relay logic that do not appear in Bitcoin PR bitcoin#27675 (which only tweaked test/functional/p2p_filter.py). This is a fundamental alteration of core P2P behavior rather than a backport of the original 17-line test change.

Please revert or isolate these relay-mechanism changes so that this PR only contains the intended backport.

• Affected file:

  • src/net_processing.cpp (lines 2653–2674)

• Original Bitcoin change:

  • test/functional/p2p_filter.py only
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd589dd and d35ee94.

📒 Files selected for processing (10)
  • src/bench/mempool_eviction.cpp (1 hunks)
  • src/bench/mempool_stress.cpp (1 hunks)
  • src/bench/rpc_mempool.cpp (1 hunks)
  • src/net_processing.cpp (5 hunks)
  • src/node/interfaces.cpp (1 hunks)
  • src/test/util/setup_common.cpp (2 hunks)
  • src/txmempool.cpp (2 hunks)
  • src/txmempool.h (4 hunks)
  • src/validation.cpp (1 hunks)
  • test/functional/mempool_reorg.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit Inference Engine (CLAUDE.md)

C++20 codebase should be placed under src/

Files:

  • src/node/interfaces.cpp
  • src/bench/mempool_stress.cpp
  • src/test/util/setup_common.cpp
  • src/validation.cpp
  • src/txmempool.h
  • src/bench/rpc_mempool.cpp
  • src/bench/mempool_eviction.cpp
  • src/txmempool.cpp
  • src/net_processing.cpp
**

⚙️ CodeRabbit Configuration File

**: # CodeRabbit AI Review Instructions for Dash Backports

Your Role

You are reviewing Bitcoin Core backports to Dash Core. Your ONLY job is to validate that the Dash commit faithfully represents the original Bitcoin commit with minimal, necessary adaptations.

Critical Validation Rules

1. File Operations Must Match (AUTO-REJECT if violated)

  • If Bitcoin modifies an existing file → Dash MUST modify (not create new)
  • If Bitcoin creates a new file → Dash creates
  • If Bitcoin deletes a file → Dash deletes
  • Common failure: Bitcoin modifies keys.txt, Dash creates new file with 58 keys

2. Size Ratio Check (80-150% of Bitcoin)

  • Count functional lines changed (exclude comments/whitespace)
  • Dash changes should be 80-150% of Bitcoin's size
  • Red flag: 2-line Bitcoin fix becoming 150+ lines in Dash

3. No Scope Creep

  • Reject if you see: "TODO:", "FIXME:", "while we're here", "also fix"
  • No unrelated refactoring or style changes
  • Only Bitcoin's intended changes + minimal Dash adaptations

4. Bitcoin-Specific Code Detection

  • Auto-reject witness/segwit code: msg_wtxidrelay, MSG_WTX, witness imports
  • Auto-reject RBF (replace-by-fee) functionality
  • Note: PSBT is supported in Dash (don't flag)

5. Mandatory Adaptations Only

  • bitcoindash in strings/paths
  • BitcoinDash in user-facing text
  • Port numbers: 8332→9998 (RPC), 8333→9999 (P2P)
  • Hardcoded test values specific to Dash
  • No other changes unless absolutely required

6. Completeness Check

  • All files changed in Bitcoin must be present
  • Extra files need clear justification (Dash-specific compatibility)
  • Missing files = incomplete backport

Review Process

  1. First: Check file operations match exactly
  2. Second: Calculate size ratio
  3. Third: Scan for scope creep patterns
  4. Fourth: Detect Bitcoin-specific code
  5. Fifth: Verify all changes are minimal adaptations

Output Format

VALIDATION: [PASS/FAIL]

File Operatio...

Files:

  • src/node/interfaces.cpp
  • src/bench/mempool_stress.cpp
  • src/test/util/setup_common.cpp
  • src/validation.cpp
  • src/txmempool.h
  • test/functional/mempool_reorg.py
  • src/bench/rpc_mempool.cpp
  • src/bench/mempool_eviction.cpp
  • src/txmempool.cpp
  • src/net_processing.cpp
src/bench/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Performance benchmarks should be placed in src/bench/ and use nanobench

Files:

  • src/bench/mempool_stress.cpp
  • src/bench/rpc_mempool.cpp
  • src/bench/mempool_eviction.cpp
src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Unit tests should be placed in src/test/, src/wallet/test/, or src/qt/test/ and use Boost::Test or Qt 5 for GUI tests

Files:

  • src/test/util/setup_common.cpp
test/functional/**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

Functional tests should be placed in test/functional/ and written in Python

Files:

  • test/functional/mempool_reorg.py
🧠 Learnings (11)
📓 Common learnings
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T22:03:12.364Z
Learning: During multiple verification attempts of Bitcoin Core commit 06d469c26b backport to Dash PR #566, DashCoreAutoGuix consistently identified scope creep in interface_usdt_utxocache.py where additional pruning test functionality was added beyond the original Bitcoin commit. The user provided comprehensive fixes including both scope creep removal and missing mempool test file additions, but couldn't push due to authentication restrictions. The scope creep fix was identified as the priority to resolve CI failures.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T20:34:29.061Z
Learning: During Dash backport verification of Bitcoin Core commit 06d469c26b, scope creep was detected when additional pruning test functionality was added to interface_usdt_utxocache.py beyond what was in the original Bitcoin commit. The fix involved removing the extra test block while maintaining the core compiler flag fixes for USDT compilation errors.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-31T01:14:55.631Z
Learning: DashCoreAutoGuix successfully completed a complex Bitcoin Core backport (PR #29412) for block mutation detection by implementing the IsBlockMutated function, adding net processing integration, creating comprehensive unit tests, and properly adapting all Bitcoin-specific witness code for Dash compatibility. The backport maintains full security functionality while respecting Dash's non-witness transaction architecture.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T21:29:32.827Z
Learning: DashCoreAutoGuix successfully fixed scope creep in Bitcoin Core commit fcdb39d3ee backport by removing the parse test case from src/test/uint256_tests.cpp that was not part of the original Bitcoin commit. The fix was implemented in commit 16748115ce and verified through range-diff analysis.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T19:54:21.426Z
Learning: In Dash backports from Bitcoin Core, including necessary compilation fixes (such as API compatibility changes like UniValue get_int() → getInt<int>()) alongside the core backport is standard and expected practice. These compatibility fixes ensure the backported code compiles in Dash's evolved codebase while preserving Bitcoin's original functionality and intent.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-27T22:35:10.176Z
Learning: In Dash backports, src/dashbls files are vendored dependencies that should not be modified during Bitcoin Core backports unless there is specific justification. Unauthorized modifications to vendored dependencies should be removed to maintain code integrity.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T22:13:54.797Z
Learning: In Dash backports from Bitcoin Core, witness transaction-related code (MSG_WTX, wtxid) should be replaced with regular transaction handling (MSG_TX, txid) for compatibility, as demonstrated in the p2p_filter.py test fix where MSG_WTX was replaced with MSG_TX and irr_wtxid usage was replaced with irr_txid.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T17:13:35.087Z
Learning: When backporting Bitcoin Core commits that use Python's textwrap.dedent() function in test files, the textwrap import statement needs to be explicitly added if it's missing in the Dash test file.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-30T14:45:15.700Z
Learning: In Dash backports from Bitcoin Core test files, the `address_to_scriptpubkey` function should be imported from `test_framework.wallet` instead of `test_framework.address` as the import location differs between Bitcoin and Dash test frameworks.
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T17:13:35.087Z
Learning: In Dash backports from Bitcoin Core, when the DIFFICULTY_ADJUSTMENT_INTERVAL constant is missing, it should be defined as 24 for Dash (different from Bitcoin's value), as seen in the getnetworkhashps RPC backport fix.
Learnt from: CR
PR: DashCoreAutoGuix/dash#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T23:09:09.522Z
Learning: Applies to src/evo/specialtx.h : Special transactions use payload extensions as defined in src/evo/specialtx.h
📚 Learning: during multiple verification attempts of bitcoin core commit 06d469c backport to dash pr #566, da...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T22:03:12.364Z
Learning: During multiple verification attempts of Bitcoin Core commit 06d469c26b backport to Dash PR #566, DashCoreAutoGuix consistently identified scope creep in interface_usdt_utxocache.py where additional pruning test functionality was added beyond the original Bitcoin commit. The user provided comprehensive fixes including both scope creep removal and missing mempool test file additions, but couldn't push due to authentication restrictions. The scope creep fix was identified as the priority to resolve CI failures.

Applied to files:

  • src/bench/mempool_stress.cpp
  • src/test/util/setup_common.cpp
  • test/functional/mempool_reorg.py
  • src/bench/rpc_mempool.cpp
  • src/bench/mempool_eviction.cpp
  • src/net_processing.cpp
📚 Learning: during dash backport verification of bitcoin core commit 06d469c, scope creep was detected when a...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-28T20:34:29.061Z
Learning: During Dash backport verification of Bitcoin Core commit 06d469c26b, scope creep was detected when additional pruning test functionality was added to interface_usdt_utxocache.py beyond what was in the original Bitcoin commit. The fix involved removing the extra test block while maintaining the core compiler flag fixes for USDT compilation errors.

Applied to files:

  • src/bench/mempool_stress.cpp
  • src/test/util/setup_common.cpp
  • test/functional/mempool_reorg.py
  • src/bench/rpc_mempool.cpp
📚 Learning: applies to src/evo/specialtx.h : special transactions use payload extensions as defined in src/evo/s...
Learnt from: CR
PR: DashCoreAutoGuix/dash#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T23:09:09.522Z
Learning: Applies to src/evo/specialtx.h : Special transactions use payload extensions as defined in src/evo/specialtx.h

Applied to files:

  • src/bench/mempool_stress.cpp
  • src/test/util/setup_common.cpp
  • src/txmempool.h
  • src/bench/mempool_eviction.cpp
📚 Learning: dashcoreautoguix successfully fixed scope creep in bitcoin core commit fcdb39d backport by removi...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T21:29:32.827Z
Learning: DashCoreAutoGuix successfully fixed scope creep in Bitcoin Core commit fcdb39d3ee backport by removing the parse test case from src/test/uint256_tests.cpp that was not part of the original Bitcoin commit. The fix was implemented in commit 16748115ce and verified through range-diff analysis.

Applied to files:

  • src/test/util/setup_common.cpp
  • src/net_processing.cpp
📚 Learning: applies to src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp} : unit tests should be placed in s...
Learnt from: CR
PR: DashCoreAutoGuix/dash#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T23:09:09.522Z
Learning: Applies to src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp} : Unit tests should be placed in src/test/, src/wallet/test/, or src/qt/test/ and use Boost::Test or Qt 5 for GUI tests

Applied to files:

  • src/test/util/setup_common.cpp
📚 Learning: in dash backports from bitcoin core, witness transaction-related code (msg_wtx, wtxid) should be rep...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T22:13:54.797Z
Learning: In Dash backports from Bitcoin Core, witness transaction-related code (MSG_WTX, wtxid) should be replaced with regular transaction handling (MSG_TX, txid) for compatibility, as demonstrated in the p2p_filter.py test fix where MSG_WTX was replaced with MSG_TX and irr_wtxid usage was replaced with irr_txid.

Applied to files:

  • test/functional/mempool_reorg.py
  • src/net_processing.cpp
📚 Learning: when backporting bitcoin core commits that use python's textwrap.dedent() function in test files, th...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-29T17:13:35.087Z
Learning: When backporting Bitcoin Core commits that use Python's textwrap.dedent() function in test files, the textwrap import statement needs to be explicitly added if it's missing in the Dash test file.

Applied to files:

  • test/functional/mempool_reorg.py
📚 Learning: the `add_wallet_options` method is not available in dash's test framework and should be removed when...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-30T14:45:15.700Z
Learning: The `add_wallet_options` method is not available in Dash's test framework and should be removed when backporting Bitcoin Core tests that use this method, as demonstrated in wallet_rescan_unconfirmed.py.

Applied to files:

  • test/functional/mempool_reorg.py
📚 Learning: dashcoreautoguix successfully completed a complex bitcoin core backport (pr bitcoin#29412) for block mutati...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-31T01:14:55.631Z
Learning: DashCoreAutoGuix successfully completed a complex Bitcoin Core backport (PR #29412) for block mutation detection by implementing the IsBlockMutated function, adding net processing integration, creating comprehensive unit tests, and properly adapting all Bitcoin-specific witness code for Dash compatibility. The backport maintains full security functionality while respecting Dash's non-witness transaction architecture.

Applied to files:

  • test/functional/mempool_reorg.py
  • src/net_processing.cpp
📚 Learning: in dash backports from bitcoin core test files, the `address_to_scriptpubkey` function should be imp...
Learnt from: DashCoreAutoGuix
PR: DashCoreAutoGuix/dash#0
File: :0-0
Timestamp: 2025-07-30T14:45:15.700Z
Learning: In Dash backports from Bitcoin Core test files, the `address_to_scriptpubkey` function should be imported from `test_framework.wallet` instead of `test_framework.address` as the import location differs between Bitcoin and Dash test frameworks.

Applied to files:

  • test/functional/mempool_reorg.py
🧬 Code Graph Analysis (2)
src/txmempool.h (2)
src/txmempool.cpp (2)
  • info_for_relay (1331-1340)
  • info_for_relay (1331-1331)
src/node/interfaces.cpp (6)
  • txid (892-897)
  • txid (892-892)
  • txid (898-904)
  • txid (898-898)
  • txid (913-918)
  • txid (913-913)
src/bench/mempool_eviction.cpp (2)
src/txmempool.cpp (1)
  • CTxMemPoolEntry (51-69)
src/txmempool.h (1)
  • CTxMemPoolEntry (98-140)
🪛 Ruff (0.12.2)
test/functional/mempool_reorg.py

36-36: Missing return type annotation for public function test_reorg_relay

Add return type annotation: None

(ANN201)


111-111: Missing return type annotation for public function run_test

Add return type annotation: None

(ANN201)

⏰ 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). (3)
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: win64-build / Build source
🔇 Additional comments (11)
src/node/interfaces.cpp (1)

928-928: Please verify constructor update against Bitcoin Core PR bitcoin#27675

The extra 0 parameter for entry_sequence on line 928 of src/node/interfaces.cpp aligns with the mempool sequence‐tracking feature, but the local history doesn’t include Bitcoin Core PR bitcoin#27675. Before merging, confirm that this change exactly matches the upstream diff and that no unrelated scope creep was introduced.

  • Verify that Bitcoin Core PR bitcoin#27675 modifies the CTxMemPoolEntry constructor call in src/node/interfaces.cpp at line 928.
  • Ensure no additional changes beyond that PR were pulled into this backport.
src/validation.cpp (1)

856-857: Ignore scope mismatch warning—validation.cpp is modified in Bitcoin PR bitcoin#27675

Fetching the PR details confirms that Bitcoin Core PR bitcoin#27675 changes 15 files (151 additions, 91 deletions), including src/validation.cpp. The backport’s update to CTxMemPoolEntry construction therefore aligns with the original Bitcoin commit’s scope.

src/validation.cpp is listed among the files modified by PR bitcoin#27675
• Total files changed in the original PR: 15 (not just a single test file)

No further action needed—this change matches the upstream implementation.

Likely an incorrect or invalid review comment.

src/bench/mempool_eviction.cpp (1)

15-21: Constructor adaptation matches upstream PR bitcoin#27675

The addition of uint64_t sequence = 0 and its insertion into the CTxMemPoolEntry constructor exactly mirrors the Bitcoin Core PR bitcoin#27675 diff for src/bench/mempool_eviction.cpp. No extra changes have been introduced.

• Bitcoin patch snippet (PR bitcoin#27675):

 static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& pool)
 {
     int64_t nTime = 0;
     unsigned int nHeight = 1;
+    uint64_t sequence = 0;
     bool spendsCoinbase = false;
     unsigned int sigOpCost = 4;
     LockPoints lp;
     pool.addUnchecked(CTxMemPoolEntry(
-        tx, nFee, nTime, nHeight,
+        tx, nFee, nTime, nHeight, sequence,
         spendsCoinbase, sigOpCost, lp));
 }

• Our backport matches this change exactly (using Dash’s sigOps alias).

No further action required.

src/bench/rpc_mempool.cpp (1)

17-17: LGTM - Clean constructor adaptation.

The inline parameter comments make the constructor call very readable, and the addition of entry_sequence=0 is consistent with the constructor signature change.

src/bench/mempool_stress.cpp (1)

17-21: Consistent constructor adaptation across benchmark files.

The pattern of adding a local sequence variable and passing it to the CTxMemPoolEntry constructor is consistent with the previous benchmark files, indicating a coordinated codebase update.

src/test/util/setup_common.cpp (3)

659-659: Test utility constructor update is mechanically correct.

The addition of the sequence parameter (0) to the CTxMemPoolEntry constructor in the test utility is consistent with the constructor signature change.


673-674: Helper function correctly adapted to new constructor signature.

The TestMemPoolEntryHelper::FromTx method properly includes the new sequence parameter (0) in the constructor call.


659-674: Scope assessment incorrect—no scope creep
The original Bitcoin Core PR bitcoin#27675 modified 15 files (benchmarks, net_processing, node interfaces, txmempool, validation, and tests), not just a 17-line test update. Your backport mirrors that same set of changes across core and test code. No drastic scope reduction is needed—please proceed.

Likely an incorrect or invalid review comment.

src/txmempool.cpp (1)

51-59: Cannot verify original Bitcoin commit; manual validation required

The commit ID 1f352cf2fd7 isn’t present in the local history, so we can’t inspect the original 17-line change. Please:

  • Confirm you’ve referenced the correct Bitcoin Core commit or branch.
  • Fetch the upstream repository (e.g. git fetch upstream) and run git show <commit> to review the exact diff.
  • Ensure this PR only includes the minimal bloom-filter removal from the original, without introducing new constructor or architectural changes (e.g. the added entry_sequence parameter in CTxMemPoolEntry).

Once you’ve validated the true upstream diff, please adjust this backport to match that scope or document why any extra changes are necessary.

src/txmempool.h (1)

1-1053: Unable to Verify Bitcoin Commit Reference

I attempted to locate commit 1f352cf2fd7 in the repository but it was not found. Please confirm that the commit hash is correct and accessible in this branch, or provide the exact Bitcoin commit details for backport validation.

src/net_processing.cpp (1)

1-6331: Incorrect backport assumption—ignore previous feedback

The changes in this PR correspond to Bitcoin Core PR bitcoin#27675, which adds an entry_sequence field to CTxMemPoolEntry and integrates it into net_processing.cpp to control how recently‐added transactions are relayed. The earlier review compared against the wrong Bitcoin PR (which only touched a test file) and is not applicable here.

Likely an incorrect or invalid review comment.

Comment on lines +309 to 312
/** The mempool sequence num at which we sent the last `inv` message to this peer.
* Can relay txs with lower sequence numbers than this (see CTxMempool::info_for_relay). */
uint64_t m_last_inv_sequence GUARDED_BY(NetEventsInterface::g_msgproc_mutex){1};
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

VALIDATION: FAIL - Not a faithful backport of Bitcoin PR bitcoin#27675

This change introduces mempool sequence tracking to the relay logic, which is not part of the original Bitcoin PR bitcoin#27675. The original Bitcoin commit only modified a test file (test/functional/p2p_filter.py) with 17 lines of changes, not core relay logic.

🤖 Prompt for AI Agents
In src/net_processing.cpp around lines 309 to 312, remove the addition of
mempool sequence tracking variables and related relay logic changes, as these
were not part of the original Bitcoin PR #27675. Revert the code to match the
original Bitcoin commit, which only modified the test/functional/p2p_filter.py
file without altering core relay logic.

Comment on lines +1002 to +1003
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const uint256& txid)
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Major API change not present in original Bitcoin PR

The FindTxForGetData method signature has been completely changed to use sequence-based relay instead of time-based relay. This is not part of Bitcoin PR bitcoin#27675 which only touched test files.

🤖 Prompt for AI Agents
In src/net_processing.cpp at lines 1002-1003, the method signature of
FindTxForGetData has been changed to use sequence-based relay instead of the
original time-based relay, which deviates from the original Bitcoin PR #27675.
To fix this, revert the method signature and implementation to match the
original PR by using time-based relay parameters and logic, ensuring consistency
with the upstream Bitcoin codebase.

Comment on lines +6136 to 6139
// Ensure we'll respond to GETDATA requests for anything we've just announced
LOCK(m_mempool.cs);
tx_relay->m_last_inv_sequence = m_mempool.GetSequence();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Sequence number tracking after inventory announcements

Updates m_last_inv_sequence after sending transaction inventories. This sequence-based approach is completely different from the bloom filter mechanism it replaces and is not part of the original Bitcoin PR bitcoin#27675.

🤖 Prompt for AI Agents
In src/net_processing.cpp around lines 6136 to 6139, the code updates
m_last_inv_sequence after sending transaction inventories, which uses a
sequence-based approach different from the previous bloom filter mechanism and
is not part of the original Bitcoin PR #27675. Review this change to ensure it
aligns with the intended design; if the sequence tracking is required, confirm
it is correctly synchronized with m_mempool and properly documented to clarify
its purpose and difference from the bloom filter method.

Comment on lines +1331 to +1340
TxMempoolInfo CTxMemPool::info_for_relay(const uint256& txid, uint64_t last_sequence) const
{
LOCK(cs);
indexed_transaction_set::const_iterator i = mapTx.find(txid);
if (i != mapTx.end() && i->GetSequence() < last_sequence) {
return GetInfo(i);
} else {
return TxMempoolInfo();
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Additional scope creep in new method implementation.

The info_for_relay method represents new functionality for sequence-based relay filtering, which is not consistent with a simple bloom filter removal as described in the original Bitcoin PR bitcoin#27675.

This method implements entirely new relay logic rather than removing existing bloom filter code. Combined with the constructor changes, this confirms the PR is a complete reimplementation rather than a faithful backport.

The original Bitcoin commit should be reviewed to determine if these changes align with the intended scope, or if this PR needs to be rewritten to match the actual Bitcoin changes.

🤖 Prompt for AI Agents
In src/txmempool.cpp around lines 1331 to 1340, the info_for_relay method
introduces new sequence-based relay filtering logic that deviates from the
original Bitcoin PR #27675's scope, which focused on removing bloom filter code.
Review the original Bitcoin commit to verify the intended changes and adjust
this method accordingly to either remove bloom filter logic as originally
intended or rewrite this PR to align with the actual Bitcoin changes, avoiding
adding unrelated new relay logic.

Comment on lines +36 to +110
def test_reorg_relay(self):
self.log.info("Test that transactions from disconnected blocks are available for relay immediately")
# Prevent time from moving forward
self.nodes[1].setmocktime(int(time.time()))
self.connect_nodes(0, 1)
self.generate(self.wallet, 3)

# Disconnect node0 and node1 to create different chains.
self.disconnect_nodes(0, 1)
# Connect a peer to node1, which doesn't have immediate tx relay
peer1 = self.nodes[1].add_p2p_connection(P2PTxInvStore())

# Create a transaction that is included in a block.
tx_disconnected = self.wallet.send_self_transfer(from_node=self.nodes[1])
self.generate(self.nodes[1], 1, sync_fun=self.no_op)

# Create a transaction and submit it to node1's mempool.
tx_before_reorg = self.wallet.send_self_transfer(from_node=self.nodes[1])

# Create a child of that transaction and submit it to node1's mempool.
tx_child = self.wallet.send_self_transfer(utxo_to_spend=tx_disconnected["new_utxo"], from_node=self.nodes[1])
assert_equal(self.nodes[1].getmempoolentry(tx_child["txid"])["ancestorcount"], 1)
assert_equal(len(peer1.get_invs()), 0)

# node0 has a longer chain in which tx_disconnected was not confirmed.
self.generate(self.nodes[0], 3, sync_fun=self.no_op)

# Reconnect the nodes and sync chains. node0's chain should win.
self.connect_nodes(0, 1)
self.sync_blocks()

# Child now has an ancestor from the disconnected block
assert_equal(self.nodes[1].getmempoolentry(tx_child["txid"])["ancestorcount"], 2)
assert_equal(self.nodes[1].getmempoolentry(tx_before_reorg["txid"])["ancestorcount"], 1)

# peer1 should not have received an inv for any of the transactions during this time, as not
# enough time has elapsed for those transactions to be announced. Likewise, it cannot
# request very recent, unanounced transactions.
assert_equal(len(peer1.get_invs()), 0)
# It's too early to request these two transactions
requests_too_recent = msg_getdata([CInv(t=MSG_TX, h=int(tx["txid"], 16)) for tx in [tx_before_reorg, tx_child]])
peer1.send_and_ping(requests_too_recent)
for _ in range(len(requests_too_recent.inv)):
peer1.sync_with_ping()
with p2p_lock:
assert "tx" not in peer1.last_message
assert "notfound" in peer1.last_message

# Request the tx from the disconnected block
request_disconnected_tx = msg_getdata([CInv(t=MSG_TX, h=int(tx_disconnected["txid"], 16))])
peer1.send_and_ping(request_disconnected_tx)

# The tx from the disconnected block was never announced, and it entered the mempool later
# than the transactions that are too recent.
assert_equal(len(peer1.get_invs()), 0)
with p2p_lock:
# However, the node will answer requests for the tx from the recently-disconnected block.
assert_equal(peer1.last_message["tx"].tx.sha256, int(tx_disconnected["txid"], 16))

self.nodes[1].setmocktime(int(time.time()) + 30)
peer1.sync_with_ping()
# the transactions are now announced
assert_equal(len(peer1.get_invs()), 3)
for _ in range(3):
# make sure all tx requests have been responded to
peer1.sync_with_ping()
last_tx_received = peer1.last_message["tx"]

tx_after_reorg = self.wallet.send_self_transfer(from_node=self.nodes[1])
request_after_reorg = msg_getdata([CInv(t=MSG_TX, h=int(tx_after_reorg["txid"], 16))])
assert tx_after_reorg["txid"] in self.nodes[1].getrawmempool()
peer1.send_and_ping(request_after_reorg)
with p2p_lock:
assert_equal(peer1.last_message["tx"], last_tx_received)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

File operation mismatch confirmed

This test is being added to mempool_reorg.py, but Bitcoin PR bitcoin#27675 only modifies test/functional/p2p_filter.py. This test appears to validate the new mempool sequence number functionality which is not part of the original Bitcoin commit.

The test itself has implementation issues if this functionality were to be kept:

  1. Line 40: time.time() should use self.mocktime for consistency
  2. Line 95: Magic number 30 should be a named constant
  3. The test validates sequence-based relay logic that doesn't exist in Bitcoin PR p2p: Drop m_recently_announced_invs bloom filter bitcoin/bitcoin#27675
🧰 Tools
🪛 Ruff (0.12.2)

36-36: Missing return type annotation for public function test_reorg_relay

Add return type annotation: None

(ANN201)

🤖 Prompt for AI Agents
In test/functional/mempool_reorg.py from lines 36 to 110, replace the use of
time.time() at line 40 with self.mocktime to maintain consistent mock time
usage. At line 95, replace the magic number 30 with a descriptive named constant
to improve code clarity. Additionally, since the sequence-based relay logic
tested here is not part of Bitcoin PR #27675, either remove this test or
refactor it to align with the actual functionality introduced in that PR.

@DashCoreAutoGuix
Copy link
Owner Author

❌ Backport Verification - CATASTROPHIC FAILURE

Original Bitcoin commit: 1f352cf2fd7 (bitcoin#27675: p2p: Drop m_recently_announced_invs bloom filter)
Reviewed commit hash: 88231b1ac40-verify-1754128313

CRITICAL VIOLATIONS DETECTED:

🚨 Scope Explosion Violation

  • Bitcoin commit: 1 file, 17 changes (13 additions, 4 deletions)
  • Your PR: 10 files, 218 changes (142 additions, 76 deletions)
  • Size ratio: 1282.4% (should be 80-150%)

🚨 File Operation Mismatch

  • 10 EXTRA FILES modified that don't exist in Bitcoin commit
  • Bitcoin only touched: test/functional/p2p_filter.py
  • Your PR modifies entire mempool implementation across src/ and benchmark files

🚨 Intent Violation

What Bitcoin Did: Modified a single test file to extend MEMPOOL msg functional test coverage for bloom filter removal
What Your PR Does:

  • Modifies core mempool implementation in src/txmempool.cpp and src/txmempool.h
  • Changes net processing logic in src/net_processing.cpp
  • Updates validation logic in src/validation.cpp
  • Modifies benchmark files across src/bench/
  • Changes node interfaces in src/node/interfaces.cpp
  • Updates test setup utilities

🚨 CI Status: CATASTROPHIC

  • 3 build failures across all platforms (linux64_fuzz-build, mac-build, Lint)
  • All builds failing due to fundamental issues

🚨 Reviewer Feedback Analysis

PastaPastaPasta comments reviewed: 0
Other human comments reviewed: 0

🚨 Auto-Reject Conditions Met

  • File operation mismatch: Bitcoin modifies 1 test file, Dash modifies 10 core implementation files
  • Scope explosion: 1282.4% size increase (>500% threshold)
  • Intent violation: Test file change becomes core implementation rewrite
  • CI catastrophic: 3+ build failures
  • Missing original file: test/functional/p2p_filter.py not included

Required Action: COMPLETE REWRITE

This PR violates EVERY fundamental principle of faithful backporting:

  1. Start over: Discard current changes completely
  2. Study Bitcoin commit: Only implement the test file modification in test/functional/p2p_filter.py
  3. Scope discipline: Zero changes to core mempool, net processing, or validation code
  4. Size validation: Aim for ~17 lines total, not 218

Example of correct scope:

Only file that should change:
test/functional/p2p_filter.py | 17 +++++++++++++----

This PR represents a fundamental misunderstanding of Bitcoin commit 1f352cf2fd7. Please review the actual Bitcoin changes and implement ONLY the test file modifications.

Status: REJECTED - Requires complete rewrite


🚫 This PR has been automatically closed due to catastrophic validation failures. Please create a new PR with a proper backport implementation.

@DashCoreAutoGuix
Copy link
Owner Author

Automatically closed due to catastrophic validation failures. Please see the detailed analysis above and create a new PR with a proper backport implementation.

@DashCoreAutoGuix DashCoreAutoGuix added the invalid This doesn't seem right label Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right needs-fixes Requires manual fixes to address verification issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants