Jaspervdm - Progress update thread - March to May 2020

March 9-15
I have spent most of last week refactoring the node p2p communication layer. In v3.1 (and older) the node uses blocking code. It spawns 2 threads for every connection: a reader and a writer. These threads attempt to do locking reads and writes with short timeouts in a loop. This is not very resource efficient, as each thread uses a bunch of memory and possibly wastes cpu cycles when there is nothing to read or write.

I have been working on moving the p2p layer to asynchronous code, using the async/.await functionality that was stabilized in Rust a while ago. This means that there is a multi-threaded runtime that manages all connections and only tries to read/write when necessary. This should reduce resource usage and also opens up possibilities for future improvements, such as having a single thread that is responsible for processing headers/txs/blocks.

At the end of last week I managed to do an initial sync from scratch using async p2p code. However, there is still a bunch of work to be done before the PR can be reviewed and eventually merged. Since there is still a lot of blocking code in the node that interfaces with the p2p layer, it is kind of awkward at times having to juggle synchronous and asynchronous contexts, so I will be spending more time trying to refactor code to simplify this. There are also some stability issues that need to be addressed. I will provide another update next week.

Stay safe everyone

9 Likes