As noted in Blockchain basics, a blockchain relies on a decentralized network of computers—called nodes—that communicate with each other.
Because the node is a core component of any blockchain, it’s important to understand what makes a Substrate node unique, including the core services and libraries that are provided by default and how the node can be customized and extended to suit different project goals.
In a decentralized network, all nodes act as both clients that request data and as servers that respond to requests for data. Conceptually and programmatically, the Substrate architecture divides operational responsibilities along similar lines. The following diagram illustrates this separation of responsibilities in simplified form to help you visualize the architecture and how Substrate provides a modular framework for building blockchains.
At a high level, a Substrate node provides a layered environment with two main elements:
- An outer node that handles network activity such as peer discovery, managing transaction requests, reaching consensus with peers, and responding to RPC calls.
- A runtime that contains all of the business logic for executing the state transition function of the blockchain.
The outer node is responsible for activity that takes place outside of the runtime. For example, the outer node is responsible for handling peer discovery, managing the transaction pool, communicating with other nodes to reach consensus, and answering RPC calls or browser requests from the outside world.
Some of the most important activities that are handled by the outer node involve the following components:
- Storage: The outer node persists the evolving state of a Substrate blockchain using a simple and highly efficient key-value storage layer.
- Peer-to-peer networking: The outer node uses the Rust implementation of the
libp2pnetwork stack to communicate with other network participants.
- Consensus: The outer node communicates with other network participants to ensure they agree on the state of the blockchain.
- Remote procedure call (RPC) API: The outer node accepts inbound HTTP and WebSocket requests to allow blockchain users to interact with the network.
- Telemetry: The outer node collects and provides access to node metrics through an embedded Prometheus server.
- Execution environment: The outer node is responsible for selecting the execution environment—WebAssembly or native Rust—for the runtime to use then dispatching calls to the runtime selected.
Performing these tasks often requires the outer node to query the runtime for information or to provide information to the runtime. This communication is handled by calling specialized runtime APIs.
The runtime determines whether transactions are valid or invalid and is responsible for handling changes to the blockchain's state transition function.
Because the runtime executes the functions it receives, it controls how transactions are included in blocks and how blocks are returned to the outer node for gossiping or importing to other nodes. In essence, the runtime is responsible for handling everything that happens on-chain. It is also the core component of the node for building Substrate blockchains.
The Substrate runtime is designed to compile to WebAssembly (Wasm) byte code. This design decision enables:
- Support for forkless upgrades.
- Multi-platform compatibility.
- Runtime validity checking.
- Validation proofs for relay chain consensus mechanisms.
Similar to how the outer node has a way to provide information to the runtime, the runtime uses specialized host functions to communicate with the outer node or the outside world.
Now that you have an overview of the Substrate architecture and core node components, explore the following topics to learn more.