Learn Rust

To be productive with substrate requires some familiarity with Rust. Fortunately, the Rust community is known for comprehensive documentation and tutorials. The most common resource for initially learning Rust is The Rust Book. To see examples of popular crate usage patterns, Rust by Example is also convenient.

API Design

To become more familiar with commmon design patterns in Rust, the following links might be helpful:


To optimize runtime performance, Substrate developers should make use of iterators, traits, and Rust's other "zero cost abstractions":

It is not (immediately) necessary to become familiar with multithreading because the runtime operates in a single-threaded context. Even so, an optimized substrate node architecture will use a custom RPC interface. Moreover, the runtime might take advantage of the offchain workers API to minimize the computation executed on-chain. Effectively using these features requires increased familiarity with advanced Rust.

For a high-level overview of concurrency in Rust, Stjepan Glavina provides the following descriptions in Lock-free Rust: Crossbeam in 2019:

  • Rayon splits your data into distinct pieces, gives each piece to a thread to do some kind of computation on it, and finally aggregates results. Its goal is to distribute CPU-intensive tasks onto a thread pool.
  • Tokio runs tasks which sometimes need to be paused in order to wait for asynchronous events. Handling tons of such tasks is no problem. Its goal is to distribute IO-intensive tasks onto a thread pool.
  • Crossbeam is all about low-level concurrency: atomics, concurrent data structures, synchronization primitives. Same idea as the std::sync module, but bigger. Its goal is to provide tools on top of which libraries like Rayon and Tokio can be built.


Are we async yet?