mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 20:05:49 +00:00
Switch node template to use AuRa (#3790)
* Stuck on service * Make service compile * Remove Grandpa dependency * Update node-template/runtime/Cargo.toml Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix build * Update crypto import * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/runtime/src/lib.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Fix macro dependency * Trying to add grandpa back * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/chain_spec.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Update node-template/src/service.rs Co-Authored-By: André Silva <andre.beat@gmail.com> * Unused import * Use grandpa block import
This commit is contained in:
committed by
André Silva
parent
bf1786b628
commit
c1a24fb537
Generated
+4
-4
@@ -2519,8 +2519,8 @@ dependencies = [
|
|||||||
"substrate-basic-authorship 2.0.0",
|
"substrate-basic-authorship 2.0.0",
|
||||||
"substrate-cli 2.0.0",
|
"substrate-cli 2.0.0",
|
||||||
"substrate-client 2.0.0",
|
"substrate-client 2.0.0",
|
||||||
"substrate-consensus-babe 2.0.0",
|
"substrate-consensus-aura 2.0.0",
|
||||||
"substrate-consensus-babe-primitives 2.0.0",
|
"substrate-consensus-aura-primitives 2.0.0",
|
||||||
"substrate-executor 2.0.0",
|
"substrate-executor 2.0.0",
|
||||||
"substrate-finality-grandpa 2.0.0",
|
"substrate-finality-grandpa 2.0.0",
|
||||||
"substrate-finality-grandpa-primitives 2.0.0",
|
"substrate-finality-grandpa-primitives 2.0.0",
|
||||||
@@ -2545,7 +2545,7 @@ dependencies = [
|
|||||||
"sr-primitives 2.0.0",
|
"sr-primitives 2.0.0",
|
||||||
"sr-std 2.0.0",
|
"sr-std 2.0.0",
|
||||||
"sr-version 2.0.0",
|
"sr-version 2.0.0",
|
||||||
"srml-babe 2.0.0",
|
"srml-aura 2.0.0",
|
||||||
"srml-balances 2.0.0",
|
"srml-balances 2.0.0",
|
||||||
"srml-executive 2.0.0",
|
"srml-executive 2.0.0",
|
||||||
"srml-grandpa 2.0.0",
|
"srml-grandpa 2.0.0",
|
||||||
@@ -2557,7 +2557,7 @@ dependencies = [
|
|||||||
"srml-timestamp 2.0.0",
|
"srml-timestamp 2.0.0",
|
||||||
"srml-transaction-payment 2.0.0",
|
"srml-transaction-payment 2.0.0",
|
||||||
"substrate-client 2.0.0",
|
"substrate-client 2.0.0",
|
||||||
"substrate-consensus-babe-primitives 2.0.0",
|
"substrate-consensus-aura-primitives 2.0.0",
|
||||||
"substrate-offchain-primitives 2.0.0",
|
"substrate-offchain-primitives 2.0.0",
|
||||||
"substrate-primitives 2.0.0",
|
"substrate-primitives 2.0.0",
|
||||||
"substrate-session 2.0.0",
|
"substrate-session 2.0.0",
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ substrate-service = { path = "../core/service" }
|
|||||||
inherents = { package = "substrate-inherents", path = "../core/inherents" }
|
inherents = { package = "substrate-inherents", path = "../core/inherents" }
|
||||||
transaction-pool = { package = "substrate-transaction-pool", path = "../core/transaction-pool" }
|
transaction-pool = { package = "substrate-transaction-pool", path = "../core/transaction-pool" }
|
||||||
network = { package = "substrate-network", path = "../core/network" }
|
network = { package = "substrate-network", path = "../core/network" }
|
||||||
babe = { package = "substrate-consensus-babe", path = "../core/consensus/babe" }
|
aura = { package = "substrate-consensus-aura", path = "../core/consensus/aura" }
|
||||||
babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../core/consensus/babe/primitives" }
|
aura-primitives = { package = "substrate-consensus-aura-primitives", path = "../core/consensus/aura/primitives" }
|
||||||
grandpa = { package = "substrate-finality-grandpa", path = "../core/finality-grandpa" }
|
grandpa = { package = "substrate-finality-grandpa", path = "../core/finality-grandpa" }
|
||||||
grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path = "../core/finality-grandpa/primitives" }
|
grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path = "../core/finality-grandpa/primitives" }
|
||||||
substrate-client = { path = "../core/client" }
|
substrate-client = { path = "../core/client" }
|
||||||
|
|||||||
@@ -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 developer 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`.
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ support = { package = "srml-support", path = "../../srml/support", default_featu
|
|||||||
primitives = { package = "substrate-primitives", path = "../../core/primitives", default_features = false }
|
primitives = { package = "substrate-primitives", path = "../../core/primitives", default_features = false }
|
||||||
substrate-session = { path = "../../core/session", default-features = false }
|
substrate-session = { path = "../../core/session", default-features = false }
|
||||||
balances = { package = "srml-balances", path = "../../srml/balances", default_features = false }
|
balances = { package = "srml-balances", path = "../../srml/balances", default_features = false }
|
||||||
babe = { package = "srml-babe", path = "../../srml/babe", default-features = false }
|
aura = { package = "srml-aura", path = "../../srml/aura", default_features = false }
|
||||||
babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../core/consensus/babe/primitives", default-features = false }
|
aura-primitives = { package = "substrate-consensus-aura-primitives", path = "../../core/consensus/aura/primitives", default_features = false }
|
||||||
|
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default_features = false }
|
||||||
executive = { package = "srml-executive", path = "../../srml/executive", default_features = false }
|
executive = { package = "srml-executive", path = "../../srml/executive", default_features = false }
|
||||||
indices = { package = "srml-indices", path = "../../srml/indices", default_features = false }
|
indices = { package = "srml-indices", path = "../../srml/indices", default_features = false }
|
||||||
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
|
|
||||||
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../../srml/randomness-collective-flip", default_features = false }
|
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../../srml/randomness-collective-flip", default_features = false }
|
||||||
system = { package = "srml-system", path = "../../srml/system", default_features = false }
|
system = { package = "srml-system", path = "../../srml/system", default_features = false }
|
||||||
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default_features = false }
|
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default_features = false }
|
||||||
@@ -41,11 +41,11 @@ std = [
|
|||||||
"runtime-io/std",
|
"runtime-io/std",
|
||||||
"support/std",
|
"support/std",
|
||||||
"balances/std",
|
"balances/std",
|
||||||
"babe/std",
|
"aura/std",
|
||||||
"babe-primitives/std",
|
"aura-primitives/std",
|
||||||
|
'grandpa/std',
|
||||||
"executive/std",
|
"executive/std",
|
||||||
"indices/std",
|
"indices/std",
|
||||||
"grandpa/std",
|
|
||||||
"primitives/std",
|
"primitives/std",
|
||||||
"sr-primitives/std",
|
"sr-primitives/std",
|
||||||
"randomness-collective-flip/std",
|
"randomness-collective-flip/std",
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -180,15 +164,8 @@ impl system::Trait for 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 {
|
||||||
@@ -214,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +249,7 @@ 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},
|
||||||
@@ -365,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()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fn authorities() -> Vec<AuraId> {
|
||||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
Aura::authorities()
|
||||||
fn configuration() -> babe_primitives::BabeConfiguration {
|
|
||||||
// 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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -196,26 +187,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))
|
||||||
|
|||||||
Reference in New Issue
Block a user