You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to safely and efficiently perform runtime upgrades for your Substrate-based blockchain, including best practices and step-by-step instructions.
33348
+
tutorial_badge: Intermediate
33349
+
---
33350
+
33351
+
# Runtime Upgrades
33352
+
33353
+
## Introduction
33354
+
33355
+
Upgrading the runtime of your Substrate-based blockchain is a core feature that enables you to add new functionality, fix bugs, or optimize performance without requiring a hard fork. Runtime upgrades are performed by submitting a special extrinsic that replaces the existing Wasm runtime code on-chain. This process is trustless, transparent, and can be executed via governance or sudo, depending on your chain's configuration.
33356
+
33357
+
This tutorial will guide you through the process of preparing, submitting, and verifying a runtime upgrade for your parachain or standalone Substrate chain.
33358
+
33359
+
## Prerequisites
33360
+
33361
+
Before proceeding, ensure you have:
33362
+
33363
+
- A working Substrate-based chain (local or testnet)
33364
+
- The latest source code for your runtime, with desired changes implemented and tested
33365
+
- [Rust toolchain](https://www.rust-lang.org/) and [wasm32-unknown-unknown target](https://substrate.dev/docs/en/knowledgebase/getting-started/#add-the-wasm-target) installed
33366
+
- Sufficient privileges to submit a runtime upgrade (sudo or governance access)
33367
+
- [Polkadot.js Apps](https://polkadot.js.org/apps/) or another compatible tool for submitting extrinsics
33368
+
33369
+
## Step 1: Prepare Your Runtime Upgrade
33370
+
33371
+
1. **Implement and Test Changes**
33372
+
- Make your desired changes to the runtime code (e.g., add a pallet, update logic, fix bugs).
33373
+
- Thoroughly test your changes locally using unit tests and integration tests.
33374
+
- Optionally, run your chain locally with the new runtime to ensure it works as expected.
33375
+
33376
+
---
33377
+
33378
+
### Example: Making a Meaningful Runtime Upgrade (Custom Pallet)
33379
+
33380
+
Suppose you have followed the Zero to Hero tutorials and already have a custom pallet integrated into your runtime. Here's how you could make a meaningful upgrade by extending your custom pallet and updating the runtime:
33381
+
33382
+
#### 1. Add a New Feature to the Custom Pallet
33383
+
33384
+
For example, add a new dispatchable function to reset the counter to zero:
33385
+
33386
+
**In `pallets/custom-pallet/src/lib.rs`:**
33387
+
33388
+
```rust
33389
+
#[pallet::call]
33390
+
impl<T: Config> Pallet<T> {
33391
+
// ... existing calls ...
33392
+
33393
+
/// Reset the counter to zero. Only callable by Root.
- Update your pallet's `Event` and `WeightInfo` as needed.
33405
+
- Add unit tests for the new function in `tests.rs`.
33406
+
33407
+
#### 2. Update the Runtime to Use the New Pallet Version
33408
+
33409
+
- If you changed the pallet's public API, ensure the runtime's configuration is updated accordingly (e.g., in `runtime/src/lib.rs` and `runtime/src/configs/mod.rs`).
33410
+
- Re-export the updated pallet if needed.
33411
+
33412
+
#### 3. Bump the Runtime Version
33413
+
33414
+
- In your runtime's `Cargo.toml` and `lib.rs`, increment the `spec_version` and `impl_version` fields. For example:
description: Learn how to safely and efficiently perform runtime upgrades for your Substrate-based blockchain, including best practices and step-by-step instructions.
4
+
tutorial_badge: Intermediate
5
+
---
6
+
7
+
# Runtime Upgrades
8
+
9
+
## Introduction
10
+
11
+
Upgrading the runtime of your Substrate-based blockchain is a core feature that enables you to add new functionality, fix bugs, or optimize performance without requiring a hard fork. Runtime upgrades are performed by submitting a special extrinsic that replaces the existing Wasm runtime code on-chain. This process is trustless, transparent, and can be executed via governance or sudo, depending on your chain's configuration.
12
+
13
+
This tutorial will guide you through the process of preparing, submitting, and verifying a runtime upgrade for your parachain or standalone Substrate chain.
14
+
15
+
## Prerequisites
16
+
17
+
Before proceeding, ensure you have:
18
+
19
+
- A working Substrate-based chain (local or testnet)
20
+
- The latest source code for your runtime, with desired changes implemented and tested
21
+
-[Rust toolchain](https://www.rust-lang.org/) and [wasm32-unknown-unknown target](https://substrate.dev/docs/en/knowledgebase/getting-started/#add-the-wasm-target) installed
22
+
- Sufficient privileges to submit a runtime upgrade (sudo or governance access)
23
+
-[Polkadot.js Apps](https://polkadot.js.org/apps/) or another compatible tool for submitting extrinsics
24
+
25
+
## Step 1: Prepare Your Runtime Upgrade
26
+
27
+
1.**Implement and Test Changes**
28
+
- Make your desired changes to the runtime code (e.g., add a pallet, update logic, fix bugs).
29
+
- Thoroughly test your changes locally using unit tests and integration tests.
30
+
- Optionally, run your chain locally with the new runtime to ensure it works as expected.
31
+
32
+
---
33
+
34
+
### Example: Making a Meaningful Runtime Upgrade (Custom Pallet)
35
+
36
+
Suppose you have followed the Zero to Hero tutorials and already have a custom pallet integrated into your runtime. Here's how you could make a meaningful upgrade by extending your custom pallet and updating the runtime:
37
+
38
+
#### 1. Add a New Feature to the Custom Pallet
39
+
40
+
For example, add a new dispatchable function to reset the counter to zero:
41
+
42
+
**In `pallets/custom-pallet/src/lib.rs`:**
43
+
44
+
```rust
45
+
#[pallet::call]
46
+
impl<T:Config> Pallet<T> {
47
+
// ... existing calls ...
48
+
49
+
/// Reset the counter to zero. Only callable by Root.
- Update your pallet's `Event` and `WeightInfo` as needed.
61
+
- Add unit tests for the new function in `tests.rs`.
62
+
63
+
#### 2. Update the Runtime to Use the New Pallet Version
64
+
65
+
- If you changed the pallet's public API, ensure the runtime's configuration is updated accordingly (e.g., in `runtime/src/lib.rs` and `runtime/src/configs/mod.rs`).
66
+
- Re-export the updated pallet if needed.
67
+
68
+
#### 3. Bump the Runtime Version
69
+
70
+
- In your runtime's `Cargo.toml` and `lib.rs`, increment the `spec_version` and `impl_version` fields. For example:
0 commit comments