Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tutorials to latest monthly tag #607

Merged
merged 14 commits into from
Nov 30, 2021
51 changes: 22 additions & 29 deletions v3/tutorials/01-create-your-first-substrate-chain/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ To install the Front-end Template:
1. Clone the Front-end Template repository by running the following command:

```
git clone -b latest --depth 1 https://github.com/substrate-developer-hub/substrate-front-end-template
git clone https://github.com/substrate-developer-hub/substrate-front-end-template
```

1. Change to the root of the front-end template directory by running the following command:
Expand Down Expand Up @@ -266,43 +266,38 @@ To start the local Substrate node:
1. Start the node in development mode by running the following command:

```
./target/release/node-template --dev --tmp
./target/release/node-template --dev
```

The `node-template` command-line options specify how you want the running node to operate.
In this case, the options specify the following:

- The `--dev` option specifies that the node is run as a developer node chain specification.

- The `--tmp` option specifies that the node will delete all active data—such as keys,
blockchain database, and networking information when you stop the node by pressing Control-c.
You can use `--tmp` option to ensure you have a clean working state any time you stop and
restart the node.
In this case, the `--dev` option specifies that the node runs in developer mode using the predefined `development` chain specification.
By default, this option also deletes all active data—such as keys, the blockchain database, and networking information when you stop the node by pressing Control-c.
Using the `--dev` option ensures that you have a clean working state any time you stop and restart the node.

1. Verify your node is up and running successfully by reviewing the output displayed in the terminal.

The terminal should display output similar to this:

```
2021-03-16 10:56:51 Running in --dev mode, RPC CORS has been disabled.
2021-03-16 10:56:51 Substrate Node
2021-03-16 10:56:51 ✌️ version 3.0.0-8370ddd-x86_64-linux-gnu
2021-03-16 10:56:51 ❤️ by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2021
2021-03-16 10:56:51 📋 Chain specification: Development
2021-03-16 10:56:51 🏷 Node name: few-size-5380
2021-03-16 10:56:51 👤 Role: AUTHORITY
2021-03-16 10:56:51 💾 Database: RocksDb at /tmp/substrateP1jD7H/chains/dev/db
2021-03-16 10:56:51 ⛓ Native runtime: node-template-100 (node-template-1.tx1.au1)
2021-03-16 10:56:51 🔨 Initializing Genesis block/state (state: 0x17df…04a0, header-hash: 0xc43b…ed16)
2021-03-16 10:56:51 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
2021-03-16 10:56:51 ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
2021-03-16 10:56:51 Using default protocol ID "sup" because none is configured in the chain specs
2021-03-16 10:56:51 🏷 Local node identity is: 12D3KooWQdU84EJCqDr4aqfhb7dxXU2fzd6i2Rn1XdNtsiM5jvEC
2021-03-16 10:56:51 📦 Highest known block at #0
2021-11-24 15:36:35 Running in --dev mode, RPC CORS has been disabled.
2021-11-24 15:36:35 Substrate Node
2021-11-24 15:36:35 ✌️ version 4.0.0-dev-82b7c2c-aarch64-macos
2021-11-24 15:36:35 ❤️ by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2021
2021-11-24 15:36:35 📋 Chain specification: Development
2021-11-24 15:36:35 🏷 Node name: six-wash-9274
2021-11-24 15:36:35 👤 Role: AUTHORITY
2021-11-24 15:36:35 💾 Database: RocksDb at /tmp/substrateP1jD7H/chains/dev/db
2021-11-24 15:36:35 ⛓ Native runtime: node-template-100 (node-template-1.tx1.au1)
2021-11-24 15:36:35 🔨 Initializing Genesis block/state (state: 0xa59b…5331, header-hash: 0xc5d2…37f3)
2021-11-24 15:36:35 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
2021-11-24 15:36:35 ⏱ Loaded block-time = 6s from block 0xc5d2fdad35e14684753f087c1a20f022274e154d39add4f7efe34e95476a37f3
2021-11-24 15:36:35 Using default protocol ID "sup" because none is configured in the chain specs
2021-11-24 15:36:35 🏷 Local node identity is: 12D3KooWG5niQF5bjsFao3D8DZRpUUB6uWZC2pK8hCDZ94zsr8Sc
2021-11-24 15:36:35 📦 Highest known block at #0
...
...
...
2021-03-16 10:56:56 💤 Idle (0 peers), best: #2 (0x05bd…de3f), finalized #0 (0xc43b…ed16), ⬇ 0 ⬆ 0
2021-11-24 15:36:40 💤 Idle (0 peers), best: #1 (0xd2b5…d03f), finalized #0 (0xc5d2…37f3), ⬇ 0 ⬆ 0
```

