Polkadot Fundamentals and Substrate Development
Upgrading a running network
Substrate supports forkless upgrades and in this chapter we will learn how to execute a runtime upgrade.
Most blockchain projects require a hard fork of the code base to support ongoing development of new features or enhancements to existing features. With Substrate, you can deploy enhanced runtime capabilities—including breaking changes—without a hard fork
Runtime upgrades involve updating dependencies for the runtime to include the utility pallet. So, essentially we will be adding the utility pallet as a dependency. The reason it’s called a “runtime upgrade” is because you simply add this dependency to a “running” node - this makes the process very easy and straightforward.
The reason why specifically the utility pallet is added is because it is a stateless pallet with helpers for dispatch management and this is important because function calls that are dispatched to the substrate runtime are not handled by the default pallets available.
These are the objectives for this chapter -
- Use the Sudo pallet to simulate governance for a chain upgrade.
- Upgrade the runtime for a running node to include a new pallet.
- Submit a transaction to upload the modified runtime onto a running node.
Adding utility pallet to runtime -
Open terminal, change directory and run this command -
cargo run --release -- --dev
- Open the Polkadot/Substrate Portal in a browser and connect to the local node.
- Click the left-most dropdown menu to select the network.
- Under Development, select Local Node, then click Switch.
- In the upper left, notice the node template version is the default version 100.
To update the dependencies for the runtime to include the Utility pallet:
- Open a second terminal shell window or tab.
- Change to the root directory where you compiled the Substrate node template.
- Open the runtime/Cargo.toml file in a text editor.
- Locate the [dependencies] section.
- Add the Utility pallet as a dependency.
This is what it should look like -
pallet-utility = {
version = "4.0.0-dev",
default-features = false,
git = "https://github.com/paritytech/substrate.git",
branch = "polkadot-v0.9.37"
}
Locate the [features] section and the list of the default features for the standard binary.
Add the Utility pallet to the list.
"pallet-utility/std",
Adding utility config
To add the Utility types and configuration trait:
Open the runtime/src/lib.rs file in a text editor.
Add the implementation for the Config trait for the Utility pallet.
impl pallet_utility::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
}
Locate the construct_runtime! Macro.
Add the Utility pallet inside the construct_runtime! Macro.
Utility: pallet_utility,
Locate the runtime_version macro.
Update the value for the EXISTENTIAL_DEPOSIT for the Balances pallet.
pub const EXISTENTIAL_DEPOSIT: u128 = 1000 // Update this value.
Increment the spec_version to specify the new runtime version.
spec_version: 101, // Change the spec_version from 100 to 101
Now all we need to do is recompile and connect to the local node -
- Verify that the local node continues to run in the first terminal.
- In the second terminal where you updated the runtime Cargo.toml and lib.rs files, recompile the runtime by running the following command -
cargo build --release --package node-template-runtime
Execute a runtime upgrade
The running node isn't using the upgraded runtime yet. To complete the upgrade, you need to submit a transaction that updates the node to use the upgraded runtime.
To update the network with the upgraded runtime:
- Open the Polkadot/Substrate Portal in a browser and connect to the local node.
- Click Developer and select Extrinsics to submit a transaction for the runtime to use the new build artifact.
- Select the administrative Alice account.
- Select the sudo pallet and the sudoUncheckedWeight(call, weight) function.
- Select system and setCode(code) as the call to make using the Alice account.
- Click file upload, then select or drag and drop the compact and compressed WebAssembly file—node_template_runtime.compact.compressed.wasm—that you generated for the updated runtime.
- For example, navigate to the target/release/wbuild/node-template-runtime directory and select node_template_runtime.compact.compressed.wasm as the file to upload.
- Leave both of the weight parameters set to the default value of 0.
- Click Submit Transaction.
- Review the authorization, then click Sign and Submit.
- Click Network and select Explorer to see that there has been a successful sudo.Sudid event.
- Click Developer and select Extrinsics. Click on submit the following extrinsic and scroll to the bottom of the list. You will see utility as an option.
Verify the constant value by querying the chain state in the Polkadot/Substrate Portal.
- Click Developer and select Chain state.
- Click Constants.
- Select the balances pallet.
- Select existentialDeposit as the constant value as the value to query.
Comments
You need to enroll in the course to be able to comment!