-
Notifications
You must be signed in to change notification settings - Fork 36.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net, test: invalid p2p messages and test framework improvements #19272
net, test: invalid p2p messages and test framework improvements #19272
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
bc42270
to
6b18bfe
Compare
ACK 6b18bfe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed and ran all tests. Just one suggestion if you plan on making any changes.
6b18bfe
to
beecd6b
Compare
Thanks for reviewing @troygiorshev. Took your suggestion and also removed an unnecessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
Mentioned this elsewhere but my edit is already outdated. Small suggestion for p2p_invalid_messages.py, feel free to ignore:
If you replace the 3 (specifically, test_checksum
, test_size
, and test_msgtype
) self.nodes[0].p2p
with conn
, all of the subtest disconnect_p2ps
can also be removed. The only reason they need it now is to clear p2ps
.
beecd6b
to
2ecb8f7
Compare
Thank you for reviewing, @gzhao408. Took your suggestion and credited you as co-author in the commit. |
I don't think we should be removing the |
@jnewbery good point...
In terms of state, I'm thinking state = (1) the (1) I think it's ok if the array has an extra entry if we're not using the (2) For connections: Definitely agree that subtests should disconnect peers to clean up after themselves. Either I'm not sure if disconnected from peer's POV == disconnected from the node's POV. If they're effectively the same, I'd say it's unnecessary to call I might be overthinking this haha, I dug into this when I thought superfluous |
AFAICT the tests are order-independent with this PR, and I checked that this passes when rebased to current master: +from test_framework.util import assert_equal
+ def assert_no_connected_peers(self):
+ assert_equal(self.nodes[0].num_connected_mininodes(), 0)
+
def run_test(self):
self.test_magic_bytes()
+ self.assert_no_connected_peers()
self.test_checksum()
+ self.assert_no_connected_peers()
self.test_size()
+ self.assert_no_connected_peers()
self.test_msgtype()
+ self.assert_no_connected_peers()
self.test_oversized_inv_msg()
+ self.assert_no_connected_peers()
self.test_oversized_getdata_msg()
+ self.assert_no_connected_peers()
self.test_oversized_headers_msg()
+ self.assert_no_connected_peers()
self.test_resource_exhaustion()
+ self.assert_no_connected_peers() |
2ecb8f7
to
06a275f
Compare
Anyway, removed the removal of |
06a275f
to
efb9a95
Compare
… header is split across two buffers 80d4423 Test buffered valid message (Troy Giorshev) Pull request description: This PR is a tweak of bitcoin#19302. This sends a valid message. Additionally, this test includes logging in the same vein as bitcoin#19272. ACKs for top commit: MarcoFalke: tested ACK 80d4423 (added an assert(false) to observe deterministic coverage) 🌦 gzhao408: ACK bitcoin@80d4423 👊 Tree-SHA512: 3b1aa5ec480a1661917354788923d64595e2886448c9697ec0606a81293e8b4a4642b2b3cc9afb2206ce6f74e5c6d687308c5ad19cb73c5b354d3071ad8496f8
@MarcoFalke several PRs on this test have been merged but no approval from you on this one. I think they are good improvements but feel free to close it if you disagree; it will save me from spinning my wheels. |
I generally use the conflicts list of DrahtBot to see which pr has the most reviews and is the most ready to merge and then get them in one by one if they have received their ACKs. Will take another look here. One sec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me
efb9a95
to
255fbca
Compare
Rebased for merged #19304, reverted the chain setting, and removed a line left over from the last change (thanks Marco). -MSG_LIMIT = 4 * 1000 * 1000 # 4MB, per MAX_PROTOCOL_MESSAGE_LENGTH
VALID_DATA_LIMIT = MAX_PROTOCOL_MESSAGE_LENGTH - 5 # Account for the 5-byte length prefix
- self.setup_clean_chain = False
+ self.setup_clean_chain = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice changes, Jon. I've left a few minor comments inline.
255fbca
to
11c1184
Compare
11c1184
to
ca65836
Compare
reACK ca65836 Reviewed and stepped through each test. Verified that none of these changes caused linting errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c6e7519647ef8736aaa5d8e7f804d0340a36029a
0730884
to
98af0f0
Compare
reACK 98af0f0 |
so that oversized ADDR, GETDATA, HEADERS and INV messages print the same consistent debug logs.
- call disconnect_p2ps() outside of the assert_debug_log scopes - send messages directly from the p2p conn rather than via nodes[0].p2p - add an assertion
98af0f0
to
56010f9
Compare
Rebased, no changes. Thank you for ACKing @troygiorshev! Should be trivial to re-ack with |
reACK 56010f9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. Nice changes, easy to review. Compiled without issue, verified all unit and functions tests passing.
Below are a nonblocking nit and a question for explanation.
@@ -24,8 +27,7 @@ | |||
wait_until, | |||
) | |||
|
|||
MSG_LIMIT = 4 * 1000 * 1000 # 4MB, per MAX_PROTOCOL_MESSAGE_LENGTH | |||
VALID_DATA_LIMIT = MSG_LIMIT - 5 # Account for the 5-byte length prefix | |||
VALID_DATA_LIMIT = MAX_PROTOCOL_MESSAGE_LENGTH - 5 # Account for the 5-byte length prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I am missing something, but this 5 bytes message length seems to be coming from ser_string()
in messages.py
. But is it something that the node also recognizes? It doesn't seem to be part of the p2p protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We set VALID_DATA_LIMIT
so that the length of the serialised msg_unrecognized
message built with it will equal MAX_PROTOCOL_MESSAGE_LENGTH
. This is verified at line 153; you can also add the following assertion at line 111
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
+ assert_equal(len(msg.serialize()), MAX_PROTOCOL_MESSAGE_LENGTH + 1)
or try changing the offset from 5 to 4 or 6.
I've added this assertion and some other ones while testing @troygiorshev's net message headers refactoring and may propose the changes if they look worthwhile to me after a few days' time.
ACK 56010f9 🎛 Show signature and timestampSignature:
Timestamp of file with hash |
…mprovements Summary: 56010f92564a94b0ca6c008c0e6f74a19fad4a2a test: hoist p2p values to test framework constants (Jon Atack) 75447f0893f9ad9bf83d182b301d139430d8de1c test: improve msg sends and p2p disconnections in p2p_invalid_messages (Jon Atack) 57960192a5362ff1a7b996995332535f4c2a25c3 test: refactor test_large_inv() into 3 tests with common method (Jon Atack) e2b21d8a597c536a8617408d43958bfe9f98a442 test: add p2p_invalid_messages logging (Jon Atack) 9fa494dc0969c61d5ef33708a08923cca19ce091 net: update misbehavior logging for oversized messages (Jon Atack) Pull request description: ...seen while reviewing #19264, #19252, #19304 and #19107: in `net_processing.cpp` - make the debug logging for oversized message size misbehavior the same for `addr`, `getdata`, `headers` and `inv` messages in `p2p_invalid_messages` - add missing logging - improve assertions/message sends, move cleanup disconnections outside the assertion scopes - split a slowish 3-part test into 3 order-independent tests - add a few p2p constants to the test framework --- Backport of [[bitcoin/bitcoin#19272 | core#19272]] Test Plan: ninja all check check-functional Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D9530
...seen while reviewing #19264, #19252, #19304 and #19107:
in
net_processing.cpp
addr
,getdata
,headers
andinv
messagesin
p2p_invalid_messages