If the number after `finalized` is increasing, your blockchain is producing new blocks and reaching consensus about the state they describe.
Expand Down Expand Up @@ -385,9 +380,7 @@ To transfer funds to an account:

After a successful transfer, you can continue to explore the front-end template components or
stop the local Substrate node the state changes you made.
With `--tmp` flag specified when running the Node Template, stopping the local node stops the
blockchain and purge all persistent block data that goes with it so you can start with a clean new
state next time you start again.
Because you specified the `--dev` option when you started the node, stopping the local node stops the blockchain and purges all persistent block data so that you can start with a clean state next time you start the node.

To stop the local Substrate node:

Expand Down
127 changes: 42 additions & 85 deletions v3/tutorials/03-permissioned-network/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,23 @@ the right CLI flag as offchain worker is disabled by default for non-authority n

### Build the Node Template

If you already have Node Template cloned, you can just create a
**check out of the v3.0.0 branch** from the base template,
otherwise, clone this branch of the project:
To get started:
1. Clone the node template.

```bash
# Fresh clone, if needed:
git clone -b v3.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
# From the working directory, create a new branch and check it out
cd substrate-node-template
git branch perm-network
git checkout perm-network
```
```bash
git clone -b latest --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
```

You should be able to `build` the project (or `check`) without any error:
1. Build the node template.

```bash
cd substrate-node-template/
cargo build --release
```
```bash
cd substrate-node-template/
cargo build --release
```

If you do run into issues building, checkout [these helpful tips](/v3/getting-started/installation#2-rust-developer-environment).

<br />
<Message
type={`green`}
title={`Tip`}
text="If you do run into issues building, checkout
[these helpful tips](/v3/getting-started/installation#2-rust-developer-environment).
"
/>

Now open the code with your favorite editor, and let's make some changes.
1. Now open the code with your favorite editor, and let's make some changes.

### Add the `node-authorization` pallet

Expand All @@ -149,9 +136,11 @@ First we must add the pallet to our runtime dependencies:
**`runtime/Cargo.toml`**

```TOML
[dependencies]
#--snip--
pallet-node-authorization = { default-features = false, version = '3.0.0' }
[dependencies.pallet-node-authorization]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'devhub/latest'
version = '4.0.0-dev'

#--snip--
[features]
Expand All @@ -163,11 +152,9 @@ std = [
]
```

We need to simulate the governance in our simple blockchain, so we just let a `sudo` admin rule,
configuring the pallet's interface to `EnsureRoot`. In a production environment we sould want to have
difference, governance based checking implemented here. More details of this `Config` can be found in
the pallet's
[reference docs](/rustdocs/latest/pallet_node_authorization/pallet/trait.Config.html).
We need to simulate the governance in our simple blockchain, so we just let a `sudo` admin rule, configuring the pallet's interface to `EnsureRoot`.
In a production environment we should want to have governance based checking implemented here.
More details of this `Config` can be found in the pallet's [reference docs](/rustdocs/latest/pallet_node_authorization/pallet/trait.Config.html).

**`runtime/src/lib.rs`**

Expand Down Expand Up @@ -210,20 +197,15 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
/* --snip-- */

/*** Add This Line ***/
NodeAuthorization: pallet_node_authorization::{Pallet, Call, Storage, Event<T>, Config<T>},

NodeAuthorization: pallet_node_authorization, // <-- add this line
/* --snip-- */

}
);
```

### Add genesis storage for our pallet

`PeerId` is encoded in bs58 format, so we need a new library
[bs58](https://docs.rs/bs58/) in **node/Cargo.toml** to decode it to get its bytes.
`PeerId` is encoded in bs58 format, so we need a new library [bs58](https://docs.rs/bs58/) in **node/Cargo.toml** to decode it to get its bytes.

**`node/cargo.toml`**

Expand Down Expand Up @@ -258,25 +240,24 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {

/* --snip-- */

/*** Add This Block Item ***/
node_authorization: NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone()
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone()
),
],
}),

/* --snip-- */

GenesisConfig {

/* --snip-- */

/*** Add This Block Item ***/
node_authorization: NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone()
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone()
),
],
},
}
}
```

