Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
It's possible to simulate diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py
index aa43cc18e2..4a83e44b91 100755
--- a/test/functional/p2p_tx_download.py
+++ b/test/functional/p2p_tx_download.py
@@ -116,6 +116,8 @@ class TxDownloadTest(BitcoinTestFramework):
self.log.info("Put the tx in node 0's mempool")
self.nodes[0].sendrawtransaction(tx['hex'])
+ time.sleep(2)
+
# Since node 1 is connected outbound to an honest peer (node 0), it
# should get the tx within a timeout.
# However, node 0 sees the same connection as inbound, so it may not |
|
I tested the master and PR versions using the same binary and Crypt-iQ's reproducer, adding a delay after On master, with a 2-second delay, 2/5 runs failed due to mempool sync timeouts. With the PR, both runs passed. Increasing the delay to 5 seconds made master pass, but runs took around 83 seconds instead of 26, while the PR remained around 26 seconds. Looking at node1's debug log, master requests the wtx from peer 4, which never responds, and retries node0 only after 60 seconds. With the PR, it requests from peer 0 almost immediately after receiving the inventory. So this isn't just fixing a flaky test; it also avoids a silent 60-second slowdown when the race occurs. |
|
@Pranav-error Sharing LLM output will get you blocked, see https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md. If you have something relevant to say, this is great, but then please write it by hand or if it must be LLM output, clearly mark it as such. |
|
@maflcko i had used ai to pharse my words so there is no gramtical misatke so i woudn't be doing that also from next time |
maflcko
left a comment
There was a problem hiding this comment.
thx, but I am not sure if this is correct
| self.nodes[0].setmocktime(0) | ||
| self.nodes[1].setmocktime(0) |
There was a problem hiding this comment.
you can remove both, the outer loop already takes care of this.
There was a problem hiding this comment.
I did this in 761ec7e which also removed another location
There was a problem hiding this comment.
I think if you select self.nodes[1].setmocktime(now) the test will break, because NONPREF_PEER_TX_DELAY can never hit? Sure, it never hit in practise before either, but it seems a bit odd for the test to imply it can be hit when now it can deterministically never hit.
Also, what does "races" refer to when both nodes use mocktime? The patch here doesn't seem right, or at least incomplete.
I think the issue you are seeing was introduced in 2706c5b (I haven't tried this).
So the possible fixes are:
- Revert 2706c5b (and go back to rough "best-effort" test coverage)
- Properly use mocktime to keep the test coverage (and ideally exercise the exact code triggers mentioned here)
There was a problem hiding this comment.
I should have spent a bit more time before opening the PR. I do think there's a flake here though.
I think currently the test is broken on master:
self.nodes[0]uses mocktime andself.nodes[1]does not. So whenself.nodes[0].bumpmocktime(timeout)is used, it doesn't make much sense because that timeout is actually meant forself.nodes[1]since it doesn't have the tx and may request the tx from the test peers and then fallback to requesting it fromself.nodes[0]. I thinkself.nodes[0]mocktime does need to be bumped, but only around the order ofINBOUND_INVENTORY_BROADCAST_INTERVALso it can actually announce toself.nodes[1].- the second thing is that because
self.nodes[1]does not use mock time, its real clock can advance beforeself.nodes[0]sends the inv. If time advances onself.nodes[1]byNONPREF_PEER_TX_DELAYbeforeself.nodes[0]can announce,self.nodes[1]will request from a test peer first. It will expire after ~60s (GETDATA_TX_INTERVAL) and while this is happening, thesync_mempoolstimeout of 60s may be hit.
Is this too much of an edge case?
There was a problem hiding this comment.
Sorry, I pasted the wrong commit id :(
I've edited my comment with the correct id.
I agree that there is a flake here, and it could make sense to fix it. However, I think the correct fix is going to look different.
There was a problem hiding this comment.
Properly use mocktime to keep the test coverage (and ideally exercise the exact code triggers mentioned here)
I think it makes more sense to do this and split into two subtests where one subtest checks behavior when self.nodes[1] requests from a non-preferred peer first and the other checks behavior when self.nodes[1] requests from self.nodes[0] first.
There was a problem hiding this comment.
sgtm. Happy to review a pull doing that :)
There was a problem hiding this comment.
I'm a little confused what test_inv_block is testing. Is it testing that even peers that inv the tx first and never provide it ("block" delivery of the tx) can't prevent the node from getting the tx? Because if so, it seems a little odd because in the real world, self.nodes[1] would request the tx from its other peers after ~2s as self.nodes[0] would only announce after ~5s. But the test immediately bumps the mocktime of self.nodes[0] so it ~instantly announces to self.nodes[1] and usually self.nodes[1] will request from self.nodes[0] instead of from its other peers. This doesn't match reality, so I'm confused.
There was a problem hiding this comment.
Yeah, I think this was another bug introduced in 2706c5b? It dropped the NONPREF_PEER_TX_DELAY sleep.
Not sure if there is another test case already for the outbound announcing first, but I think it would be good to write two test cases, or at a minimum fix this test case to add back the NONPREF_PEER_TX_DELAY properly.
There was a problem hiding this comment.
I tested that commit and it did introduce the bug. I modified the test to use mocktime and request from a blocking inbound peer first in 4cc74b2. I decided against adding a subtest for an outbound announcing first since test_preferred_tiebreaker_inv covers this case and, to me, it doesn't really test a peer blocking relay. It mostly seems like an artifact of 2706c5b. Also, the whole p2p_tx_download.py suite takes ~20s to run on my machine, compared to the commit before 2706c5b which took ~90s to run.
|
Concept ACK on splitting this into two subtests. But one thing to watch for in the rework is that So I tried this and applied this branch locally. I changed node 0's bump from There was #35324, which introduced this assertion with a comment that it may fail rarely and retry the test. So that means that sizing that bump to the interval would turn that rare failure into an actual routine one. There's a function, |
I think bumping to a reasonable amount over is fine to make the chance of this happening low. Looping also works, though maybe we could just cap the timers in net_processing.cpp |
Because nodes[1] time was not mocked in test_inv_block, it was possible for wall clock to advance 2s by the time nodes[0] had delivered a tx announcement to it. Then, nodes[1] would request the tx from a test peer, never receive the tx, and fail in sync_mempools(). Fix this by using mocktime for nodes[1] as well. Another issue is that nodes[0] would immediately announce the tx which usually made nodes[1] request it from them instead of from a blocking inbound peer. Fix this by ensuring that nodes[1] requests from a blocking inbound peer first.
e556dc1 to
4cc74b2
Compare
|
Latest push to 4cc74b2 uses mocktime and ensures that |
Yeap. Agreed. Would also be interested to see whether a cap would apply to some of the other tests on #19732. |
|
Tested on macOS arm64. The PR passed 20/20 runs, and Crypt-iQ's reproducer (2s delay after sendrawtransaction) passed 10/10 runs. For comparison, my Nov 20 runs on master with the same delay failed 2/5 times due to mempool sync timeouts. Didn't test on other OSes or with rr though, but looks good from my testing too. |
|
|

Because
nodes[1]time was not mocked in test_block_inv, it was possible for wall clock to advance 2s by the timenodes[0]had delivered a tx announcement to it. Then,nodes[1]would request the tx from a test peer, never receive the tx, and fail in sync_mempools().