Repository navigation
test: p2p: check that headers message with invalid proof-of-work disconnects peer - #26184
Conversation
|
concept ack |
07342be to
4bf49eb
Compare
|
Force-pushed taking Marco's review (#26184 (comment)) into account: we first create a valid headers message now and check that it is accepted by the node, and only then we only modify its nNonce until the PoW is invalidated. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee 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. |
There was a problem hiding this comment.
nit: Could also check the connected header hash
assert any(x["hash"] == blockheader.hash and x["status"] == "headers-only" for x in self.nodes[0].getchaintips())There was a problem hiding this comment.
Good idea, done. Decided to access the getchaintips() result at index 0 (works since the result is always returned in decreasing order of height) in order to take use of assert_equal, so if this ever fails, we see the expected/actual values immediately.
|
@brunoerg: @furszy: Thanks for your reviews, will include both your nits in a bit.
Considering that we have quite detailled |
Ah, wasn't aware of its existence. Great. |
4bf49eb to
7726712
Compare
|
ACK 7726712 |
furszy
left a comment
There was a problem hiding this comment.
Code review ACK 7726712 with a non-blocking speedup.
To make the test faster, instead of increase the nonce + rehash the block, could just set the target bits to 0 (or set it above the pow limit). The same "header with invalid proof of work" error will be thrown.
e.g.
# Invalidate header
blockheader.nBits = 0
blockheader.rehash()
with self.nodes[0].assert_debug_log(['Misbehaving', 'header with invalid proof of work']):
peer.send_message(msg_headers([blockheader]))
peer.wait_for_disconnect()|
ACK 7726712 |
One of the earliest anti-DoS checks done after receiving and deserializing a
headersmessage from a peer is verifying whether the proof-of-work is valid (called in methodPeerManagerImpl::ProcessHeadersMessage):bitcoin/src/net_processing.cpp
Lines 2752 to 2762 in f227e15
The called method
PeerManagerImpl::CheckHeadersPoWcallsMisbehavingwith a score of 100, i.e. leading to an immediate disconnect of the peer:bitcoin/src/net_processing.cpp
Lines 2368 to 2372 in f227e15
This PR adds a simple test for both the misbehaving log and the resulting disconnect. For creating a block header with invalid proof-of-work, we first create one that is accepted by the node (the difficulty field
nBitsis copied from the genesis block) and based on that the nonce is modified until we have block header hash prefix that is too high to fulfill even the minimum difficulty.