test: add test for rebroadcast of transaction received via p2p#34359
test: add test for rebroadcast of transaction received via p2p#34359sedited merged 1 commit intobitcoin:masterfrom
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34359. ReviewsSee the guideline 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. |
6abf771 to
051ca37
Compare
So, |
|
yes - because of the wallet bug, the wallet creates an invalid transaction, trying to double-spend an utxo that was already used in a block. The node then rejects that tx obviously, and the rpc querying for the tx fails. |
051ca37 to
ce8560d
Compare
ce8560d to
5c9dedf
Compare
|
rebased/undrafted after merge of #34358 |
5c9dedf to
b2c9eac
Compare
b2c9eac to
990e2cd
Compare
| def set_test_params(self): | ||
| self.num_nodes = 1 | ||
| self.num_nodes = 2 | ||
| self.extra_args = [["-whitelist=relay,noban@127.0.0.1"], ["-whitelist=relay,noban@127.0.0.1"]] |
There was a problem hiding this comment.
Is there a reason why this is needed? Without this, sending the tx fails, but I don't see why.
There was a problem hiding this comment.
node0 must have node1 with the noban permission in order to send the transaction to it without delay in this part of the test:
self.log.info("node0 sends a tx to node1 and disconnects")
recv_addr = node1.getnewaddress()
recv_txid = node.sendtoaddress(recv_addr, 1)bitcoin/src/net_processing.cpp
Lines 5981 to 5989 in b6b8f8a
Note that in this part of the test the time is frozen and does not flow because setmocktime() has been called on node0 so it never sets fSendTrickle to true and thus never sends the transaction to node1.
Btw this suffices:
| self.extra_args = [["-whitelist=relay,noban@127.0.0.1"], ["-whitelist=relay,noban@127.0.0.1"]] | |
| self.extra_args = [["-whitelist=noban@127.0.0.1"], []] |
There was a problem hiding this comment.
Ok, that is pretty obvious, thx. Could also add a comment, like # Needed due to mocktime. A third alternative could be self.noban_tx_relay = True # Needed due to mocktime.
There was a problem hiding this comment.
... or to advance the mocktime across NextInvToInbounds(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL, node.m_network_key) but that would always leave, at least in theory, some chance that we did not advance enough.
There was a problem hiding this comment.
used self.noban_tx_relay, which is more common
maflcko
left a comment
There was a problem hiding this comment.
lgtm. Feel free to ignore the nits.
I guess this doesn't add any coverage in terms of new paths/lines, because the wallet does not differentiate between tx sources, but if this ever were to change in the future, this test would already be there.
review ACK 990e2cd 🦉
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: review ACK 990e2cd0babf7a2ee90d7b40e91a0c7477511957 🦉
Qvh92TAwBuuBKdQwPindEYsKDLnaNpJ8iBuqe/CM1y4flECUTk5rYxTez0Xkgs5tWg/eb7685VUp8bnGdkSgCQ==
| node.setmocktime(now + RESEND_TIMER_LIMIT) | ||
| # Tell scheduler to call MaybeResendWalletTxs now. | ||
| node.mockscheduler(60) | ||
| # Give some time for trickle to occur |
There was a problem hiding this comment.
nit: I guess this is no longer needed and can be removed now? Also -- unrelated, the peer_second.wait_for_broadcast([txid]) can be moved into the assert_debug_log scope, so that the timeout=2-polling on it can be removed?
The wallet doesn't only rebroadcast transactions it created, but also relevant transactions received via p2p. Since this is not self-evident, add test coverage for it.
990e2cd to
73e3853
Compare
|
990e2cd to 73e3853: addressed feedback
Yes, my main motivation is to have a test for this behavior before discussing changes to it. I knew that rebroadcast has privacy downsides, but I always thought that just making sure your txns confirm in a couple of hours would be sufficient to mitigate it, which seemed annoying but manageable to me. But I never realized that just passively (not submitting any txns) running a Bitcoin core node for a day with a loaded wallet used a long time ago (maybe even with private broadcast then) would put you at risk of being deanonymized via dusting / rebroadcast tracking - even though I'm sure more regular wallet contributors knew this, after all there is the ancient issue #3828. |
|
Just addressed some nits: re-ACK 73e3853 🦌 Show signatureSignature: |
danielabrozzoni
left a comment
There was a problem hiding this comment.
tACK 73e3853
It wasn't obvious to me that the wallet rebroadcasts transactions it's the recipient of, so it's nice to have a test that makes this a bit more explicit.
I left a micro-nit in case you need to retouch, otherwise it's good as-is.
| node.getmempoolentry(txid) | ||
| node.getmempoolentry(child_txid) | ||
|
|
||
| self.log.info("Test rebroadcast of transactions received by others") |
There was a problem hiding this comment.
nit: I find "received by others" to be slightly confusing, because instead of reading it as "p2p tx message that someone sent us", I read it as "transaction whose recipient is someone else", which is the opposite of what's happening here (node1 does the rebroadcast and is the recipient).
Maybe "Test rebroadcast of incoming wallet transactions" is clearer.
The wallet doesn't only rebroadcast transactions it created, but also relevant transactions received via p2p.
Since this is not self-evident, add test coverage for it.