mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 17:41:08 +00:00
Fix service setup for non-validator nodes (#378)
* Fix service setup for non-validator nodes * Apply suggestions
This commit is contained in:
committed by
Gavin Wood
parent
2c6409a942
commit
da39da8a04
@@ -169,6 +169,16 @@ pub fn register_validator<O: KnownOracle + 'static>(
|
|||||||
RegisteredMessageValidator { inner: validator as _ }
|
RegisteredMessageValidator { inner: validator as _ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register a gossip validator for a non-authority node.
|
||||||
|
pub fn register_non_authority_validator(service: Arc<NetworkService>) {
|
||||||
|
service.with_gossip(|gossip, ctx|
|
||||||
|
gossip.register_validator(
|
||||||
|
ctx,
|
||||||
|
POLKADOT_ENGINE_ID,
|
||||||
|
Arc::new(substrate_network::consensus_gossip::DiscardAll)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// A registered message validator.
|
/// A registered message validator.
|
||||||
///
|
///
|
||||||
/// Create this using `register_validator`.
|
/// Create this using `register_validator`.
|
||||||
|
|||||||
+52
-92
@@ -25,7 +25,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use polkadot_primitives::{parachain, Block, Hash, BlockId};
|
use polkadot_primitives::{parachain, Block, Hash, BlockId};
|
||||||
use polkadot_runtime::{GenesisConfig, RuntimeApi};
|
use polkadot_runtime::{GenesisConfig, RuntimeApi};
|
||||||
use polkadot_network::gossip::{self as network_gossip, Known};
|
use polkadot_network::{gossip::{self as network_gossip, Known}, validation::ValidationNetwork};
|
||||||
use service::{
|
use service::{
|
||||||
FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor,
|
FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor,
|
||||||
error::Error as ServiceError, TelemetryOnConnect
|
error::Error as ServiceError, TelemetryOnConnect
|
||||||
@@ -198,10 +198,6 @@ service::construct_service_factory! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.config().roles != service::Roles::AUTHORITY {
|
|
||||||
return Ok(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
if service.config().custom.collating_for.is_some() {
|
if service.config().custom.collating_for.is_some() {
|
||||||
info!(
|
info!(
|
||||||
"The node cannot start as an authority because it is also configured to run as a collator."
|
"The node cannot start as an authority because it is also configured to run as a collator."
|
||||||
@@ -241,59 +237,62 @@ service::construct_service_factory! {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
use polkadot_network::validation::ValidationNetwork;
|
if service.config().roles.is_authority() {
|
||||||
let extrinsic_store = {
|
let extrinsic_store = {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
let mut path = PathBuf::from(service.config().database_path.clone());
|
let mut path = PathBuf::from(service.config().database_path.clone());
|
||||||
path.push("availability");
|
path.push("availability");
|
||||||
|
|
||||||
av_store::Store::new(::av_store::Config {
|
av_store::Store::new(::av_store::Config {
|
||||||
cache_size: None,
|
cache_size: None,
|
||||||
path,
|
path,
|
||||||
})?
|
})?
|
||||||
};
|
};
|
||||||
|
|
||||||
// collator connections and validation network both fulfilled by this
|
// collator connections and validation network both fulfilled by this
|
||||||
let validation_network = ValidationNetwork::new(
|
let validation_network = ValidationNetwork::new(
|
||||||
service.network(),
|
service.network(),
|
||||||
service.on_exit(),
|
service.on_exit(),
|
||||||
gossip_validator,
|
gossip_validator,
|
||||||
service.client(),
|
service.client(),
|
||||||
polkadot_network::validation::WrappedExecutor(service.spawn_task_handle()),
|
polkadot_network::validation::WrappedExecutor(service.spawn_task_handle()),
|
||||||
);
|
);
|
||||||
let proposer = consensus::ProposerFactory::new(
|
let proposer = consensus::ProposerFactory::new(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
select_chain.clone(),
|
select_chain.clone(),
|
||||||
validation_network.clone(),
|
validation_network.clone(),
|
||||||
validation_network,
|
validation_network,
|
||||||
service.transaction_pool(),
|
service.transaction_pool(),
|
||||||
Arc::new(service.spawn_task_handle()),
|
Arc::new(service.spawn_task_handle()),
|
||||||
service.keystore(),
|
service.keystore(),
|
||||||
extrinsic_store,
|
extrinsic_store,
|
||||||
polkadot_runtime::constants::time::SLOT_DURATION,
|
polkadot_runtime::constants::time::SLOT_DURATION,
|
||||||
service.config().custom.max_block_data_size,
|
service.config().custom.max_block_data_size,
|
||||||
);
|
);
|
||||||
|
|
||||||
let client = service.client();
|
let client = service.client();
|
||||||
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
||||||
|
|
||||||
let babe_config = babe::BabeParams {
|
let babe_config = babe::BabeParams {
|
||||||
config: Config::get_or_compute(&*client)?,
|
config: Config::get_or_compute(&*client)?,
|
||||||
keystore: service.keystore(),
|
keystore: service.keystore(),
|
||||||
client,
|
client,
|
||||||
select_chain,
|
select_chain,
|
||||||
block_import,
|
block_import,
|
||||||
env: proposer,
|
env: proposer,
|
||||||
sync_oracle: service.network(),
|
sync_oracle: service.network(),
|
||||||
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||||
force_authoring: service.config().force_authoring,
|
force_authoring: service.config().force_authoring,
|
||||||
time_source: babe_link,
|
time_source: babe_link,
|
||||||
};
|
};
|
||||||
|
|
||||||
let babe = start_babe(babe_config)?;
|
let babe = start_babe(babe_config)?;
|
||||||
let select = babe.select(service.on_exit()).then(|_| Ok(()));
|
let select = babe.select(service.on_exit()).then(|_| Ok(()));
|
||||||
service.spawn_task(Box::new(select));
|
service.spawn_essential_task(Box::new(select));
|
||||||
|
} else {
|
||||||
|
network_gossip::register_non_authority_validator(service.network());
|
||||||
|
}
|
||||||
|
|
||||||
let config = grandpa::Config {
|
let config = grandpa::Config {
|
||||||
// FIXME substrate#1578 make this available through chainspec
|
// FIXME substrate#1578 make this available through chainspec
|
||||||
@@ -326,7 +325,7 @@ service::construct_service_factory! {
|
|||||||
on_exit: service.on_exit(),
|
on_exit: service.on_exit(),
|
||||||
telemetry_on_connect: Some(telemetry_on_connect),
|
telemetry_on_connect: Some(telemetry_on_connect),
|
||||||
};
|
};
|
||||||
service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
service.spawn_essential_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
||||||
},
|
},
|
||||||
(_, true) => {
|
(_, true) => {
|
||||||
grandpa::setup_disabled_grandpa(
|
grandpa::setup_disabled_grandpa(
|
||||||
@@ -336,45 +335,6 @@ service::construct_service_factory! {
|
|||||||
)?;
|
)?;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// let config = grandpa::Config {
|
|
||||||
// // FIXME #1578 make this available through chainspec
|
|
||||||
// gossip_duration: Duration::from_millis(333),
|
|
||||||
// justification_period: 4096,
|
|
||||||
// name: Some(service.config().name.clone()),
|
|
||||||
// keystore: Some(service.keystore()),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if !service.config().disable_grandpa {
|
|
||||||
// if service.config().roles.is_authority() {
|
|
||||||
// let telemetry_on_connect = TelemetryOnConnect {
|
|
||||||
// telemetry_connection_sinks: service.telemetry_on_connect_stream(),
|
|
||||||
// };
|
|
||||||
// let grandpa_config = grandpa::GrandpaParams {
|
|
||||||
// config: config,
|
|
||||||
// link: link_half,
|
|
||||||
// network: service.network(),
|
|
||||||
// inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
|
||||||
// on_exit: service.on_exit(),
|
|
||||||
// telemetry_on_connect: Some(telemetry_on_connect),
|
|
||||||
// };
|
|
||||||
// service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
|
||||||
// } else {
|
|
||||||
// service.spawn_task(Box::new(grandpa::run_grandpa_observer(
|
|
||||||
// config,
|
|
||||||
// link_half,
|
|
||||||
// service.network(),
|
|
||||||
// service.on_exit(),
|
|
||||||
// )?));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // regardless of whether grandpa is started or not, when
|
|
||||||
// // authoring blocks we expect inherent data regarding what our
|
|
||||||
// // last finalized block is, to be available.
|
|
||||||
// grandpa::register_finality_tracker_inherent_data_provider(
|
|
||||||
// service.client(),
|
|
||||||
// &service.config().custom.inherent_data_providers,
|
|
||||||
// )?;
|
|
||||||
|
|
||||||
Ok(service)
|
Ok(service)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user