Skip to content

Commit a2412d2

Browse files
nuke-web3shawntabriziSacha Lansky
authored andcommitted
Update Node Template (paritytech#10710)
* update node template from downsteam template version = 4.0.0-dev rust setup updated * Update bin/node-template/runtime/Cargo.toml Co-authored-by: Shawn Tabrizi <[email protected]> * Review Rust setup README * Apply suggestions from code review Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Sacha Lansky <[email protected]>
1 parent 9bfd42b commit a2412d2

File tree

6 files changed

+203
-57
lines changed

6 files changed

+203
-57
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ Start the development chain with detailed logging:
7272
```bash
7373
RUST_BACKTRACE=1 ./target/release/node-template -ldebug --dev
7474
```
75+
7576
> Development chain means that the state of our chain will be in a tmp folder while the nodes are
76-
> running. Also, **alice** account will be authority and sudo account as declared in the [genesis
77-
> state](https://github.com/substrate-developer-hub/substrate-node-template/blob/main/node/src/chain_spec.rs#L49).
78-
> At the same time the following accounts will be prefunded:
77+
> running. Also, **alice** account will be authority and sudo account as declared in the
78+
> [genesis state](https://github.com/substrate-developer-hub/substrate-node-template/blob/main/node/src/chain_spec.rs#L49).
79+
> At the same time the following accounts will be pre-funded:
7980
> - Alice
8081
> - Bob
8182
> - Alice//stash
8283
> - Bob//stash
8384
84-
In case of being interested in maintaining the chain' state futher in time a base path other than
85-
a temporary directory must be added so the db can be stored in the provided folder. We could use
86-
this folder to store different chain databases, as a different folder will be created per different
87-
chain that is ran. The following commands shows how to use a newly created folder as our db base
88-
path.
85+
In case of being interested in maintaining the chain' state between runs a base path must be added
86+
so the db can be stored in the provided folder instead of a temporal one. We could use this folder
87+
to store different chain databases, as a different folder will be created per different chain that
88+
is ran. The following commands shows how to use a newly created folder as our db base path.
8989

9090
```bash
9191
// Create a folder to use as the db base path
@@ -103,6 +103,7 @@ $ ls ./my-chain-state/chains/dev
103103
db keystore network
104104
```
105105

106+
106107
### Connect with Polkadot-JS Apps Front-end
107108

108109
Once the node template is running locally, you can connect it with **Polkadot-JS Apps** front-end

bin/node-template/docs/rust-setup.md

Lines changed: 181 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,21 @@
22
title: Installation
33
---
44

5-
This page will guide you through the steps needed to prepare a computer for development with the
6-
Substrate Node Template. Since Substrate is built with
7-
[the Rust programming language](https://www.rust-lang.org/), the first thing you will need to do is
8-
prepare the computer for Rust development - these steps will vary based on the computer's operating
9-
system. Once Rust is configured, you will use its toolchains to interact with Rust projects; the
10-
commands for Rust's toolchains will be the same for all supported, Unix-based operating systems.
5+
This guide is for reference only, please check the latest information on getting starting with Substrate
6+
[here](https://docs.substrate.io/v3/getting-started/installation/).
117

12-
## Unix-Based Operating Systems
8+
This page will guide you through the **2 steps** needed to prepare a computer for **Substrate** development.
9+
Since Substrate is built with [the Rust programming language](https://www.rust-lang.org/), the first
10+
thing you will need to do is prepare the computer for Rust development - these steps will vary based
11+
on the computer's operating system. Once Rust is configured, you will use its toolchains to interact
12+
with Rust projects; the commands for Rust's toolchains will be the same for all supported,
13+
Unix-based operating systems.
1314

14-
Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples
15-
in the Substrate [Tutorials](https://docs.substrate.io/tutorials/v3) and
16-
[How-to Guides](https://docs.substrate.io/how-to-guides/v3) use Unix-style terminals to demonstrate
17-
how to interact with Substrate from the command line.
18-
19-
### macOS
15+
## Build dependencies
2016

21-
Open the Terminal application and execute the following commands:
22-
23-
```bash
24-
# Install Homebrew if necessary https://brew.sh/
25-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
26-
27-
# Make sure Homebrew is up-to-date, install openssl and cmake
28-
brew update
29-
brew install openssl cmake
30-
```
17+
Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples
18+
in the [Substrate Docs](https://docs.substrate.io) use Unix-style terminals to demonstrate how to
19+
interact with Substrate from the command line.
3120

3221
### Ubuntu/Debian
3322

@@ -36,47 +25,201 @@ Use a terminal shell to execute the following commands:
3625
```bash
3726
sudo apt update
3827
# May prompt for location information
39-
sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl
28+
sudo apt install -y git clang curl libssl-dev llvm libudev-dev
4029
```
4130

4231
### Arch Linux
4332

4433
Run these commands from a terminal:
4534

4635
```bash
47-
pacman -Syu --needed --noconfirm cmake gcc openssl-1.0 pkgconf git clang
48-
export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"
49-
export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0"
36+
pacman -Syu --needed --noconfirm curl git clang
5037
```
5138

52-
### Fedora/RHEL/CentOS
39+
### Fedora
5340

54-
Use a terminal to run the following commands:
41+
Run these commands from a terminal:
5542

5643
```bash
57-
# Update
5844
sudo dnf update
59-
# Install packages
60-
sudo dnf install cmake pkgconfig rocksdb rocksdb-devel llvm git libcurl libcurl-devel curl-devel clang
45+
sudo dnf install clang curl git openssl-devel
46+
```
47+
48+
### OpenSUSE
49+
50+
Run these commands from a terminal:
51+
52+
```bash
53+
sudo zypper install clang curl git openssl-devel llvm-devel libudev-devel
54+
```
55+
56+
### macOS
57+
58+
> **Apple M1 ARM**
59+
> If you have an Apple M1 ARM system on a chip, make sure that you have Apple Rosetta 2
60+
> installed through `softwareupdate --install-rosetta`. This is only needed to run the
61+
> `protoc` tool during the build. The build itself and the target binaries would remain native.
62+
63+
Open the Terminal application and execute the following commands:
64+
65+
```bash
66+
# Install Homebrew if necessary https://brew.sh/
67+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
68+
69+
# Make sure Homebrew is up-to-date, install openssl
70+
brew update
71+
brew install openssl
6172
```
6273

63-
## Rust Developer Environment
74+
### Windows
75+
76+
**_PLEASE NOTE:_** Native development of Substrate is _not_ very well supported! It is _highly_
77+
recommend to use [Windows Subsystem Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
78+
(WSL) and follow the instructions for [Ubuntu/Debian](#ubuntudebian).
79+
Please refer to the separate
80+
[guide for native Windows development](https://docs.substrate.io/v3/getting-started/windows-users/).
6481

65-
This project uses [`rustup`](https://rustup.rs/) to help manage the Rust toolchain. First install
66-
and configure `rustup`:
82+
## Rust developer environment
83+
84+
This guide uses <https://rustup.rs> installer and the `rustup` tool to manage the Rust toolchain.
85+
First install and configure `rustup`:
6786

6887
```bash
6988
# Install
70-
curl https://sh.rustup.rs -sSf | sh
89+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
7190
# Configure
7291
source ~/.cargo/env
7392
```
7493

75-
Finally, configure the Rust toolchain:
94+
Configure the Rust toolchain to default to the latest stable version, add nightly and the nightly wasm target:
7695

7796
```bash
7897
rustup default stable
98+
rustup update
99+
rustup update nightly
100+
rustup target add wasm32-unknown-unknown --toolchain nightly
101+
```
102+
103+
## Test your set-up
104+
105+
Now the best way to ensure that you have successfully prepared a computer for Substrate
106+
development is to follow the steps in [our first Substrate tutorial](https://docs.substrate.io/tutorials/v3/create-your-first-substrate-chain/).
107+
108+
## Troubleshooting Substrate builds
109+
110+
Sometimes you can't get the Substrate node template
111+
to compile out of the box. Here are some tips to help you work through that.
112+
113+
### Rust configuration check
114+
115+
To see what Rust toolchain you are presently using, run:
116+
117+
```bash
118+
rustup show
119+
```
120+
121+
This will show something like this (Ubuntu example) output:
122+
123+
```text
124+
Default host: x86_64-unknown-linux-gnu
125+
rustup home: /home/user/.rustup
126+
127+
installed toolchains
128+
--------------------
129+
130+
stable-x86_64-unknown-linux-gnu (default)
131+
nightly-2020-10-06-x86_64-unknown-linux-gnu
132+
nightly-x86_64-unknown-linux-gnu
133+
134+
installed targets for active toolchain
135+
--------------------------------------
136+
137+
wasm32-unknown-unknown
138+
x86_64-unknown-linux-gnu
139+
140+
active toolchain
141+
----------------
142+
143+
stable-x86_64-unknown-linux-gnu (default)
144+
rustc 1.50.0 (cb75ad5db 2021-02-10)
145+
```
146+
147+
As you can see above, the default toolchain is stable, and the
148+
`nightly-x86_64-unknown-linux-gnu` toolchain as well as its `wasm32-unknown-unknown` target is installed.
149+
You also see that `nightly-2020-10-06-x86_64-unknown-linux-gnu` is installed, but is not used unless explicitly defined as illustrated in the [specify your nightly version](#specifying-nightly-version)
150+
section.
151+
152+
### WebAssembly compilation
153+
154+
Substrate uses [WebAssembly](https://webassembly.org) (Wasm) to produce portable blockchain
155+
runtimes. You will need to configure your Rust compiler to use
156+
[`nightly` builds](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) to allow you to
157+
compile Substrate runtime code to the Wasm target.
158+
159+
> There are upstream issues in Rust that need to be resolved before all of Substrate can use the stable Rust toolchain.
160+
> [This is our tracking issue](https://github.com/paritytech/substrate/issues/1252) if you're curious as to why and how this will be resolved.
161+
162+
#### Latest nightly for Substrate `master`
163+
164+
Developers who are building Substrate _itself_ should always use the latest bug-free versions of
165+
Rust stable and nightly. This is because the Substrate codebase follows the tip of Rust nightly,
166+
which means that changes in Substrate often depend on upstream changes in the Rust nightly compiler.
167+
To ensure your Rust compiler is always up to date, you should run:
168+
169+
```bash
170+
rustup update
79171
rustup update nightly
80-
rustup update stable
81172
rustup target add wasm32-unknown-unknown --toolchain nightly
82173
```
174+
175+
> NOTE: It may be necessary to occasionally rerun `rustup update` if a change in the upstream Substrate
176+
> codebase depends on a new feature of the Rust compiler. When you do this, both your nightly
177+
> and stable toolchains will be pulled to the most recent release, and for nightly, it is
178+
> generally _not_ expected to compile WASM without error (although it very often does).
179+
> Be sure to [specify your nightly version](#specifying-nightly-version) if you get WASM build errors
180+
> from `rustup` and [downgrade nightly as needed](#downgrading-rust-nightly).
181+
182+
#### Rust nightly toolchain
183+
184+
If you want to guarantee that your build works on your computer as you update Rust and other
185+
dependencies, you should use a specific Rust nightly version that is known to be
186+
compatible with the version of Substrate they are using; this version will vary from project to
187+
project and different projects may use different mechanisms to communicate this version to
188+
developers. For instance, the Polkadot client specifies this information in its
189+
[release notes](https://github.com/paritytech/polkadot/releases).
190+
191+
```bash
192+
# Specify the specific nightly toolchain in the date below:
193+
rustup install nightly-<yyyy-MM-dd>
194+
```
195+
196+
#### Wasm toolchain
197+
198+
Now, configure the nightly version to work with the Wasm compilation target:
199+
200+
```bash
201+
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
202+
```
203+
204+
### Specifying nightly version
205+
206+
Use the `WASM_BUILD_TOOLCHAIN` environment variable to specify the Rust nightly version a Substrate
207+
project should use for Wasm compilation:
208+
209+
```bash
210+
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --release
211+
```
212+
213+
> Note that this only builds _the runtime_ with the specified nightly. The rest of project will be
214+
> compiled with **your default toolchain**, i.e. the latest installed stable toolchain.
215+
216+
### Downgrading Rust nightly
217+
218+
If your computer is configured to use the latest Rust nightly and you would like to downgrade to a
219+
specific nightly version, follow these steps:
220+
221+
```bash
222+
rustup uninstall nightly
223+
rustup install nightly-<yyyy-MM-dd>
224+
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
225+
```

bin/node-template/node/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "node-template"
3-
version = "3.0.0"
3+
version = "4.0.0-dev"
44
description = "A fresh FRAME-based Substrate node, ready for hacking."
55
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
66
homepage = "https://substrate.io/"
@@ -52,7 +52,8 @@ pallet-transaction-payment-rpc = { version = "4.0.0-dev", path = "../../../frame
5252
frame-benchmarking = { version = "4.0.0-dev", path = "../../../frame/benchmarking" }
5353
frame-benchmarking-cli = { version = "4.0.0-dev", path = "../../../utils/frame/benchmarking-cli" }
5454

55-
node-template-runtime = { version = "3.0.0", path = "../runtime" }
55+
# Local Dependencies
56+
node-template-runtime = { version = "4.0.0-dev", path = "../runtime" }
5657

5758
[build-dependencies]
5859
substrate-build-script-utils = { version = "3.0.0", path = "../../../utils/build-script-utils" }

bin/node-template/pallets/template/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pallet-template"
3-
version = "3.0.0"
3+
version = "4.0.0-dev"
44
description = "FRAME pallet template for defining custom runtime logic."
55
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
66
homepage = "https://substrate.io/"

bin/node-template/runtime/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "node-template-runtime"
3-
version = "3.0.0"
4-
description = "A fresh FRAME-based Substrate runtime, ready for hacking."
3+
version = "4.0.0-dev"
4+
description = "A fresh FRAME-based Substrate node, ready for hacking."
55
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
66
homepage = "https://substrate.io/"
77
edition = "2021"
@@ -27,10 +27,10 @@ pallet-timestamp = { version = "4.0.0-dev", default-features = false, path = "..
2727
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, path = "../../../frame/transaction-payment" }
2828
frame-executive = { version = "4.0.0-dev", default-features = false, path = "../../../frame/executive" }
2929
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" }
30-
sp-block-builder = { path = "../../../primitives/block-builder", default-features = false, version = "4.0.0-dev"}
30+
sp-block-builder = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/block-builder"}
3131
sp-consensus-aura = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/aura" }
3232
sp-core = { version = "4.1.0-dev", default-features = false, path = "../../../primitives/core" }
33-
sp-inherents = { path = "../../../primitives/inherents", default-features = false, version = "4.0.0-dev"}
33+
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents"}
3434
sp-offchain = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/offchain" }
3535
sp-runtime = { version = "4.1.0-dev", default-features = false, path = "../../../primitives/runtime" }
3636
sp-session = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/session" }
@@ -47,7 +47,8 @@ frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "
4747
frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/benchmarking", optional = true }
4848
hex-literal = { version = "0.3.4", optional = true }
4949

50-
pallet-template = { version = "3.0.0", default-features = false, path = "../pallets/template" }
50+
# Local Dependencies
51+
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }
5152

5253
[build-dependencies]
5354
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }

0 commit comments

Comments
 (0)