Fix race condition when reading from the network in mininode.py
Summary:
In some rare cases, a test would fail memtionning that it got an invalid message. This could be reproduced consistently on tests that use heavily the network such as abc-p2p-fullblocktest.py when choosing a small read buffer size (in my case 8). By inspecting the data read from the network, it appeared that blocks of 8 bytes were swapped in these invlid messages.
This is dead giveaway that the buffer pieces are reassembled in an invalid order.
In order to prevent this from happening, we take a the lock on the node when recieving data from the network. in order to avoid too much contention, the decoded message is returned from got_data instead and got_message is called after the lock was freed.
Test Plan:
Reduce the value of READ_BUFFER_SIZE to 8
- Ensure some tests are failing consistently withotu that patch
- Ensure these tests pass consistently with that patch
Run the whole qa test suite in order to ensure nothing was broken inadvertently.
../qa/pull-tester/rpc-tests.py -extended
Reviewers: freetrader, sickpig, awemany, kyuupichan, #bitcoin_abc
Reviewed By: freetrader, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D284