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
+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
},