Expand Down Expand Up @@ -316,7 +297,7 @@ Now all the code changes are finished, we are ready to launch our permissioned n
type={`yellow`}
title={`Information`}
text="Stuck? The solution with all required changes to the base template can be found ',
[here](https://github.com/substrate-developer-hub/substrate-node-template/tree/tutorials/solutions/permissioned-network-v3).',
[here](https://github.com/substrate-developer-hub/substrate-node-template/commit/d3eaa1946d647b910a229ff7199f39d349a59e75).',
"
/>

Expand Down Expand Up @@ -458,30 +439,6 @@ finalized in bother terminal logs. Now let's use the
and check the well known nodes of our blockchain. Don't forget to switch to one of
our local nodes running: `127.0.0.1:9944` or `127.0.0.1:9945`.

Firstly, we need to add an extra setting to tell the frontend the type of the `PeerId` used
in node-authorization pallet. Note: the format of `PeerId` here is a wrapper on bs58 decoded
peer id in bytes. Go to the **Settings Developer**
[page in apps](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/settings/developer)
, add following [custom type mapping](https://polkadot.js.org/docs/api/start/types.extend)
information:

```json
// add this as is, or with other required types you have set already:
{
"PeerId": "(Vec<u8>)"
}
```

<br />
<Message
type={`red`}
title={`Warning`}
text="If you don't do this, you will get extrinsic errors of the form:
`Verification Error: Execution(ApiError(Could not convert parameter 'tx' between node and runtime)`.
More details [here](https://polkadot.js.org/docs/api/FAQ#the-node-returns-a-could-not-convert-error-on-send).
"
/>

Then, let's go to **Developer** page, **Chain State sub-tab**, and check the data
stored in the `nodeAuthorization` pallet, `wellKnownNodes` storage. You should be
able to see the peer ids of Alice and Bob's nodes, prefixed with `0x` to show its
Expand Down
32 changes: 20 additions & 12 deletions v3/tutorials/04-forkless-upgrades/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ clients, the first step of this tutorial is to start the template node as-is. Bu
unmodified [Node Template](https://github.com/substrate-developer-hub/substrate-node-template).

```shell
cargo run --release -- --dev --tmp
cargo run --release -- --dev
```

<br />
Expand Down Expand Up @@ -225,11 +225,11 @@ First, add the Scheduler pallet as a dependency in the template node's runtime C
**`runtime/Cargo.toml`**

```toml
[dependencies.pallet-scheduler]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-10'
version = '4.0.0-dev'
[dependencies.pallet-scheduler]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'devhub/latest'
version = '4.0.0-dev'

#--snip--

Expand Down Expand Up @@ -263,6 +263,7 @@ impl pallet_scheduler::Config for Runtime {
type ScheduleOrigin = frame_system::EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type OriginPrivilegeCmp = EqualPrivilegeOnly;
}

// Add the Scheduler pallet inside the construct_runtime! macro.
Expand All @@ -273,11 +274,17 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
/*** snip ***/
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
Scheduler: pallet_scheduler,
}
);
```

Add the following trait dependency at the top of the file:

```rust
pub use frame_support::EqualPrivilegeOnly;
```

The final step to preparing an upgraded FRAME runtime is to increment its
[`spec_version`](/rustdocs/latest/sp_version/struct.RuntimeVersion.html#structfield.spec_version),
which is a member of
Expand Down Expand Up @@ -333,7 +340,7 @@ cargo build --release -p node-template-runtime
type={`yellow`}
title={`Information`}
text="Here is a
[solution](https://github.com/substrate-developer-hub/substrate-node-template/tree/tutorials/solutions/runtime-upgrade-v3)
[solution](https://github.com/substrate-developer-hub/substrate-node-template/tree/tutorials/solutions/runtime-upgrade)
to check against in case you\'re stuck. See the `diff` in the commit history for details.
"
/>
Expand All @@ -354,8 +361,7 @@ more about building Rust code with Cargo.

### Upgrade the Runtime

Use this link to open the Polkadot JS Apps UI and automatically configure the UI to connect to the
local node: https://polkadot.js.org/apps/#/extrinsics?rpc=ws://127.0.0.1:9944.
Use [this link](https://polkadot.js.org/apps/#/extrinsics?rpc=ws://127.0.0.1:9944) to open the Polkadot JS Apps UI and automatically configure the UI to connect to the local node.

<Message
type={`green`}
Expand Down Expand Up @@ -463,7 +469,9 @@ In the previous section, the Scheduler pallet was configured with the `Root` ori
[`ScheduleOrigin`](/rustdocs/latest/pallet_scheduler/trait.Config.html#associatedtype.ScheduleOrigin),
which means that the `sudo` function (_not_ `sudo_unchecked_weight`) can be used to invoke the
`schedule` function. Use this link to open the Polkadot JS Apps UI's Sudo tab:
https://polkadot.js.org/apps/#/sudo?rpc=ws://127.0.0.1:9944. Wait until all the other fields have
https://polkadot.js.org/apps/#/sudo?rpc=ws://127.0.0.1:9944.

Wait until all the other fields have
been filled in before providing the `when` parameter. Leave the `maybe_periodic` parameter empty and
the `priority` parameter at its default value of `0`. Select the System pallet's `set_code` function
as the `call` parameter and provide the Wasm binary as before. Leave the "with weight override"
Expand All @@ -489,4 +497,4 @@ app to query the `existentialDeposit` constant value from the Balances pallet.

- Learn about [storage migrations](/v3/runtime/upgrades#storage-migrations) and
attempt one alongside a runtime upgrade.
- Explore the [how-to guides section on storage migrations](/how-to-guides/v3/storage-migrations/basics)
- Explore the [how-to guides section on storage migrations](/how-to-guides/v3/storage-migrations/basics).
8 changes: 4 additions & 4 deletions v3/tutorials/06-node-metrics/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Prometheus->Grafana: `substrate_peers_count (1582023828, 5), (1582023847, 4) [..
text="We suggest for _testing_ that you download the compiled `bin` programs for these apps
as opposed to fully installing them or using them in docker. Just `download` for your
architecture, and run it from the `working directory` that is convenient for you.
The links above provide instruction on this, and this guide assume you do it this way.
The preceding links provide instructions for downloading the compiled programs, and this guide assumes you follow those instructions.
"
/>

Expand Down Expand Up @@ -143,7 +143,7 @@ be accessed over an interface other than local host with
# start the template node in dev & tmp mode to experiment
# optionally add the `--prometheus-port <PORT>`
# or `--prometheus-external` flags
./target/release/node-template --dev --tmp
./target/release/node-template --dev
```

### Configure Prometheus to scrape your Substrate node
Expand Down Expand Up @@ -264,8 +264,8 @@ If you do create one, consider uploading it to the [community list of
dashboards](https://grafana.com/grafana/dashboards) and letting the Substrate
builder community know it exists by listing in on [Awesome
Substrate](https://github.com/substrate-developer-hub/awesome-substrate)! Here
is ours on [the grafana public
dashboards](https://grafana.com/grafana/dashboards/13759/)
is ours on [the Grafana public
dashboard](https://grafana.com/grafana/dashboards/13759/).

## Next Steps

Expand Down
Loading