Skip to content

test: p2p: add test for rejected tx request logic (m_recent_rejects filter) - #29827

Closed
theStack wants to merge 2 commits into
bitcoin:masterfrom
theStack:202404-test-p2p-check_rejected_tx_requests
Closed

theStack wants to merge 2 commits into
bitcoin:masterfrom
theStack:202404-test-p2p-check_rejected_tx_requests

Conversation

@theStack

@theStack theStack commented Apr 7, 2024 •

Copy link
Copy Markdown
Contributor

Motivated by the discussion in #28970 (#28970 (comment)), this PR adds test coverage for the logic around the m_recent_rejects filter, in particular that the filter is cleared after a new block comes in:

bitcoin/src/net_processing.cpp

Lines 2199 to 2206 in f0794cb

if (m_chainman.ActiveChain().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
// If the chain tip has changed previously rejected transactions
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
// or a double-spend. Reset the rejects filter and give those
// txs a second chance.
hashRecentRejectsChainTip = m_chainman.ActiveChain().Tip()->GetBlockHash();
m_recent_rejects.reset();
}

As expected, the second part of the test fails if the following patch is applied:

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 6996af38cb..5cb1090e70 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2202,7 +2202,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
         // or a double-spend. Reset the rejects filter and give those
         // txs a second chance.
         hashRecentRejectsChainTip = m_chainman.ActiveChain().Tip()->GetBlockHash();
-        m_recent_rejects.reset();
+        //m_recent_rejects.reset();
     }
 
     const uint256& hash = gtxid.GetHash();

I'm still not sure in which file this test fits best, and if there is already test coverage for the first part of the test somewhere. Happy for any suggestions.

@DrahtBot

DrahtBot commented Apr 7, 2024 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, glozow, instagibbs

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@DrahtBot DrahtBot added the Tests label Apr 7, 2024

@glozow glozow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

concept ACK thanks! Maybe p2p_invalid_tx.py would be a good file but no strong opinion

Comment thread test/functional/p2p_tx_download.py Resolved
Comment thread test/functional/p2p_tx_download.py Resolved
Comment thread test/functional/p2p_tx_download.py Resolved
@theStack
theStack force-pushed the 202404-test-p2p-check_rejected_tx_requests branch from e9122b7 to 27a5a5f Compare April 9, 2024 14:40
@theStack

theStack commented Apr 9, 2024

Copy link
Copy Markdown
Contributor Author

This PR is based on #29735 now in order to take use of the fill_mempool (see #29827 (comment)). Note that I had issues with this helper due to tx_to_be_evicted not being evicted (failed assertion assert tx_to_be_evicted_id not in node.getrawmempool()), as the mempool filling txs spent that newly created coin again; fixed by the first commit.

@instagibbs

Copy link
Copy Markdown
Member

concept ack, will review once parent PR is merged

@theStack
theStack force-pushed the 202404-test-p2p-check_rejected_tx_requests branch from 27a5a5f to cdc8283 Compare April 11, 2024 13:13

