Odak modu
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 -
Adding utility pallet to runtime -
Open terminal, change directory and run this command -
cargo run --release -- --dev
To update the dependencies for the runtime to include the Utility pallet:
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 -
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:
Verify the constant value by querying the chain state in the Polkadot/Substrate Portal.
Yazılım Kariyerinde İlerlemeni Hızlandıracak Programlar
Patika+ programlarımız ile 4-8 aylık yoğun yazılım kamplarına katıl, temel bilgilerden başlayarak kapsamlı bilgiler edin, yazılım kariyerine başla!
Yorum yapabilmek için derse kayıt olmalısın!