Merge pull request #6 from substrate-developer-hub/shawntabrizi-update-node-template

Update to `d1cd01c74`
main
Shawn Tabrizi 2019-10-21 23:09:35 +09:00 committed by GitHub
commit 43ee95347b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1000 additions and 958 deletions

1522
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,19 @@
[[bin]]
name = 'node-template'
path = 'src/main.rs'
[package]
authors = ['Anonymous']
build = 'build.rs'
edition = '2018'
name = 'node-template'
version = '2.0.0'
[build-dependencies]
vergen = '3.0.4'
[profile.release]
panic = 'unwind'
[dependencies] [dependencies]
derive_more = '0.15.0' derive_more = '0.15.0'
exit-future = '0.1.4' exit-future = '0.1.4'
@ -7,20 +23,20 @@ parking_lot = '0.9.0'
tokio = '0.1.22' tokio = '0.1.22'
trie-root = '0.15.2' trie-root = '0.15.2'
[dependencies.babe] [dependencies.aura]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe' package = 'substrate-consensus-aura'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.babe-primitives] [dependencies.aura-primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe-primitives' package = 'substrate-consensus-aura-primitives'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.basic-authorship] [dependencies.basic-authorship]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-basic-authorship' package = 'substrate-basic-authorship'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.codec] [dependencies.codec]
package = 'parity-scale-codec' package = 'parity-scale-codec'
@ -33,22 +49,22 @@ version = '3.1.3'
[dependencies.grandpa] [dependencies.grandpa]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-finality-grandpa' package = 'substrate-finality-grandpa'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.grandpa-primitives] [dependencies.grandpa-primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-finality-grandpa-primitives' package = 'substrate-finality-grandpa-primitives'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.inherents] [dependencies.inherents]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-inherents' package = 'substrate-inherents'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.network] [dependencies.network]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-network' package = 'substrate-network'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.node-template-runtime] [dependencies.node-template-runtime]
path = 'runtime' path = 'runtime'
@ -56,48 +72,32 @@ path = 'runtime'
[dependencies.primitives] [dependencies.primitives]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-primitives' package = 'substrate-primitives'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.sr-io] [dependencies.sr-io]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.substrate-cli] [dependencies.substrate-cli]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.substrate-client] [dependencies.substrate-client]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.substrate-executor] [dependencies.substrate-executor]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.substrate-service] [dependencies.substrate-service]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.transaction-pool] [dependencies.transaction-pool]
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-transaction-pool' package = 'substrate-transaction-pool'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[profile.release]
panic = 'unwind'
[[bin]]
name = 'node-template'
path = 'src/main.rs'
[workspace] [workspace]
members = ['runtime'] members = ['runtime']
[package]
authors = ['Anonymous']
build = 'build.rs'
edition = '2018'
name = 'node-template'
version = '2.0.0'
[build-dependencies]
vergen = '3.0.4'

View File

@ -10,7 +10,7 @@ Install Rust:
curl https://sh.rustup.rs -sSf | sh curl https://sh.rustup.rs -sSf | sh
``` ```
Install required tools: Initialize your Wasm Build environment:
```bash ```bash
./scripts/init.sh ./scripts/init.sh
@ -19,17 +19,23 @@ Install required tools:
Build Wasm and native code: Build Wasm and native code:
```bash ```bash
cargo build cargo build --release
``` ```
## Run ## Run
### Single node development chain ### Single node development chain
You can start a development chain with: Purge any existing development chain state:
```bash ```bash
cargo run -- --dev ./target/release/node-template purge-chain --dev
```
Start a development chain with:
```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`. Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev`.

View File

