Skip to content
Snippets Groups Projects
Unverified Commit 3718adb0 authored by Dan Forbes's avatar Dan Forbes Committed by GitHub
Browse files

Upgrade to v2.0.0-rc5 (#65)

parent f8924ad3
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
[![Try on playground](https://img.shields.io/badge/Playground-node_template-brightgreen?logo=Parity%20Substrate)](https://playground-staging.substrate.dev/?deploy=node-template)
# Substrate Node Template
A new FRAME-based Substrate node, ready for hacking :rocket:
## Local Development
Follow these steps to prepare your local environment for Substrate development :hammer_and_wrench:
Follow these steps to prepare a local Substrate development environment :hammer_and_wrench:
### Simple Method
### Simple Setup
You can install all the required dependencies with a single command (be patient, this can take up
to 30 minutes).
Install all the required dependencies with a single command (be patient, this can take up to 30
minutes).
```bash
curl https://getsubstrate.io -sSf | bash -s -- --fast
```
### Manual Method
Manual steps for Linux-based systems can be found below; you can
[find more information at substrate.dev](https://substrate.dev/docs/en/knowledgebase/getting-started/#manual-installation).
Install Rust:
### Manual Setup
```bash
curl https://sh.rustup.rs -sSf | sh
```
Initialize your Wasm Build environment:
```bash
./scripts/init.sh
```
Find manual setup instructions at the
[Substrate Developer Hub](https://substrate.dev/docs/en/knowledgebase/getting-started/#manual-installation).
### Build
Once you have prepared your local development environment, you can build the node template. Use this
command to build the [Wasm](https://substrate.dev/docs/en/knowledgebase/advanced/executor#wasm-execution)
and [native](https://substrate.dev/docs/en/knowledgebase/advanced/executor#native-execution) code:
Once the development environment is set up, build the node template. This command will build the
[Wasm](https://substrate.dev/docs/en/knowledgebase/advanced/executor#wasm-execution) and
[native](https://substrate.dev/docs/en/knowledgebase/advanced/executor#native-execution) code:
```bash
cargo build --release
```
## Playground [![Try on playground](https://img.shields.io/badge/Playground-node_template-brightgreen?logo=Parity%20Substrate)](https://playground-staging.substrate.dev/?deploy=node-template)
[The Substrate Playground](https://playground-staging.substrate.dev/?deploy=node-template) is an
online development environment that allows you to take advantage of a pre-configured container
with pre-compiled build artifacts :woman_cartwheeling:
## Run
### Single Node Development Chain
Purge any existing developer chain state:
Purge any existing dev chain state:
```bash
./target/release/node-template purge-chain --dev
```
Start a development chain with:
Start a dev chain:
```bash
./target/release/node-template --dev
```
Detailed logs may be shown by running the node with the following environment variables set:
`RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev`.
Or, start a dev chain with detailed logging:
```bash
RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/node-template -lruntime=debug --dev
```
### Multi-Node Local Testnet
If you want to see the multi-node consensus algorithm in action, refer to
[our Start a Private Network tutorial](https://substrate.dev/docs/en/tutorials/start-a-private-network/).
## Template Structure
A Substrate project such as this consists of a number of components that are spread across a few
directories.
### Node
A blockchain node is an application that allows users to participate in a blockchain network.
Substrate-based blockchain nodes expose a number of capabilities:
- Networking: Substrate nodes use the [`libp2p`](https://libp2p.io/) networking stack to allow the
nodes in the network to communicate with one another.
- Consensus: Blockchains must have a way to come to
[consensus](https://substrate.dev/docs/en/knowledgebase/advanced/consensus) on the state of the
network. Substrate makes it possible to supply custom consensus engines and also ships with
several consensus mechanisms that have been built on top of Web3 Foundation research.
- RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes.
There are several files in the `node` directory - take special note of the following:
- [`chain_spec.rs`](./node/src/chain_spec.rs): A
[chain specification](https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec) is a
source code file that defines a Substrate chain's initial (genesis) state. Chain specifications
are useful for development and testing, and critical when architecting the launch of a
production chain. Take note of the `development_config` and `testnet_genesis` functions, which
are used to define the genesis state for the local development chain configuration. These
functions identify some
[well-known accounts](https://substrate.dev/docs/en/knowledgebase/integrate/subkey#well-known-keys)
and use them to configure the blockchain's initial state.
- [`service.rs`](./node/src/service.rs): This file defines the node implementation. Take note of
the libraries that this file imports and the names of the functions it invokes. In particular,
there are references to consensus-related topics, such as the
[longest chain rule](https://substrate.dev/docs/en/knowledgebase/advanced/consensus#longest-chain-rule),
the [Aura](https://substrate.dev/docs/en/knowledgebase/advanced/consensus#aura) block authoring
mechanism and the
[GRANDPA](https://substrate.dev/docs/en/knowledgebase/advanced/consensus#grandpa) finality
gadget.
After the node has been [built](#build), refer to the embedded documentation to learn more about the
capabilities and configuration parameters that it exposes:
```shell
./target/release/node-template --help
```
### Runtime
The Substrate project in this repository uses the
[FRAME](https://substrate.dev/docs/en/knowledgebase/runtime/frame) framework to construct a
blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules
called "pallets". At the heart of FRAME is a helpful
[macro language](https://substrate.dev/docs/en/knowledgebase/runtime/macros) that makes it easy to
create pallets and flexibly compose them to create blockchains that can address a variety of needs.
Review the [FRAME runtime implementation](./runtime/src/lib.rs) included in this template and note
the following:
- This file configures several pallets to include in the runtime. Each pallet configuration is
defined by a code block that begins with `impl $PALLET_NAME::Trait for Runtime`.
- The pallets are composed into a single runtime by way of the
[`construct_runtime!`](https://crates.parity.io/frame_support/macro.construct_runtime.html)
macro, which is part of the core
[FRAME Support](https://substrate.dev/docs/en/knowledgebase/runtime/frame#support-library)
library.
### Pallets
The runtime in this project is constructed using many FRAME pallets that ship with the
[core Substrate repository](https://github.com/paritytech/substrate/tree/master/frame) and a
template pallet that is [defined in the `pallets`](./pallets/template/src/lib.rs) directory.
A FRAME pallet is compromised of a number of blockchain primitives:
- Storage: FRAME defines a rich set of powerful
[storage abstractions](https://substrate.dev/docs/en/knowledgebase/runtime/storage) that makes
it easy to use Substrate's efficient key-value database to manage the evolving state of a
blockchain.
- Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched)
from outside of the runtime in order to update its state.
- Events: Substrate uses [events](https://substrate.dev/docs/en/knowledgebase/runtime/events) to
notify users of important changes in the runtime.
- Errors: When a dispatchable fails, it returns an error.
- Trait: The `Trait` configuration interface is used to define the types and parameters upon which
a FRAME pallet depends.
### Run in Docker
First, install [Docker](https://docs.docker.com/get-docker/) and
......
[package]
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']
build = 'build.rs'
description = 'Substrate Node template'
description = 'A fresh FRAME-based Substrate node, ready for hacking.'
edition = '2018'
homepage = 'https://substrate.dev'
license = 'Unlicense'
name = 'node-template'
repository = 'https://github.com/substrate-developer-hub/substrate-node-template/'
version = '2.0.0-rc4'
version = '2.0.0-rc5'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
......@@ -22,96 +23,97 @@ structopt = '0.3.8'
[dependencies.node-template-runtime]
path = '../runtime'
version = '2.0.0-rc4'
version = '2.0.0-rc5'
[dependencies.sc-basic-authorship]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-cli]
features = ['wasmtime']
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-client-api]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sc-consensus]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-consensus-aura]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-executor]
features = ['wasmtime']
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-finality-grandpa]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-network]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-service]
features = ['wasmtime']
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sc-transaction-pool]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sp-consensus]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sp-consensus-aura]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '0.8.0-rc4'
tag = 'v2.0.0-rc5'
version = '0.8.0-rc5'
[dependencies.sp-core]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sp-finality-grandpa]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sp-inherents]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sp-runtime]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[dependencies.sp-transaction-pool]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
[build-dependencies.substrate-build-script-utils]
git = 'https://github.com/paritytech/substrate.git'
tag = 'v2.0.0-rc4'
version = '2.0.0-rc4'
tag = 'v2.0.0-rc5'
version = '2.0.0-rc5'
This diff is collapsed.
......@@ -18,46 +18,48 @@
use crate::chain_spec;
use crate::cli::Cli;
use crate::service;
use sc_cli::SubstrateCli;
use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};
use sc_service::ServiceParams;
use crate::service::new_full_params;
impl SubstrateCli for Cli {
fn impl_name() -> &'static str {
"Substrate Node"
fn impl_name() -> String {
"Substrate Node".into()
}
fn impl_version() -> &'static str {
env!("SUBSTRATE_CLI_IMPL_VERSION")
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}
fn description() -> &'static str {
env!("CARGO_PKG_DESCRIPTION")
fn description() -> String {
env!("CARGO_PKG_DESCRIPTION").into()
}
fn author() -> &'static str {
env!("CARGO_PKG_AUTHORS")
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}
fn support_url() -> &'static str {
"support.anonymous.an"
fn support_url() -> String {
"support.anonymous.an".into()
}
fn copyright_start_year() -> i32 {
2017
}
fn executable_name() -> &'static str {
env!("CARGO_PKG_NAME")
}
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
"dev" => Box::new(chain_spec::development_config()?),
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
})
}
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&node_template_runtime::VERSION
}
}
/// Parse and run command line arguments
......@@ -67,15 +69,18 @@ pub fn run() -> sc_cli::Result<()> {
match &cli.subcommand {
Some(subcommand) => {
let runner = cli.create_runner(subcommand)?;
runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
runner.run_subcommand(subcommand, |config| {
let (ServiceParams { client, backend, task_manager, import_queue, .. }, ..)
= new_full_params(config)?;
Ok((client, backend, import_queue, task_manager))
})
}
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node(
service::new_light,
service::new_full,
node_template_runtime::VERSION
)
runner.run_node_until_exit(|config| match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
})
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Creating mock runtime here
use crate::{Module, Trait};
use sp_core::H256;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
......@@ -12,9 +10,8 @@ impl_outer_origin! {
pub enum Origin for Test {}
}
// For testing the pallet, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of pallets we want to use.
// Configure a mock runtime to test the pallet.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
......@@ -23,6 +20,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl system::Trait for Test {
type BaseCallFilter = ();
type Origin = Origin;
......@@ -48,14 +46,16 @@ impl system::Trait for Test {
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl Trait for Test {
type Event = ();
}
pub type TemplateModule = Module<Test>;
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment