3

When we run a substrate client 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?

2 Answers 2

1

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.

1
  • Yes, the node does the connection with runtime. I was curious to know which part of the node does that. The runtime is compiled into wasm. So, which part of the node loads/makes communication with the wasm? Commented Jul 6, 2023 at 7:56
0

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.

4
  • So how does the node interact with the runtime? Commented Jul 5, 2023 at 8:49
  • 1
    @DaanvanderPlas service.rs file calls RuntimeApi which directly interacts with runtime of the chain and service.rs works hand in hand with the client side. Commented Jul 5, 2023 at 9:21
  • @ShubhamGupta could you help me with where exactly service.rs calls the RuntimeApi ? I was going through github.com/substrate-developer-hub/substrate-node-template/blob/… but couldn't find Commented Jul 6, 2023 at 7:58
  • @AbishekBashyal sure will update my answer Commented Jul 6, 2023 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.