Moving the discussion from #15798 here, as it makes more sense to have it in an issue instead of a PR. #15798 no longer reflects the current proposed Rust changes, and Rust related work is now happening across multiple others.
Corys thoughts / introduction from #15798:
This is not intended to be merged as-is, but instead to serve as a reference for anyone who might be interested in trying out some rust code inside of Bitcoin Core. I have no idea what works. I have lots of questions about debugging, threading, etc. But instead of trying to hack and document how things work, we thought it’d be fun for everyone to be able to poke at it and scratch our heads together :). If something interesting comes out of it, a discussion about merging can happen then.
It is surprisingly functional. The rust tools are impeccable. I would’ve thought this would be a project that would take months/years, but the rust devs have done such a good job that mostly everything already just works. The gitian descriptors have been modified to actually incorporate working rust code. All of our currently supported platforms seem to already work (even macOS cross!) with the exception of 32bit windows and ancient linux distros. The specific issues are documented in the gitian descriptors. For now, Gitian needs net access and a larger disk volume, but those are both very temporary issues
Why rust? I don’t know. Maybe not. But I think it’s a fair assumption to say that Rust code will eventually end up in Bitcoin Core as the result of adding a new dependency. Adoption is happing quickly. So, I think it prudent to look ahead and not only be prepared, but actively help usher it in. Already I have a few things that I would like to work on and upstream to rust-lang to make our integration nicer, and I assume that more will be uncovered as it actually gets used.
Anybody have any fun ideas?
There’s still discussion to be had / documentation to be added around various Rust related decisions, such as:
- Whether to use/require the
2015
or2018
Editions. - A minimum required version of the language.
- How failures in the Rust code are (expected to be) handled by the c++ code.
As well as higher level discussions around how far we might take the Rust integration/re-writing of certain parts of the code, and the complexities that could introduce in regards which contributors can/can’t write/review Rust, or have more/less experience with the language compared to C++
etc.
Personally, I’d like to think that we’ll have some off-by-default Rust as part of the Bitcoin Core 0.20.0 release; and I think something like #16834 might be a good first approach. Regardless of approach, the idea of using Rust inside Bitcoin Core seems to resonate with some of the (still limited set) of other contributors I’ve discussed it with.
Using rustc
directly instead of Cargo
The initial Rust integration PR used Cargo for managing compiling, dependencies etc. Since then, the Rust changes have been refactored to remove the cbindgen
dependency and drop any usage of Cargo altogether, in favour of using rustc
directly.
See also the recent Security advisory for Cargo.
Related PRs
Fetch Headers over DNS Rust-based Backup over-REST block downloader Add Parallel P2P Client in Rust