@ -1,26 +1,62 @@
[dependencies.babe] [package]
default-features = false authors = ['Anonymous']
git = 'https://github.com/paritytech/substrate.git' edition = '2018'
package = 'srml-babe' name = 'node-template-runtime'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' version = '2.0.0'
[build-dependencies.wasm-builder-runner]
package = 'substrate-wasm-builder-runner'
version = '1.0.2'
[dependencies.babe-primitives] [features]
default-features = false default = ['std']
std = [
'codec/std',
'client/std',
'rstd/std',
'runtime-io/std',
'support/std',
'balances/std',
'aura/std',
'aura-primitives/std',
'grandpa/std',
'executive/std',
'indices/std',
'primitives/std',
'sr-primitives/std',
'randomness-collective-flip/std',
'system/std',
'timestamp/std',
'sudo/std',
'transaction-payment/std',
'version/std',
'serde',
'safe-mix/std',
'offchain-primitives/std',
'substrate-session/std',
]
[dependencies.aura]
default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-babe-primitives' package = 'srml-aura'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.aura-primitives]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-consensus-aura-primitives'
rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.balances] [dependencies.balances]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-balances' package = 'srml-balances'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.client] [dependencies.client]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-client' package = 'substrate-client'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.codec] [dependencies.codec]
default-features = false default-features = false
@ -32,43 +68,49 @@ version = '1.0.0'
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-executive' package = 'srml-executive'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.grandpa] [dependencies.grandpa]
default-features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-grandpa' package = 'srml-grandpa'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.indices] [dependencies.indices]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-indices' package = 'srml-indices'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.offchain-primitives] [dependencies.offchain-primitives]
default-features = false default-features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-offchain-primitives' package = 'substrate-offchain-primitives'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.primitives] [dependencies.primitives]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'substrate-primitives' package = 'substrate-primitives'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.randomness-collective-flip]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-randomness-collective-flip'
rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.rstd] [dependencies.rstd]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'sr-std' package = 'sr-std'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.runtime-io] [dependencies.runtime-io]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'sr-io' package = 'sr-io'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.safe-mix] [dependencies.safe-mix]
default-features = false default-features = false
@ -82,74 +124,45 @@ version = '1.0.101'
[dependencies.sr-primitives] [dependencies.sr-primitives]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.substrate-session] [dependencies.substrate-session]
default-features = false default-features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.sudo] [dependencies.sudo]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-sudo' package = 'srml-sudo'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.support] [dependencies.support]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-support' package = 'srml-support'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.system] [dependencies.system]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-system' package = 'srml-system'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.timestamp] [dependencies.timestamp]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'srml-timestamp' package = 'srml-timestamp'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.transaction-payment]
default_features = false
git = 'https://github.com/paritytech/substrate.git'
package = 'srml-transaction-payment'
rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[dependencies.version] [dependencies.version]
default_features = false default_features = false
git = 'https://github.com/paritytech/substrate.git' git = 'https://github.com/paritytech/substrate.git'
package = 'sr-version' package = 'sr-version'
rev = '3dedd246c62255ba6f9b777ecba318dfc2078d85' rev = 'd1cd01c74e8d5550396cb654f9a3f1b641efdf4c'
[build-dependencies.wasm-builder-runner]
package = 'substrate-wasm-builder-runner'
version = '1.0.2'
[package]
authors = ['Anonymous']
edition = '2018'
name = 'node-template-runtime'
version = '2.0.0'
[features]
default = ['std']
std = [
'codec/std',
'client/std',
'rstd/std',
'runtime-io/std',
'support/std',
'balances/std',
'babe/std',
'babe-primitives/std',
'executive/std',
'indices/std',
'grandpa/std',
'primitives/std',
'sr-primitives/std',
'system/std',
'timestamp/std',
'sudo/std',
'version/std',
'serde',
'safe-mix/std',
'offchain-primitives/std',
'substrate-session/std',
]

View File

