When we run a
cargo run -- --dev we run a
substrate-node. The business logic is defined on the pallets composed by
construct_runtime! inside the runtime. So which part of the node is responsible for initiating and interacting with the runtime?
When we run a
In a Substrate client, such as when running
cargo run -- --dev, the responsibility for initiating and interacting with the runtime lies with the node itself. The node is the main component that handles the execution of the blockchain network and manages the runtime.
When you run the Substrate client, it starts the node, which includes the consensus engine,networking, block production, and Transaction Processing. Runtime contains the core business logic of the blockchain. It consists of a set of pallets, which are reusable modules that define the state, storage, and behavior of the blockchain. The runtime is responsible for executing the transactions, maintaining the state of the blockchain, and processing the system events.
So, the node is responsible for initiating the runtime and coordinating its interaction with other components. It ensures that the defined business logic in the pallets is executed correctly and maintains the integrity of the blockchain network.
Substrate provides a FRAME based blockchain system for adding custom pallets to make a application specific blockchain. To achieve this a custom runtime is also required which will interact with custom pallet.
How node and runtime are connected?
You can find connection between node and runtime by going through node/src/service.rs and node/src/chain_spec.rs file,
service.rs file contains the logic for the spawn of the network and
chain_spec.rs file contains the genesis configuration for the chain.
Here you can see the type
FullClient is taking
RuntimeApi as one of its generic input as you can see in below code snippet.
pub(crate) type FullClient = sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
Than this is used byspawn_tasks
client field, you can find
spawn_tasks definition here, there is a method gen_rpc_module in
spawn_tasks which than is using the client to as its input and you can find its definition here. I hope this helps.