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
{{ message }}
This repository was archived by the owner on Aug 20, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: tuts/perform-a-runtime-upgrade/v2.0.0-alpha.6/code.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ If you have completed that tutorial, but your chain is no longer currently runni
20
20
21
21
## Make a Change to the Code
22
22
23
-
Runtime upgrades are necessary when you want to change the code of a live chain. While it is generally advisale to complete the code as much as possible before launching the chain, changes after launch become necessary to do things like fix bugs or add features.
23
+
Runtime upgrades are necessary when you want to change the code of a live chain. While it is generally advisable to complete the code as much as possible before launching the chain, changes after launch become necessary to do things like fix bugs or add features.
24
24
25
25
### Primary Logic Change
26
26
@@ -55,7 +55,7 @@ substrate-node-template
55
55
+-- ...
56
56
```
57
57
58
-
In this file you will see this block of code where the two extrinsics to set the value and increment the value are written.
58
+
In this file you will see this block of code containing two extrinsics used to set and increment the value.
Confirm that your changes are correct so far by running `cargo check -p pallet-template`. If this command completes successfully, you're ready to move on. If not, stop and solve your errors or ask for help before continuing.
97
+
Confirm that your changes are correct so far by running `cargo check -p pallet-template`. If this command completes successfully, you're ready to move on. If not, stop and fix your errors or ask for help before continuing.
98
98
99
99
### Bumping the Spec Version
100
100
@@ -105,7 +105,7 @@ We've already made all of the logic changes we intend to make to our code, and o
Copy file name to clipboardExpand all lines: tuts/perform-a-runtime-upgrade/v2.0.0-alpha.6/migrations.md
+10-8
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,12 @@ lang: en
4
4
title: Storage Migrations
5
5
---
6
6
7
-
The runtime upgrade we just performed completed successfully simply by adding our new feature and incrementing our `spec_version`. In may simple and moderately complex cases this is all that's necessary. In other cases, you may restructure the way data is stored in the blockchain as well as modifying the logic. In these cases, it is necessary to include a migration path for the existing data. In this section we'll explore data migrations.
7
+
The runtime upgrade we just performed completed successfully simply by adding our new feature and incrementing our `spec_version`. In many simple and moderately complex cases this is all that's necessary. In other cases, you may restructure the way data is stored in the blockchain as well as modifying the logic. In these cases, it is necessary to include a migration path for the existing data. In this section we'll explore data migrations.
8
8
9
9
## Primary Code Change
10
10
11
11
For this example we will rename our storage struct from `TemplateModule` to `UpgradedTemplateModule`. To begin we open the `pallets/template/src/lib.rs` file and modify the the following line
12
+
12
13
```rust
13
14
traitStoreforModule<T:Trait> asTemplateModule {
14
15
```
@@ -22,6 +23,7 @@ trait Store for Module<T: Trait> as UpgradedTemplateModule {
22
23
## Bumping the Spec Version
23
24
24
25
As before, we will open the `runtime/src/lib.rs` file and change our `spec_version`. This time we change it to 3.
26
+
25
27
```rust
26
28
/// This runtime version.
27
29
pubconstVERSION:RuntimeVersion=RuntimeVersion {
@@ -40,20 +42,20 @@ Any time you change the storage struct, the name of a storage item, or the way a
40
42
41
43
As you can see from the `decl_storage!` block of our template pallet, we are only dealing with a single storage item that was, and still is called `Something`.
42
44
43
-
The complete code for our migration looks like this, and can be inserted at the bottom of the `decl_module!` block, just like the dispatchable call we aded in the previous upgrade.
45
+
The complete code for our migration looks like this, and can be inserted at the bottom of the `decl_module!` block, just like the dispatchable call we added in the previous upgrade.
1_000// In reality the weight of migration should be determined by benchmarking
53
-
}
54
+
1_000// In reality the weight of a migration should be determined by benchmarking
55
+
}
54
56
```
55
57
56
-
First, his code `use`s two helper functions from frame support that are designed specifically for storage migrations. You will always need to do this.
58
+
First, this code `use`s two helper functions from frame support that are designed specifically for storage migrations. You will always need to do this.
57
59
58
60
Next, it grabs the value out of the old storage location. Notice that we need an explicit type annotation when grabbing the old data. This will always be necessary, and if you are unsure, just check the `decl_storage!` block to learn the type. As parameters, we have supplied the _old_ storage struct name, the storage item name, and an empty array. The third parameter will be necessary when working with storage maps, but we are using a plain storage value, so we leave it blank.
Copy file name to clipboardExpand all lines: tuts/perform-a-runtime-upgrade/v2.0.0-alpha.6/transaction.md
+6-4
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@ In this section we will perform the on-chain runtime upgrading by submitting the
8
8
9
9
## Locating the Wasm Build Artifact
10
10
11
-
At the end of the last section we compiled our runtime. Substrate Runtimes are always compiles to Web Assembly (or Wasm) as well as native code so that the Wasm can be stored on the blockchain and facilitate this forkless upgrade process. Our freshly compiled runtime is stored at `./target/release/wbuild/node-template-runtime/node-template-runtime.compact.wasm`. Ensure this file exists and that it was modified recently.
11
+
At the end of the last section we compiled our runtime. Substrate Runtimes are always compiled to both Web Assembly (or Wasm) and native code so that the Wasm can be stored on the blockchain and facilitate this forkless upgrade process. Our freshly compiled runtime is stored at `./target/release/wbuild/node-template-runtime/node-template-runtime.compact.wasm`. Ensure this file exists and that it was modified recently.
12
+
13
+
> Read more about forkless upgrades and Wasm vs native runtimes in the [executor](/kb/advanced/executor) article.
12
14
13
15
## Starting the User Interface
14
16
@@ -20,16 +22,16 @@ On the `Settings` tab ensure that you are connected to a `Local Node` or `ws://1
20
22
21
23
> Some browsers, notably Firefox, will not connect to a local node from an https website. An easy work around is to try another browser, like Chromium. Another option is to [host this interface locally](https://github.com/polkadot-js/apps#development).
22
24
23
-
## Submit the Transaction
25
+
## Submit the Extrinsic
24
26
25
-
As you can imagine, in a real-world blockchain, we don't want just anyone to be able to change the runtime logic. There is a special transaction for performing these upgrades called, `system::set_code`. This special transaction cannot be called by an ordinary user, and must be called from within the blockchain itself. Substrate provides many useful pallets to provide limited access to this sensitive function as well as others like it. In a real-world blockchain you might use the Democracy or Collective pallets. Our blockchain has a very simple governance mechanism called sudo which allows a privileged user to call sensitive functions like `system::set_code`. In our case, the privileged user is the `Alice` account, so we will submit the upgrade transaction as her.
27
+
As you can imagine, in a real-world blockchain, we don't want just anyone to be able to change the runtime logic. There is a special extrinsic for performing these upgrades called, `system::set_code`. This special transaction cannot be called by an ordinary user, and must be called from within the blockchain itself. Substrate provides many useful pallets to provide limited access to this sensitive function as well as others like it. In a real-world blockchain you might use the Democracy or Collective pallets. Our blockchain has a very simple governance mechanism called "sudo" which allows a privileged user to call sensitive functions like `system::set_code`. In our case, the privileged user is the `Alice` account, so we will submit the upgrade transaction as her.
26
28
27
29
Navigate to the Sudo tab in the interface, and select `system` and `set_code` from the dropdowns. Upload the `node-template-runtime.compact.wasm` file we saw previously, and submit the transaction.
28
30
29
31
TODO screenshot
30
32
31
33
## Try out the Results
32
34
33
-
Once the upgrade transaction is included in a block, you should see a notification in the UI saying the a runtime upgrade has been performed, and the UI will need to be refreshed. Once you've refreshed, you can navigate to the "Extrinsics" tab, select "Template Module" from the dropdown, and see that our new extrinsic, `clear_value` is now available.
35
+
Once the upgrade transaction is included in a block, you should see a notification in the UI saying that a runtime upgrade has been performed, and the UI will need to be refreshed. Once you've refreshed you can navigate to the "Extrinsics" tab, select "Template Module" from the dropdown, and see that our new extrinsic, `clear_value` is now available.
34
36
35
37
Congratulations, you've upgraded your blockchain's runtime! Traditionally the process of upgrading a blockchain would have required a coordinated effort from all (or at least most) of the node operators in the network. But in this case, you have performed the upgrade in a single transaction without even causing a fork!
0 commit comments