@ -19,7 +19,7 @@ use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSourc
fn main() { fn main() {
build_current_project_with_rustflags( build_current_project_with_rustflags(
"wasm_binary.rs", "wasm_binary.rs",
WasmBuilderSource::Crates("1.0.7"), WasmBuilderSource::Crates("1.0.8"),
// This instructs LLD to export __heap_base as a global variable, which is used by the // This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator. // external memory allocator.
"-Clink-arg=--export=__heap_base", "-Clink-arg=--export=__heap_base",

View File

@ -16,13 +16,13 @@ use sr_primitives::{
}; };
use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto}; use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto};
use sr_primitives::weights::Weight; use sr_primitives::weights::Weight;
use babe::{AuthorityId as BabeId};
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
use grandpa::fg_primitives;
use client::{ use client::{
block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api}, block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
runtime_api as client_api, impl_runtime_apis runtime_api as client_api, impl_runtime_apis
}; };
use aura_primitives::sr25519::AuthorityId as AuraId;
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
use grandpa::fg_primitives;
use version::RuntimeVersion; use version::RuntimeVersion;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use version::NativeVersion; use version::NativeVersion;
@ -33,7 +33,7 @@ pub use sr_primitives::BuildStorage;
pub use timestamp::Call as TimestampCall; pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall; pub use balances::Call as BalancesCall;
pub use sr_primitives::{Permill, Perbill}; pub use sr_primitives::{Permill, Perbill};
pub use support::{StorageValue, construct_runtime, parameter_types}; pub use support::{StorageValue, construct_runtime, parameter_types, traits::Randomness};
/// An index to a block. /// An index to a block.
pub type BlockNumber = u32; pub type BlockNumber = u32;
@ -80,14 +80,12 @@ pub mod opaque {
/// Opaque block identifier type. /// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>; pub type BlockId = generic::BlockId<Block>;
pub type SessionHandlers = (Grandpa, Babe);
impl_opaque_keys! { impl_opaque_keys! {
pub struct SessionKeys { pub struct SessionKeys {
#[id(key_types::AURA)]
pub aura: AuraId,
#[id(key_types::GRANDPA)] #[id(key_types::GRANDPA)]
pub grandpa: GrandpaId, pub grandpa: GrandpaId,
#[id(key_types::BABE)]
pub babe: BabeId,
} }
} }
} }
@ -102,20 +100,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
}; };
/// Constants for Babe.
/// Since BABE is probabilistic this is the average expected block time that
/// we are targetting. Blocks will be produced at a minimum duration defined
/// by `SLOT_DURATION`, but some slots will not be allocated to any
/// authority and hence no block will be produced. We expect to have this
/// block time on average following the defined slot duration and the value
/// of `c` configured for BABE (where `1 - c` represents the probability of
/// a slot being empty).
/// This value is only used indirectly to define the unit constants below
/// that are expressed in blocks. The rest of the code should use
/// `SLOT_DURATION` instead (like the timestamp module for calculating the
/// minimum period).
/// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
pub const MILLISECS_PER_BLOCK: u64 = 6000; pub const MILLISECS_PER_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
@ -166,30 +150,22 @@ impl system::Trait for Runtime {
type Header = generic::Header<BlockNumber, BlakeTwo256>; type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type. /// The ubiquitous event type.
type Event = Event; type Event = Event;
/// Update weight (to fee) multiplier per-block.
type WeightMultiplierUpdate = ();
/// The ubiquitous origin type. /// The ubiquitous origin type.
type Origin = Origin; type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first). /// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok. /// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockWeight = MaximumBlockWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block. /// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength; type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions. /// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio; type AvailableBlockRatio = AvailableBlockRatio;
/// Version of the runtime.
type Version = Version; type Version = Version;
} }
parameter_types! { impl aura::Trait for Runtime {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64; type AuthorityId = AuraId;
pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK;
}
impl babe::Trait for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = babe::SameAuthoritiesForever;
} }
impl grandpa::Trait for Runtime { impl grandpa::Trait for Runtime {
@ -215,7 +191,7 @@ parameter_types! {
impl timestamp::Trait for Runtime { impl timestamp::Trait for Runtime {
/// A timestamp: milliseconds since the unix epoch. /// A timestamp: milliseconds since the unix epoch.
type Moment = u64; type Moment = u64;
type OnTimestampSet = Babe; type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod; type MinimumPeriod = MinimumPeriod;
} }
@ -223,8 +199,6 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 500; pub const ExistentialDeposit: u128 = 500;
pub const TransferFee: u128 = 0; pub const TransferFee: u128 = 0;
pub const CreationFee: u128 = 0; pub const CreationFee: u128 = 0;
pub const TransactionBaseFee: u128 = 0;
pub const TransactionByteFee: u128 = 1;
} }
impl balances::Trait for Runtime { impl balances::Trait for Runtime {
@ -236,15 +210,25 @@ impl balances::Trait for Runtime {
type OnNewAccount = Indices; type OnNewAccount = Indices;
/// The ubiquitous event type. /// The ubiquitous event type.
type Event = Event; type Event = Event;
type TransactionPayment = ();
type DustRemoval = (); type DustRemoval = ();
type TransferPayment = (); type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit; type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee; type TransferFee = TransferFee;
type CreationFee = CreationFee; type CreationFee = CreationFee;
}
parameter_types! {
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 1;
}
impl transaction_payment::Trait for Runtime {
type Currency = balances::Module<Runtime>;
type OnTransactionPayment = ();
type TransactionBaseFee = TransactionBaseFee; type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee; type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto; type WeightToFee = ConvertInto;
type FeeMultiplierUpdate = ();
} }
impl sudo::Trait for Runtime { impl sudo::Trait for Runtime {
@ -265,13 +249,15 @@ construct_runtime!(
{ {
System: system::{Module, Call, Storage, Config, Event}, System: system::{Module, Call, Storage, Config, Event},
Timestamp: timestamp::{Module, Call, Storage, Inherent}, Timestamp: timestamp::{Module, Call, Storage, Inherent},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)}, Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Grandpa: grandpa::{Module, Call, Storage, Config, Event}, Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Indices: indices::{default, Config<T>}, Indices: indices::{default, Config<T>},
Balances: balances::{default, Error}, Balances: balances::{default, Error},
TransactionPayment: transaction_payment::{Module, Storage},
Sudo: sudo, Sudo: sudo,
// Used for the module template in `./template.rs` // Used for the module template in `./template.rs`
TemplateModule: template::{Module, Call, Storage, Event<T>}, TemplateModule: template::{Module, Call, Storage, Event<T>},
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
} }
); );
@ -292,7 +278,7 @@ pub type SignedExtra = (
system::CheckEra<Runtime>, system::CheckEra<Runtime>,
system::CheckNonce<Runtime>, system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>, system::CheckWeight<Runtime>,
balances::TakeFees<Runtime> transaction_payment::ChargeTransactionPayment<Runtime>
); );
/// Unchecked extrinsic type as expected by this runtime. /// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>; pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
@ -340,7 +326,7 @@ impl_runtime_apis! {
} }
fn random_seed() -> <Block as BlockT>::Hash { fn random_seed() -> <Block as BlockT>::Hash {
System::random_seed() RandomnessCollectiveFlip::random_seed()
} }
} }
@ -356,27 +342,13 @@ impl_runtime_apis! {
} }
} }
impl fg_primitives::GrandpaApi<Block> for Runtime { impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> { fn slot_duration() -> u64 {
Grandpa::grandpa_authorities() Aura::slot_duration()
} }
}
impl babe_primitives::BabeApi<Block> for Runtime { fn authorities() -> Vec<AuraId> {
fn configuration() -> babe_primitives::BabeConfiguration { Aura::authorities()
// The choice of `c` parameter (where `1 - c` represents the
// probability of a slot being empty), is done in accordance to the
// slot duration and expected target block time, for safely
// resisting network delays of maximum two seconds.
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
secondary_slots: true,
}
} }
} }
@ -386,4 +358,10 @@ impl_runtime_apis! {
opaque::SessionKeys::generate(seed) opaque::SessionKeys::generate(seed)
} }
} }
impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {
Grandpa::grandpa_authorities()
}
}
} }