@glozow glozow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI failure looks related to the lines added here (I haven't debugged though)

Comment thread test/functional/p2p_tx_download.py Resolved
Comment thread test/functional/test_framework/util.py Resolved
Comment thread test/functional/p2p_tx_download.py Resolved
@theStack
theStack force-pushed the 202404-test-p2p-check_rejected_tx_requests branch 2 times, most recently from 0c3dca4 to 01b17b6 Compare April 15, 2024 14:34

@instagibbs instagibbs 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.

ACK 01b17b62cbeb168629d17eb2a54d547628e16759

Comment thread test/functional/rpc_packages.py Outdated

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.

is this strictly necessary since the mempool is empty?

fine to me to add as belt and suspenders either way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is this strictly necessary since the mempool is empty?

Good point. Without that change the test fails, but not for the reason I thought it does. I think the problem is that MiniWallet is not aware of restarts between nodes and still holds mempool UTXOs that it tries to spend. Will force-push in a bit with a fix that does a self.wallet.rescan_utxos() after restarts, which should tackle the problem as the root.

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.

micro-nit: this line can be removed safely now 🥳

Comment thread test/functional/test_framework/util.py Resolved
@DrahtBot
DrahtBot requested a review from glozow April 15, 2024 15:47
@theStack
theStack force-pushed the 202404-test-p2p-check_rejected_tx_requests branch from 01b17b6 to 433cdbf Compare April 15, 2024 16:28
@theStack
theStack force-pushed the 202404-test-p2p-check_rejected_tx_requests branch from 433cdbf to 60ca5d5 Compare April 15, 2024 20:49
@maflcko

maflcko commented Apr 18, 2024

Copy link
Copy Markdown
Member

ACK 60ca5d5 🍳

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 60ca5d55081275a011ccfc9546e0c4a8c4030493 🍳
w8iRdk8dg+qdlaW4opc/RAillh5l170CUg7VjSLLc06XOoXzYZuVBpqlMM0f/0oiInwKH5sWWdw6EZbyHp7ECA==

@DrahtBot
DrahtBot requested a review from instagibbs April 18, 2024 06:59

@glozow glozow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code review ACK 60ca5d5

@instagibbs instagibbs 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.

ACK 60ca5d5

please don't feel obligated to touch due to nit

Comment thread test/functional/rpc_packages.py Outdated

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.

micro-nit: this line can be removed safely now 🥳

Fabcien pushed a commit to Fabcien/bitcoin that referenced this pull request Apr 19, 2024
…c (`m_recent_rejects` filter)

60ca5d5 test: p2p: add test for rejected tx request logic (`m_recent_rejects` filter) (Sebastian Falbesoner)
e9dc511 fixup: get all utxos up front in fill_mempool, discourage wallet mixing (glozow)

Pull request description:

  Motivated by the discussion in bitcoin#28970 (bitcoin#28970 (comment)), this PR adds test coverage for the logic around the `m_recent_rejects` filter, in particular that the filter is cleared after a new block comes in:
  https://github.com/bitcoin/bitcoin/blob/f0794cbd405636a7f528a60f2873050b865cf7e8/src/net_processing.cpp#L2199-L2206

  As expected, the second part of the test fails if the following patch is applied:
  ```diff
  diff --git a/src/net_processing.cpp b/src/net_processing.cpp
  index 6996af3..5cb1090e70 100644
  --- a/src/net_processing.cpp
  +++ b/src/net_processing.cpp
  @@ -2202,7 +2202,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
           // or a double-spend. Reset the rejects filter and give those
           // txs a second chance.
           hashRecentRejectsChainTip = m_chainman.ActiveChain().Tip()->GetBlockHash();
  -        m_recent_rejects.reset();
  +        //m_recent_rejects.reset();
       }

       const uint256& hash = gtxid.GetHash();
  ```
  I'm still not sure in which file this test fits best, and if there is already test coverage for the first part of the test somewhere. Happy for any suggestions.

ACKs for top commit:
  maflcko:
    ACK 60ca5d5 🍳
  glozow:
    code review ACK 60ca5d5
  instagibbs:
    ACK 60ca5d5

Tree-SHA512: 9cab43858e8f84db04a708151e6775c9cfc68c20ff53096220eac0b2c406f31aaf9223e8e04be345e95bf0a3f6dd15efac50b0ebeb1582a48a4560b3ab0bcba5
@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@glozow

glozow commented Apr 19, 2024

Copy link
Copy Markdown
Contributor

merged, I think there is a github error 67c0d93

@glozow glozow closed this Apr 19, 2024
@instagibbs

Copy link
Copy Markdown
Member

Seeing a failure of this test in my other PR, though I can't make heads or tails of the failure: https://cirrus-ci.com/task/6740372997537792

@theStack
theStack deleted the 202404-test-p2p-check_rejected_tx_requests branch April 19, 2024 20:50
# the next trickle relay event happens.
for test in [self.test_in_flight_max, self.test_inv_block, self.test_tx_requests]:
for test in [self.test_in_flight_max, self.test_inv_block, self.test_tx_requests,
self.test_rejects_filter_reset]:

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.

Putting this here will spin up NUM_INBOUND * self.num_nodes, which seems confusing, because they are not needed.

Also, it will cause the test thread to sync all generated blocks, blocking shutdown, and causing intermittent test failures.

Fixed in #29933

achow101 added a commit that referenced this pull request May 9, 2024
…ng, use in `fill_mempool`

dd8fa86 test: use tagged ephemeral MiniWallet instance in fill_mempool (Sebastian Falbesoner)
b2037ad test: add MiniWallet tagging support to avoid UTXO mixing (Sebastian Falbesoner)
c8e6d08 test: refactor: eliminate COINBASE_MATURITY magic number in fill_mempool (Sebastian Falbesoner)
4f34714 test: refactor: move fill_mempool to new module mempool_util (Sebastian Falbesoner)

Pull request description:

  Different MiniWallet instances using the same mode (either ADDRESS_OP_TRUE, RAW_OP_TRUE or RAW_P2PK) currently always create and spend UTXOs with identical output scripts, which can cause unintentional tx dependencies (see e.g. the discussion in #29827 (comment)). In order to avoid mixing of UTXOs between instances, this PR introduces the possibility to provide a MiniWallet tag name, that is used to derive a different internal key for the taproot construction, leading to a different P2TR output script. Note that since we use script-path spending and only the key-path is changed here, no changes in the MiniWallet spending logic are needed.

  The new tagging option is then used in the `fill_mempool` helper to create an ephemeral wallet for the filling txs, as suggested in #29827 (comment). To avoid circular dependencies, `fill_mempool` is moved to a new module `mempool_util.py` first.

  I'm still not sure if a generic word like "tag" is the right term for what this tries to achieve, happy to pick up better suggestions. Also, maybe passing a tag name is overkill and a boolean flag like "random_output_script" is sufficient?

ACKs for top commit:
  glozow:
    ACK dd8fa86
  achow101:
    ACK dd8fa86
  rkrux:
    tACK [dd8fa86](dd8fa86)
  brunoerg:
    utACK dd8fa86

Tree-SHA512: 5ef3558c3ef5ac32cfa79c8f751972ca6bceaa332cd7daac7e93412a88e30dec472cb041c0845b04abf8a317036d31ebddfc3234e609ed442417894c2bdeeac9
@bitcoin bitcoin locked and limited conversation to collaborators Apr 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants