This was actually the original goal of the Rust work, but we had to start somewhere a bit simpler. This adds a full parallel P2P client, written in Rust, which can download and serve both headers and blocks, listening on a separate port. It is designed to be simple and robust, letting the C++ net_processing handle being optimized. It avoids wasting bandwidth needlessly by not (like all Rust modules so far) starting up until either IBD completes or it seems stuck and by waiting 30 seconds any time it hears about a new block that it decides to fetch before actually fetching it.
Based on (but could probably go in independently of) #16834, #16762, and #16974.
Some tasks that need to happen to clean this up a bit:
- Build out the Rust addrman a bit - it currently always queries DNS seeds until its built out a database of 500 addresses and then never changes it. I don’t think this is a particularly terrible design at a high level for something with a goal of simply having a different failure model from the C++ addrman, but the over-reliance on the DNS seeds needs to go, at least (plus we dont want to ever query them after we’ve built up an addrman that works, eg upon upgrade).
- Build out connection logic a bit - we currently just open connections willy nilly very aggressively if our best header falls behind our best tip. This is great, but we should probably, like, disconnect peers that don’t manage to help us along our journey (especially since the Rust code is hard-limited to 128MB of memory allocations, though this may want to change to 256MB, we have very little room for peers given our socket buffers are like 8-16MB just to receive a block and send one).
- Support Windows. Currently uses poll() for socket handling and a pipe() to wake up the poll() thread. Needs a Windows version of that module, though that shouldn’t be too hard…right?
- A XXX or two, at least one of them probably requires @elichai explain Rust to me.
- Subtree the libsecp bump, and the addition of rust-bitcoin crates (all managed in the rust-bitcoin org on GH by the Usual Folks) and libc crates (which just exposes libc functions and little more, though in theory we could probably drop this if we wanted to expose them ourselves, but it should be pretty simple). Subtrees are a PITA to handle, so this will just happen right before merge.