View File

@ -69,12 +69,11 @@ decl_event!(
mod tests { mod tests {
use super::*; use super::*;
use runtime_io::with_externalities; use primitives::H256;
use primitives::{H256, Blake2Hasher};
use support::{impl_outer_origin, assert_ok, parameter_types}; use support::{impl_outer_origin, assert_ok, parameter_types};
use sr_primitives::{traits::{BlakeTwo256, IdentityLookup}, testing::Header}; use sr_primitives::{
use sr_primitives::weights::Weight; traits::{BlakeTwo256, IdentityLookup}, testing::Header, weights::Weight, Perbill,
use sr_primitives::Perbill; };
impl_outer_origin! { impl_outer_origin! {
pub enum Origin for Test {} pub enum Origin for Test {}
@ -101,7 +100,6 @@ mod tests {
type AccountId = u64; type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>; type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header; type Header = Header;
type WeightMultiplierUpdate = ();
type Event = (); type Event = ();
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockWeight = MaximumBlockWeight;
@ -116,13 +114,13 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to // This function basically just builds a genesis storage key/value store according to
// our desired mockup. // our desired mockup.
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> { fn new_test_ext() -> runtime_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into() system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
} }
#[test] #[test]
fn it_works_for_default_value() { fn it_works_for_default_value() {
with_externalities(&mut new_test_ext(), || { new_test_ext().execute_with(|| {
// Just a dummy test for the dummy funtion `do_something` // Just a dummy test for the dummy funtion `do_something`
// calling the `do_something` function with a value 42 // calling the `do_something` function with a value 42
assert_ok!(TemplateModule::do_something(Origin::signed(1), 42)); assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));

View File

@ -10,7 +10,3 @@ if [ -z $CI_PROJECT_NAME ] ; then
fi fi
rustup target add wasm32-unknown-unknown --toolchain nightly rustup target add wasm32-unknown-unknown --toolchain nightly
# Install wasm-gc. It's useful for stripping slimming down wasm binaries.
command -v wasm-gc || \
cargo +nightly install --git https://github.com/alexcrichton/wasm-gc --force

View File

@ -1,9 +1,9 @@
use primitives::{Pair, Public}; use primitives::{Pair, Public};
use node_template_runtime::{ use node_template_runtime::{
AccountId, BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig, AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY,
}; };
use babe_primitives::{AuthorityId as BabeId}; use aura_primitives::sr25519::{AuthorityId as AuraId};
use grandpa_primitives::{AuthorityId as GrandpaId}; use grandpa_primitives::{AuthorityId as GrandpaId};
use substrate_service; use substrate_service;
@ -31,13 +31,11 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public() .public()
} }
/// Helper function to generate stash, controller and session key from seed /// Helper function to generate an authority key for Aura
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, GrandpaId, BabeId) { pub fn get_authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
( (
get_from_seed::<AccountId>(&format!("{}//stash", seed)), get_from_seed::<AuraId>(s),
get_from_seed::<AccountId>(seed), get_from_seed::<GrandpaId>(s),
get_from_seed::<GrandpaId>(seed),
get_from_seed::<BabeId>(seed),
) )
} }
@ -106,7 +104,7 @@ impl Alternative {
} }
} }
fn testnet_genesis(initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId)>, fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId, root_key: AccountId,
endowed_accounts: Vec<AccountId>, endowed_accounts: Vec<AccountId>,
_enable_println: bool) -> GenesisConfig { _enable_println: bool) -> GenesisConfig {
@ -125,11 +123,11 @@ fn testnet_genesis(initial_authorities: Vec<(AccountId, AccountId, GrandpaId, Ba
sudo: Some(SudoConfig { sudo: Some(SudoConfig {
key: root_key, key: root_key,
}), }),
babe: Some(BabeConfig { aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(), authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}), }),
grandpa: Some(GrandpaConfig { grandpa: Some(GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(), authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
}), }),
} }
} }

View File

@ -5,6 +5,7 @@ use tokio::runtime::Runtime;
pub use substrate_cli::{VersionInfo, IntoExit, error}; pub use substrate_cli::{VersionInfo, IntoExit, error};
use substrate_cli::{informant, parse_and_prepare, ParseAndPrepare, NoCustom}; use substrate_cli::{informant, parse_and_prepare, ParseAndPrepare, NoCustom};
use substrate_service::{AbstractService, Roles as ServiceRoles, Configuration}; use substrate_service::{AbstractService, Roles as ServiceRoles, Configuration};
use aura_primitives::sr25519::{AuthorityPair as AuraPair};
use crate::chain_spec; use crate::chain_spec;
use log::info; use log::info;

View File

@ -3,16 +3,16 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use substrate_client::LongestChain; use substrate_client::LongestChain;
use babe;
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use futures::prelude::*; use futures::prelude::*;
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi}; use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder}; use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
use transaction_pool::{self, txpool::{Pool as TransactionPool}}; use transaction_pool::{self, txpool::{Pool as TransactionPool}};
use inherents::InherentDataProviders; use inherents::InherentDataProviders;
use network::construct_simple_protocol; use network::{construct_simple_protocol};
use substrate_executor::native_executor_instance; use substrate_executor::native_executor_instance;
pub use substrate_executor::NativeExecutor; pub use substrate_executor::NativeExecutor;
use aura_primitives::sr25519::{AuthorityPair as AuraPair};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
// Our native executor instance. // Our native executor instance.
native_executor_instance!( native_executor_instance!(
@ -44,33 +44,26 @@ macro_rules! new_full_start {
.with_transaction_pool(|config, client| .with_transaction_pool(|config, client|
Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::FullChainApi::new(client))) Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::FullChainApi::new(client)))
)? )?
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| { .with_import_queue(|_config, client, mut select_chain, transaction_pool| {
let select_chain = select_chain.take() let select_chain = select_chain.take()
.ok_or_else(|| substrate_service::Error::SelectChainRequired)?; .ok_or_else(|| substrate_service::Error::SelectChainRequired)?;
let (grandpa_block_import, grandpa_link) = let (grandpa_block_import, grandpa_link) =
grandpa::block_import::<_, _, _, node_template_runtime::RuntimeApi, _, _>( grandpa::block_import::<_, _, _, node_template_runtime::RuntimeApi, _, _>(
client.clone(), &*client, select_chain client.clone(), &*client, select_chain
)?; )?;
let justification_import = grandpa_block_import.clone();
let (babe_block_import, babe_link) = babe::block_import( let import_queue = aura::import_queue::<_, _, AuraPair, _>(
babe::Config::get_or_compute(&*client)?, aura::SlotDuration::get_or_compute(&*client)?,
grandpa_block_import, Box::new(grandpa_block_import.clone()),
client.clone(), Some(Box::new(grandpa_block_import.clone())),
client.clone(),
)?;
let import_queue = babe::import_queue(
babe_link.clone(),
babe_block_import.clone(),
Some(Box::new(justification_import)),
None, None,
client.clone(),
client, client,
inherent_data_providers.clone(), inherent_data_providers.clone(),
Some(transaction_pool),
)?; )?;
import_setup = Some((babe_block_import, grandpa_link, babe_link)); import_setup = Some((grandpa_block_import, grandpa_link));
Ok(import_queue) Ok(import_queue)
})?; })?;
@ -83,24 +76,23 @@ macro_rules! new_full_start {
pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>) pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>)
-> Result<impl AbstractService, ServiceError> -> Result<impl AbstractService, ServiceError>
{ {
let is_authority = config.roles.is_authority(); let is_authority = config.roles.is_authority();
let force_authoring = config.force_authoring;
let name = config.name.clone(); let name = config.name.clone();
let disable_grandpa = config.disable_grandpa; let disable_grandpa = config.disable_grandpa;
let force_authoring = config.force_authoring;
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config); let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
let (block_import, grandpa_link) =
import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
let service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))? let service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.with_finality_proof_provider(|client, backend| .with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _) Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)? )?
.build()?; .build()?;
let (block_import, grandpa_link, babe_link) =
import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
if is_authority { if is_authority {
let proposer = basic_authorship::ProposerFactory { let proposer = basic_authorship::ProposerFactory {
client: service.client(), client: service.client(),
@ -111,22 +103,21 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
let select_chain = service.select_chain() let select_chain = service.select_chain()
.ok_or(ServiceError::SelectChainRequired)?; .ok_or(ServiceError::SelectChainRequired)?;
let babe_config = babe::BabeParams { let aura = aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
keystore: service.keystore(), aura::SlotDuration::get_or_compute(&*client)?,
client, client,
select_chain, select_chain,
env: proposer,
block_import, block_import,
sync_oracle: service.network(), proposer,
inherent_data_providers: inherent_data_providers.clone(), service.network(),
inherent_data_providers.clone(),
force_authoring, force_authoring,
babe_link, service.keystore(),
}; )?;
let babe = babe::start_babe(babe_config)?; let select = aura.select(service.on_exit()).then(|_| Ok(()));
let select = babe.select(service.on_exit()).then(|_| Ok(()));
// the BABE authoring task is considered infallible, i.e. if it // the AURA authoring task is considered essential, i.e. if it
// fails we take down the service with it. // fails we take down the service with it.
service.spawn_essential_task(select); service.spawn_essential_task(select);
} }
@ -158,6 +149,7 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
inherent_data_providers: inherent_data_providers.clone(), inherent_data_providers: inherent_data_providers.clone(),
on_exit: service.on_exit(), on_exit: service.on_exit(),
telemetry_on_connect: Some(service.telemetry_on_connect_stream()), telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
}; };
// the GRANDPA voter task is considered infallible, i.e. // the GRANDPA voter task is considered infallible, i.e.
@ -196,26 +188,18 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>( let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>(
client.clone(), backend, Arc::new(fetch_checker), client.clone() client.clone(), backend, Arc::new(fetch_checker), client.clone()
)?; )?;
let finality_proof_import = grandpa_block_import.clone(); let finality_proof_import = grandpa_block_import.clone();
let finality_proof_request_builder = let finality_proof_request_builder =
finality_proof_import.create_finality_proof_request_builder(); finality_proof_import.create_finality_proof_request_builder();
let (babe_block_import, babe_link) = babe::block_import( let import_queue = aura::import_queue::<_, _, AuraPair, ()>(
babe::Config::get_or_compute(&*client)?, aura::SlotDuration::get_or_compute(&*client)?,
grandpa_block_import, Box::new(grandpa_block_import),
client.clone(),
client.clone(),
)?;
let import_queue = babe::import_queue(
babe_link.clone(),
babe_block_import,
None, None,
Some(Box::new(finality_proof_import)), Some(Box::new(finality_proof_import)),
client.clone(),
client, client,
inherent_data_providers.clone(), inherent_data_providers.clone(),
None,
)?; )?;
Ok((import_queue, finality_proof_request_builder)) Ok((import_queue, finality_proof_request_builder))