Followup to #29412 to revert some of the behavior change that was likely unintentional.
Based on comments from #29412 (review)
Followup to #29412 to revert some of the behavior change that was likely unintentional.
Based on comments from #29412 (review)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For detailed information about the code coverage, see the test coverage report.
See the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
78@@ -74,7 +79,7 @@ def self_transfer_requested():
79
80 # Attempt to clear the honest relayer's download request by sending the
81 # mutated block (as the attacker).
82- with self.nodes[0].assert_debug_log(expected_msgs=["bad-txnmrklroot, hashMerkleRoot mismatch"]):
83+ with self.nodes[0].assert_debug_log(expected_msgs=["Block mutated: bad-txnmrklroot, hashMerkleRoot mismatch"]):
This is not necessary, right?
I added this assertion but asserting logs is not good practice: if it is really necessary then the interface under test should expose enough info to make the required assertion. Logs aren’t a stable interface nor are they meant to serve as an interface for automated tests. Most of the time, duplicating them for test assertions just causes churn down the road. You don’t want to force devs to “fix” a bunch of tests because they changed a user facing log message.
It’s not strictly necessary, no, but if we somehow added a regression that missed the mutation check and only caught it in the AcceptBlock
portion, this change would catch it? I guess this could be shortened to just catching “Block mutated:” since that’s the actual test(making sure it’s not making further in validation)?
I am not strongly opinionated on it.
but if we somehow added a regression that missed the mutation check and only caught it in the AcceptBlock portion, this change would catch it?
Sure but testing fine grained implementation details like this sounds more like the job of a unit test to me.
unit
The functional test are also testing a unit, which is Bitcoin Core ;)
107+ # Attacker gets a DoS score of 10, not immediately disconnected, so we do it 10 times to get to 100
108+ for _ in range(10):
109+ assert_equal(len(self.nodes[0].getpeerinfo()), 2)
110+ with self.nodes[0].assert_debug_log(expected_msgs=["AcceptBlock FAILED (prev-blk-not-found)"]):
111+ attacker.send_message(msg_block(block_missing_prev))
112+ attacker.wait_for_disconnect(timeout=5)
I’m not sure if this is the right place for this test because it has nothing to do with mutated blocks. This test should have existed before my PR, so there is probably a better place for it.
Specifically the property we apparently care about is “a peer sending a disconnected block is assigned 10 DoS points” and a separate “if a peer has 100 DoS points it is disconnected”. DoS points should be exposed through getpeerinfo (if they aren’t already?) to test this properly which makes any log assertions superfluous.
it has nothing to do with mutated blocks
It kind of does, because we can’t tell if the witness is mutated without knowing the height.
p2p_unrequested_blocks.py
is a better home.
(if they aren’t already?)
That was to be my first attempt, but it’s not exposed unless I’m having reading issues. Agreed it’s better! I could also just have it run 10 times and make sure it disconnects, which does no log-reading and still gets the point across.
misbehavior_score
to getpeerinfo
since this seems to be a recurring issue: https://github.com/bitcoin/bitcoin/pull/29530
Code review ACK a1fbde0ef7cf6c94d4a5181f8ceb327096713160
Left my 2 sats on the tests but I can live with what you have here now.
ACK a1fbde0ef7cf6c94d4a5181f8ceb327096713160
I checked that the test fails without this change.
I share @dergoegge’s sentiment of decreasing our test dependency on logs, but that can wait for a followup.
tACK https://github.com/bitcoin/bitcoin/commit/a1fbde0ef7cf6c94d4a5181f8ceb327096713160
I checked that the test would fail with AcceptBlock FAILED (bad-txnmrklroot, hashMerkleRoot mismatch)
and the peer will be given 100 ban points before the change, while it would only be given 10 and the block will be rejected with AcceptBlock FAILED (prev-blk-not-found)
after it.
I do agree that p2p_mutated_blocks.py
is not the best place to include this last test though.