Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jun 17, 2020

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

@maflcko
Copy link
Member Author

maflcko commented Jun 17, 2020

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.

@maflcko
Copy link
Member Author

maflcko commented Jun 17, 2020

@troygiorshev @jnewbery based on your recent work in this area, you seem qualified to review this 🙏

@DrahtBot DrahtBot added the Tests label Jun 17, 2020
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

conn_ping.sync_with_ping()
conn.send_raw_message(msg[22:])
conn.wait_for_disconnect(timeout=1)
self.nodes[0].disconnect_p2ps()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required to disconnect conn_ping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@maflcko
Copy link
Member Author

maflcko commented Jun 17, 2020

they could be placed next to each other

Done

@jnewbery
Copy link
Contributor

@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.

@maflcko
Copy link
Member Author

maflcko commented Jun 17, 2020

Is there a pull request for the test? I'd be happy to review and close this one instead.

@troygiorshev
Copy link
Contributor

#19304 should cover everything discussed here.

@maflcko maflcko closed this Jun 17, 2020
@maflcko
Copy link
Member Author

maflcko commented Jun 17, 2020

Thx

@maflcko maflcko deleted the 2006-badBuffer branch June 17, 2020 15:46
maflcko pushed a commit that referenced this pull request Jun 18, 2020
… is split across two buffers

80d4423 Test buffered valid message (Troy Giorshev)

Pull request description:

  This PR is a tweak of #19302.  This sends a valid message.

  Additionally, this test includes logging in the same vein as #19272.

ACKs for top commit:
  MarcoFalke:
    tested ACK 80d4423 (added an assert(false) to observe deterministic coverage) 🌦
  gzhao408:
    ACK 80d4423 👊

Tree-SHA512: 3b1aa5ec480a1661917354788923d64595e2886448c9697ec0606a81293e8b4a4642b2b3cc9afb2206ce6f74e5c6d687308c5ad19cb73c5b354d3071ad8496f8
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants