Currently test coverage is non-deterministic, which makes it hard to compare coverage between commits.
Fix one instance of non-determinism in net by adding an explicit test for this case:
src/net.cpp: // if header incomplete, exit
Currently test coverage is non-deterministic, which makes it hard to compare coverage between commits.
Fix one instance of non-determinism in net by adding an explicit test for this case:
src/net.cpp: // if header incomplete, exit
Can be tested by adding an assert(false) to the line that I claim to add coverage to and observing a deterministic crash when running the new test and no crash when running the previous test script.
@troygiorshev @jnewbery based on your recent work in this area, you seem qualified to review this :pray:
106 | @@ -106,6 +107,20 @@ def test_large_inv(self): 107 | conn.send_and_ping(msg) 108 | self.nodes[0].disconnect_p2ps() 109 | 110 | + def test_buffer(self): 111 | + self.log.debug('Check that peer is disconnected for bad message even if some of the bytes are delayed')
I think this log can be info.
Changed
117 | + msg = b'\xff' * 4 + msg[4:] 118 | + conn.send_raw_message(msg[:22]) 119 | + conn_ping.sync_with_ping() 120 | + conn.send_raw_message(msg[22:]) 121 | + conn.wait_for_disconnect(timeout=1) 122 | + self.nodes[0].disconnect_p2ps()
I think this line can be removed.
It is required to disconnect conn_ping
Interesting. I need to look at it more, but this seems to hit the conditional:
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -652,9 +652,10 @@ int V1TransportDeserializer::readHeader(const char *pch, unsigned int nBytes)
nHdrPos += nCopy;
// if header incomplete, exit
- if (nHdrPos < CMessageHeader::HEADER_SIZE)
+ if (nHdrPos < CMessageHeader::HEADER_SIZE) {
+ LogPrintf("Incomplete header");
return nCopy;
-
+ }
--- a/test/functional/p2p_invalid_messages.py
+++ b/test/functional/p2p_invalid_messages.py
def test_buffer(self):
self.log.info('Check that peer is disconnected for bad message even if some of the bytes are delayed')
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- conn_ping = self.nodes[0].add_p2p_connection(P2PDataStore())
- with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
+ with self.nodes[0].assert_debug_log(['Incomplete header', 'PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
msg = conn.build_message(msg_unrecognized(str_data="d"))
# modify magic bytes
msg = b'\xff' * 4 + msg[4:]
conn.send_raw_message(msg[:22])
- conn_ping.sync_with_ping()
conn.send_raw_message(msg[22:])
conn.wait_for_disconnect(timeout=1)
- self.nodes[0].disconnect_p2ps()
Tested concept ACK on verifying the behavior of incomplete headers, both if the message is bad like in this test, and perhaps also verify behavior when the message is good, e.g. magic bytes not modified. This test is very similar to test_magic_bytes; they could be placed next to each other.
they could be placed next to each other
Done
@troygiorshev already has a test that verifies that we're able to deserialize a message that is split across two buffer reads. I think that's preferable - there's no obvious reason that split messages and invalid messages need to be linked.
Is there a pull request for the test? I'd be happy to review and close this one instead.
#19304 should cover everything discussed here.
Thx