Minimal switch of substrate-node to GRANDPA /Aura (#1128)

* add beginnings of SRML grandpa library

* get srml-grandpa compiling

* tests for srml-grandpa

* add optional session integration to grandpa SRML

* start integration into node runtime

* Allow extracting pending change from header digest

* Make it compile on wasm

* make tests compile again

* Move Authority Key fetching into service, simplify service factory construction

* Generalize Authority Consensus Setup system

* Add Authority Setup Docs

* Allow CLI params to be extensible

 - move params to structopts
 - split parsing and default command execution
 - add custom config to node
 - extended parsing of custom config
 - extending params via structop's flatten

* Minor fixes on cli extension params:
 - added docs
 - re-add actual app name, rather than node-name
 - make strategy and subcommand optional

* better cli params

* synchronize GRANDPA and normal node authorities

* Implement grandpa::network for gossip consensus

* run_grandpa in Node

* Fix missed merge error

* Integrate grandpa import queue

* more specific type def

* link up linkhalf and import block

* make grandpa future send

* get compiling

* Fix new params convention and license header

* get it running

* rebuild node runtime WASM

* change logging level

* Update node/cli/src/params.rs

Co-Authored-By: rphmeier <rphmeier@gmail.com>

* Update node/cli/src/params.rs

Co-Authored-By: rphmeier <rphmeier@gmail.com>

* Update node/cli/src/lib.rs

Co-Authored-By: rphmeier <rphmeier@gmail.com>

* Update node/runtime/src/lib.rs

Co-Authored-By: rphmeier <rphmeier@gmail.com>

* Update node/cli/src/lib.rs

Co-Authored-By: rphmeier <rphmeier@gmail.com>

* Clean up and Fixme for mutable config

* Move GrandpaService Integration into grandpa, feature gated but on per default

* Fixing grandpa runtime module test

* Update wasm runtime hashes for tests

* GRANDPA: use post-header hash when logging scheduled changes

* add an extra bit of logging to authorities

* fixing missing constrain

* remove old code

* move `NewAuthorities` to an event in srml-grandpa

* fix node-executor tests to use grandpa log

* Remove GossipConsensus from tests, use newly provided sync-feature, fixes tests

* Update to latest wasm runtimes

* address grumbles

* address grumbles

* only derive deserialize when using std

* Clean up use of Deserialize
This commit is contained in:
Robert Habermeier
2018-11-21 18:42:50 +01:00
committed by GitHub
parent 84da9d4a02
commit 11fe84a742
59 changed files with 1694 additions and 696 deletions
+9
View File
@@ -3,10 +3,12 @@ name = "node-cli"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate node implementation in Rust."
build = "build.rs"
[dependencies]
log = "0.4"
tokio = "0.1.7"
futures = "0.1"
exit-future = "0.1"
substrate-cli = { path = "../../core/cli" }
parity-codec = { version = "2.1" }
@@ -22,9 +24,16 @@ substrate-service = { path = "../../core/service" }
substrate-transaction-pool = { path = "../../core/transaction-pool" }
substrate-network = { path = "../../core/network" }
substrate-consensus-aura = { path = "../../core/consensus/aura" }
substrate-finality-grandpa = { path = "../../core/finality-grandpa" }
sr-primitives = { path = "../../core/sr-primitives" }
node-executor = { path = "../executor" }
structopt = "0.2.13"
substrate-keystore = { path = "../../core/keystore" }
[dev-dependencies]
substrate-service-test = { path = "../../core/service/test" }
[build-dependencies]
substrate-cli = { path = "../../core/cli" }
structopt = "0.2.13"
clap = "~2.32"
+65
View File
@@ -0,0 +1,65 @@
// Copyright 2017-2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
#[macro_use]
extern crate clap;
extern crate substrate_cli as cli;
#[macro_use]
extern crate structopt;
use std::fs;
use std::env;
use clap::Shell;
use std::path::Path;
include!("src/params.rs");
fn main() {
build_shell_completion();
}
/// Build shell completion scripts for all known shells
/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
fn build_shell_completion() {
let shells = [Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell];
for shell in shells.iter() {
build_completion(shell);
}
}
/// Build the shell auto-completion for a given Shell
fn build_completion(shell: &Shell) {
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(dir) => dir,
};
let path = Path::new(&outdir)
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.join("completion-scripts");
fs::create_dir(&path).ok();
let mut app = Params::clap();
app.gen_completions(
"substrate-node",
*shell,
&path);
}
@@ -0,0 +1,41 @@
== Shell completion
The Substrate cli command supports shell auto-completion. For this to work, you will need to run the completion script matching you build and system.
Assuming you built a release version using `cargo build --release` and use `bash` run the following:
[source, shell]
source target/release/completion-scripts/substrate.bash
You can find completion scripts for:
- bash
- fish
- zsh
- elvish
- powershell
To make this change persistent, you can proceed as follow:
.First install
[source, shell]
----
COMPL_DIR=$HOME/.completion
mkdir -p $COMPL_DIR
cp -f target/release/completion-scripts/substrate.bash $COMPL_DIR/
echo "source $COMPL_DIR/substrate.bash" >> $HOME/.bash_profile
source $HOME/.bash_profile
----
.Update
When you build a new version of Substrate, the following will ensure you auto-completion script matches the current binary:
[source, shell]
----
COMPL_DIR=$HOME/.completion
mkdir -p $COMPL_DIR
cp -f target/release/completion-scripts/substrate.bash $COMPL_DIR/
source $HOME/.bash_profile
----
+9 -1
View File
@@ -20,7 +20,7 @@ use primitives::{AuthorityId, ed25519};
use node_primitives::AccountId;
use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
UpgradeKeyConfig, ContractConfig, Permill, Perbill};
UpgradeKeyConfig, ContractConfig, GrandpaConfig, Permill, Perbill};
pub use node_runtime::GenesisConfig;
use substrate_service;
@@ -140,6 +140,10 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
key: endowed_accounts[0].clone(),
_genesis_phantom_data: Default::default(),
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
_genesis_phantom_data: Default::default(),
})
}
}
@@ -269,6 +273,10 @@ pub fn testnet_genesis(
key: upgrade_key,
_genesis_phantom_data: Default::default(),
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
_genesis_phantom_data: Default::default(),
})
}
}
-12
View File
@@ -1,12 +0,0 @@
name: substrate-node
author: "Parity Team <admin@parity.io>"
about: Substrate Node Rust Implementation
args:
- log:
short: l
value_name: LOG_PATTERN
help: Sets a custom logging
takes_value: true
subcommands:
- validator:
about: Run validator node
+36 -2
View File
@@ -34,6 +34,7 @@ extern crate substrate_transaction_pool as transaction_pool;
extern crate substrate_network as network;
extern crate substrate_consensus_aura as consensus;
extern crate substrate_client as client;
extern crate substrate_finality_grandpa as grandpa;
extern crate node_primitives;
#[macro_use]
extern crate substrate_service;
@@ -42,14 +43,19 @@ extern crate substrate_keystore;
#[macro_use]
extern crate log;
#[macro_use]
extern crate structopt;
pub use cli::error;
pub mod chain_spec;
mod service;
mod params;
use tokio::runtime::Runtime;
pub use cli::{VersionInfo, IntoExit};
use substrate_service::{ServiceFactory, Roles as ServiceRoles};
use params::{Params as NodeParams};
use structopt::StructOpt;
use std::ops::Deref;
/// The chain specification option.
@@ -100,9 +106,37 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
T: Into<std::ffi::OsString> + Clone,
E: IntoExit,
{
match cli::prepare_execution::<service::Factory, _, _, _, _>(args, exit, version, load_spec, "substrate-node")? {
let full_version = substrate_service::config::full_version_from_strs(
version.version,
version.commit
);
let matches = match NodeParams::clap()
.name(version.executable_name)
.author(version.author)
.about(version.description)
.version(&(full_version + "\n")[..])
.get_matches_from_safe(args) {
Ok(m) => m,
Err(e) => e.exit(),
};
let (spec, mut config) = cli::parse_matches::<service::Factory, _>(load_spec, version, "substrate-node", &matches)?;
if matches.is_present("grandpa_authority_only") {
config.custom.grandpa_authority = true;
config.custom.grandpa_authority_only = true;
// Authority Setup is only called if validator is set as true
config.roles = ServiceRoles::AUTHORITY;
} else if matches.is_present("grandpa_authority") {
config.custom.grandpa_authority = true;
// Authority Setup is only called if validator is set as true
config.roles = ServiceRoles::AUTHORITY;
}
match cli::execute_default::<service::Factory, _>(spec, exit, &matches)? {
cli::Action::ExecutedInternally => (),
cli::Action::RunService((config, exit)) => {
cli::Action::RunService(exit) => {
info!("Substrate Node");
info!(" version {}", config.full_version());
info!(" by Parity Technologies, 2017, 2018");
+33
View File
@@ -0,0 +1,33 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use structopt::StructOpt;
use cli::CoreParams;
/// Extend params for Node
#[derive(Debug, StructOpt)]
pub struct Params {
/// Should run as a GRANDPA authority node
#[structopt(long = "grandpa-authority", help = "Run Node as a GRANDPA authority, implies --validator")]
grandpa_authority: bool,
/// Should run as a GRANDPA authority node only
#[structopt(long = "grandpa-authority-only", help = "Run Node as a GRANDPA authority only, don't as a usual validator, implies --grandpa-authority")]
grandpa_authority_only: bool,
#[structopt(flatten)]
core: CoreParams
}
+76 -38
View File
@@ -24,12 +24,14 @@ use node_runtime::{GenesisConfig, ClientWithApi};
use node_primitives::Block;
use substrate_service::{
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor,
Roles, TaskExecutor,
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor
};
use node_executor;
use consensus::{import_queue, start_aura, Config as AuraConfig, AuraImportQueue, NothingExtra};
use primitives::ed25519::Pair;
use client;
use std::time::Duration;
use grandpa;
const AURA_SLOT_DURATION: u64 = 6;
@@ -38,6 +40,29 @@ construct_simple_protocol! {
pub struct NodeProtocol where Block = Block { }
}
/// Node specific configuration
pub struct NodeConfig<F: substrate_service::ServiceFactory> {
/// should run as a grandpa authority
pub grandpa_authority: bool,
/// should run as a grandpa authority only, don't validate as usual
pub grandpa_authority_only: bool,
/// grandpa connection to import block
// FIXME: rather than putting this on the config, let's have an actual intermediate setup state
// https://github.com/paritytech/substrate/issues/1134
pub grandpa_link_half: Option<grandpa::LinkHalfForService<F>>,
}
impl<F> Default for NodeConfig<F> where F: substrate_service::ServiceFactory {
fn default() -> NodeConfig<F> {
NodeConfig {
grandpa_authority: false,
grandpa_authority_only: false,
grandpa_link_half: None
}
}
}
construct_service_factory! {
struct Factory {
Block = Block,
@@ -49,49 +74,62 @@ construct_service_factory! {
LightTransactionPoolApi = transaction_pool::ChainApi<client::Client<LightBackend<Self>, LightExecutor<Self>, Block, ClientWithApi>, Block>
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
Genesis = GenesisConfig,
Configuration = (),
Configuration = NodeConfig<Self>,
FullService = FullComponents<Self>
{ |config: FactoryFullConfiguration<Self>, executor: TaskExecutor| {
let is_auth = config.roles == Roles::AUTHORITY;
FullComponents::<Factory>::new(config, executor.clone()).map(move |service|{
if is_auth {
if let Ok(Some(Ok(key))) = service.keystore().contents()
.map(|keys| keys.get(0).map(|k| service.keystore().load(k, "")))
{
info!("Using authority key {}", key.public());
let task = start_aura(
AuraConfig {
local_key: Some(Arc::new(key)),
slot_duration: AURA_SLOT_DURATION,
},
service.client(),
service.proposer(),
service.network(),
);
{ |config: FactoryFullConfiguration<Self>, executor: TaskExecutor|
FullComponents::<Factory>::new(config, executor) },
AuthoritySetup = {
|service: Self::FullService, executor: TaskExecutor, key: Arc<Pair>| {
if service.config.custom.grandpa_authority {
info!("Running Grandpa session as Authority {}", key.public());
let link_half = service.config().custom.grandpa_link_half.as_ref().take()
.expect("Link Half is present for Full Services or setup failed before. qed");
let grandpa_fut = grandpa::run_grandpa(
grandpa::Config {
gossip_duration: Duration::new(4, 0), // FIXME: make this available through chainspec?
local_key: Some(key.clone()),
name: Some(service.config().name.clone())
},
(*link_half).clone(),
grandpa::NetworkBridge::new(service.network())
)?;
executor.spawn(task);
}
}
service
})
executor.spawn(grandpa_fut);
}
if !service.config.custom.grandpa_authority_only {
info!("Using authority key {}", key.public());
executor.spawn(start_aura(
AuraConfig {
local_key: Some(key),
slot_duration: AURA_SLOT_DURATION,
},
service.client(),
service.proposer(),
service.network(),
));
}
Ok(service)
}
},
LightService = LightComponents<Self>
{ |config, executor| <LightComponents<Factory>>::new(config, executor) },
FullImportQueue = AuraImportQueue<Self::Block, FullClient<Self>, NothingExtra>
{ |config, client| Ok(import_queue(
AuraConfig {
local_key: None,
slot_duration: 5
},
client,
NothingExtra,
))
},
FullImportQueue = AuraImportQueue<Self::Block, grandpa::BlockImportForService<Self>, NothingExtra>
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>| {
let (block_import, link_half) = grandpa::block_import::<_, _, _, ClientWithApi, FullClient<Self>>(client.clone(), client)?;
config.custom.grandpa_link_half = Some(link_half);
Ok(import_queue(
AuraConfig {
local_key: None,
slot_duration: 5
},
Arc::new(block_import),
NothingExtra,
))
}},
LightImportQueue = AuraImportQueue<Self::Block, LightClient<Self>, NothingExtra>
{ |config, client| Ok(import_queue(
AuraConfig {
{ |ref mut config, client| Ok(
import_queue(AuraConfig {
local_key: None,
slot_duration: 5
},
+1
View File
@@ -28,6 +28,7 @@ srml-consensus = { path = "../../srml/consensus" }
srml-timestamp = { path = "../../srml/timestamp" }
srml-treasury = { path = "../../srml/treasury" }
srml-contract = { path = "../../srml/contract" }
srml-grandpa = { path = "../../srml/grandpa" }
wabt = "0.4"
[features]
+43 -14
View File
@@ -36,6 +36,7 @@ extern crate node_runtime;
#[cfg(test)] extern crate srml_timestamp as timestamp;
#[cfg(test)] extern crate srml_treasury as treasury;
#[cfg(test)] extern crate srml_contract as contract;
#[cfg(test)] extern crate srml_grandpa as grandpa;
#[cfg(test)] extern crate node_primitives;
#[cfg(test)] extern crate parity_codec as codec;
#[cfg(test)] extern crate sr_io as runtime_io;
@@ -66,7 +67,7 @@ mod tests {
use system::{EventRecord, Phase};
use node_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System,
SystemConfig, Event, Log};
SystemConfig, GrandpaConfig, Event, Log};
use wabt;
const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm");
@@ -262,14 +263,26 @@ mod tests {
treasury: Some(Default::default()),
contract: Some(Default::default()),
upgrade_key: Some(Default::default()),
grandpa: Some(GrandpaConfig {
authorities: vec![ // set these so no GRANDPA events fire when session changes
(Alice.to_raw_public().into(), 1),
(Bob.to_raw_public().into(), 1),
(Charlie.to_raw_public().into(), 1),
],
_genesis_phantom_data: Default::default(),
}),
}.build_storage().unwrap().0)
}
fn changes_trie_log(changes_root: Hash) -> Log {
Log::from(system::RawLog::ChangesTrieRoot::<Hash>(changes_root))
}
fn construct_block(
number: BlockNumber,
parent_hash: Hash,
state_root: Hash,
changes_root: Option<Hash>,
logs: Vec<Log>,
extrinsics: Vec<CheckedExtrinsic>
) -> (Vec<u8>, Hash) {
use trie::ordered_trie_root;
@@ -281,8 +294,8 @@ mod tests {
.into();
let mut digest = generic::Digest::<Log>::default();
if let Some(changes_root) = changes_root {
digest.push(Log::from(system::RawLog::ChangesTrieRoot::<Hash>(changes_root)));
for item in logs {
digest.push(item);
}
let header = Header {
@@ -302,14 +315,16 @@ mod tests {
1,
GENESIS_HASH.into(),
if support_changes_trie {
hex!("a998cf2956b526aecc0887903df66457e640bb2debfd7976b5c7696da31cdaef").into()
hex!("df90128fe9ee27bd61d90308cc25ad262e518d4ba09e5077558be2389780d8e5").into()
} else {
hex!("2caffd5fcc42934e6b758613ff0a7e624a8c5b7c67b7c405bf6985a7e3a19701").into()
hex!("3cb0654b6c47c6532108695327fc68e22f2e67a4b20029c3c9d05a285f9e80a2").into()
},
if support_changes_trie {
Some(hex!("1f8f44dcae8982350c14dee720d34b147e73279f5a2ce1f9781195a991970978").into())
vec![changes_trie_log(
hex!("1f8f44dcae8982350c14dee720d34b147e73279f5a2ce1f9781195a991970978").into(),
)]
} else {
None
vec![]
},
vec![
CheckedExtrinsic {
@@ -328,8 +343,14 @@ mod tests {
construct_block(
2,
block1(false).1,
hex!("72b2afc379ce2161aef95ef6f86a2321867f12b046703ea0af5aed158c2a4f30").into(),
None,
hex!("612d3e3c542b4ce62105f2f1fbc4fef1652d5ba38401795115042bee56a50752").into(),
vec![ // session changes here, so we add a grandpa change signal log.
Log::from(::grandpa::RawLog::AuthoritiesChangeSignal(0, vec![
(Keyring::One.to_raw_public().into(), 1),
(Keyring::Two.to_raw_public().into(), 1),
([3u8; 32].into(), 1),
]))
],
vec![
CheckedExtrinsic {
signed: None,
@@ -351,8 +372,8 @@ mod tests {
construct_block(
1,
GENESIS_HASH.into(),
hex!("5f4461c584ce91dd6862313fd075ffc26dc702fcc1183634ee7b0c5de8b5b4d1").into(),
None,
hex!("17df8f360a4a1bd8d5dc23f05b044f5b14ece43555f97d2058ded47d5e7fb64d").into(),
vec![],
vec![
CheckedExtrinsic {
signed: None,
@@ -460,6 +481,14 @@ mod tests {
phase: Phase::Finalization,
event: Event::staking(staking::RawEvent::Reward(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::grandpa(::grandpa::RawEvent::NewAuthorities(vec![
(Keyring::One.to_raw_public().into(), 1),
(Keyring::Two.to_raw_public().into(), 1),
([3u8; 32].into(), 1),
])),
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Spending(0))
@@ -633,8 +662,8 @@ mod tests {
let b = construct_block(
1,
GENESIS_HASH.into(),
hex!("9885d4297ce0341ec07957d1de32848460565a17ef2ea400df0e2326634914ae").into(),
None,
hex!("81f45b36d1c8f667ac948bc48f8fb61d12aae87d841b6303ab0320ca906d01d2").into(),
vec![],
vec![
CheckedExtrinsic {
signed: None,
+1 -1
View File
@@ -77,7 +77,7 @@ pub type BlockId = generic::BlockId<Block>;
/// Opaque, encoded, unchecked extrinsic.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
impl traits::Extrinsic for UncheckedExtrinsic {
+2
View File
@@ -23,6 +23,7 @@ srml-contract = { path = "../../srml/contract" }
srml-council = { path = "../../srml/council" }
srml-democracy = { path = "../../srml/democracy" }
srml-executive = { path = "../../srml/executive" }
srml-grandpa = { path = "../../srml/grandpa" }
sr-primitives = { path = "../../core/sr-primitives" }
srml-session = { path = "../../srml/session" }
srml-staking = { path = "../../srml/staking" }
@@ -46,6 +47,7 @@ std = [
"srml-council/std",
"srml-democracy/std",
"srml-executive/std",
"srml-grandpa/std",
"sr-primitives/std",
"srml-session/std",
"srml-staking/std",
+26 -10
View File
@@ -47,6 +47,7 @@ extern crate srml_contract as contract;
extern crate srml_council as council;
extern crate srml_democracy as democracy;
extern crate srml_executive as executive;
extern crate srml_grandpa as grandpa;
extern crate srml_session as session;
extern crate srml_staking as staking;
extern crate srml_system as system;
@@ -56,7 +57,6 @@ extern crate srml_upgrade_key as upgrade_key;
#[macro_use]
extern crate sr_version as version;
extern crate node_primitives;
extern crate substrate_finality_grandpa_primitives;
#[cfg(feature = "std")]
use codec::{Encode, Decode};
@@ -65,6 +65,7 @@ use substrate_primitives::u32_trait::{_2, _4};
use node_primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, SessionKey, Signature
};
use grandpa::fg_primitives::{runtime::GrandpaApi, ScheduledChange, id::*};
#[cfg(feature = "std")]
use node_primitives::Block as GBlock;
use client::{block_builder::api::runtime::*, runtime_api::{runtime::*, id::*}};
@@ -85,7 +86,6 @@ use council::seats as council_seats;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
use substrate_finality_grandpa_primitives::{runtime::GrandpaApi, ScheduledChange};
#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildStorage;
@@ -109,7 +109,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: apis_vec!([
(BLOCK_BUILDER, 1),
(TAGGED_TRANSACTION_QUEUE, 1),
(METADATA, 1)
(METADATA, 1),
(GRANDPA_API, 1),
]),
};
@@ -165,7 +166,7 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {
impl session::Trait for Runtime {
type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking;
type OnSessionChange = (Staking, grandpa::SyncedAuthorities<Runtime>);
type Event = Event;
}
@@ -209,6 +210,12 @@ impl upgrade_key::Trait for Runtime {
type Event = Event;
}
impl grandpa::Trait for Runtime {
type SessionKey = SessionKey;
type Log = Log;
type Event = Event;
}
construct_runtime!(
pub enum Runtime with Log(InternalLog: DigestItem<Hash, SessionKey>) where
Block = Block,
@@ -225,6 +232,7 @@ construct_runtime!(
CouncilVoting: council_voting,
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin},
CouncilSeats: council_seats::{Config<T>},
Grandpa: grandpa::{Module, Storage, Config<T>, Log(), Event<T>},
Treasury: treasury,
Contract: contract::{Module, Call, Config<T>, Event<T>},
UpgradeKey: upgrade_key,
@@ -463,15 +471,23 @@ impl_runtime_apis! {
}
}
impl GrandpaApi<Block> for ClientWithApi {
fn grandpa_pending_change(_digest: DigestFor<Block>)
-> Option<ScheduledChange<NumberFor<Block>>> {
unimplemented!("Robert, where is the impl?")
impl GrandpaApi<Block> for Runtime {
fn grandpa_pending_change(digest: DigestFor<Block>)
-> Option<ScheduledChange<NumberFor<Block>>>
{
for log in digest.logs.iter().filter_map(|l| match l {
Log(InternalLog::grandpa(grandpa_signal)) => Some(grandpa_signal),
_=> None
}) {
if let Some(change) = Grandpa::scrape_digest_change(log) {
return Some(change);
}
}
None
}
fn grandpa_authorities() -> Vec<(SessionKey, u64)> {
unimplemented!("Robert, where is the impl?")
Grandpa::grandpa_authorities()
}
}
}
+20 -1
View File
@@ -513,6 +513,7 @@ dependencies = [
"srml-council 0.1.0",
"srml-democracy 0.1.0",
"srml-executive 0.1.0",
"srml-grandpa 0.1.0",
"srml-session 0.1.0",
"srml-staking 0.1.0",
"srml-support 0.1.0",
@@ -521,7 +522,6 @@ dependencies = [
"srml-treasury 0.1.0",
"srml-upgrade-key 0.1.0",
"substrate-client 0.1.0",
"substrate-finality-grandpa-primitives 0.1.0",
"substrate-primitives 0.1.0",
]
@@ -1061,6 +1061,25 @@ dependencies = [
"srml-system 0.1.0",
]
[[package]]
name = "srml-grandpa"
version = "0.1.0"
dependencies = [
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 0.1.0",
"sr-primitives 0.1.0",
"sr-std 0.1.0",
"srml-session 0.1.0",
"srml-support 0.1.0",
"srml-system 0.1.0",
"substrate-finality-grandpa-primitives 0.1.0",
"substrate-primitives 0.1.0",
]
[[package]]
name = "srml-metadata"
version = "0.1.0"
+3 -3
View File
@@ -12,7 +12,6 @@ safe-mix = { version = "1.0", default-features = false }
parity-codec-derive = { version = "2.1" }
parity-codec = { version = "2.1", default-features = false }
substrate-primitives = { path = "../../../core/primitives", default-features = false }
substrate-finality-grandpa-primitives = { path = "../../../core/finality-grandpa/primitives", default-features = false }
substrate-client = { path = "../../../core/client", default-features = false }
sr-std = { path = "../../../core/sr-std", default-features = false }
srml-support = { path = "../../../srml/support", default-features = false }
@@ -29,6 +28,7 @@ srml-system = { path = "../../../srml/system", default-features = false }
srml-timestamp = { path = "../../../srml/timestamp", default-features = false }
srml-treasury = { path = "../../../srml/treasury", default-features = false }
srml-upgrade-key = { path = "../../../srml/upgrade-key", default-features = false }
srml-grandpa = { path = "../../../srml/grandpa", default-features = false }
sr-version = { path = "../../../core/sr-version", default-features = false }
node-primitives = { path = "../../primitives", default-features = false }
@@ -39,8 +39,8 @@ std = [
"parity-codec/std",
"substrate-primitives/std",
"substrate-client/std",
"substrate-finality-grandpa-primitives/std",
"sr-std/std",
"sr-primitives/std",
"srml-support/std",
"srml-balances/std",
"srml-consensus/std",
@@ -48,13 +48,13 @@ std = [
"srml-council/std",
"srml-democracy/std",
"srml-executive/std",
"sr-primitives/std",
"srml-session/std",
"srml-staking/std",
"srml-system/std",
"srml-timestamp/std",
"srml-treasury/std",
"srml-upgrade-key/std",
"srml-grandpa/std",
"sr-version/std",
"node-primitives/std",
]