mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 09:45:41 +00:00
Protocol ID configurable in the chain spec (#811)
* Protocol ID configurable in the chain spec * Removed obsolete const
This commit is contained in:
committed by
Gav Wood
parent
37102611d4
commit
0ab3b2de35
@@ -76,6 +76,7 @@ struct ChainSpecFile {
|
|||||||
pub id: String,
|
pub id: String,
|
||||||
pub boot_nodes: Vec<String>,
|
pub boot_nodes: Vec<String>,
|
||||||
pub telemetry_url: Option<String>,
|
pub telemetry_url: Option<String>,
|
||||||
|
pub protocol_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A configuration of a chain. Can be used to build a genesis block.
|
/// A configuration of a chain. Can be used to build a genesis block.
|
||||||
@@ -101,6 +102,10 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
|
|||||||
self.spec.telemetry_url.as_ref().map(String::as_str)
|
self.spec.telemetry_url.as_ref().map(String::as_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn protocol_id(&self) -> Option<&str> {
|
||||||
|
self.spec.protocol_id.as_ref().map(String::as_str)
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse json content into a `ChainSpec`
|
/// Parse json content into a `ChainSpec`
|
||||||
pub fn from_embedded(json: &'static [u8]) -> Result<Self, String> {
|
pub fn from_embedded(json: &'static [u8]) -> Result<Self, String> {
|
||||||
let spec = json::from_slice(json).map_err(|e| format!("Error parsing spec file: {}", e))?;
|
let spec = json::from_slice(json).map_err(|e| format!("Error parsing spec file: {}", e))?;
|
||||||
@@ -126,7 +131,8 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
|
|||||||
id: &str,
|
id: &str,
|
||||||
constructor: fn() -> G,
|
constructor: fn() -> G,
|
||||||
boot_nodes: Vec<String>,
|
boot_nodes: Vec<String>,
|
||||||
telemetry_url: Option<&str>
|
telemetry_url: Option<&str>,
|
||||||
|
protocol_id: Option<&str>,
|
||||||
) -> Self
|
) -> Self
|
||||||
{
|
{
|
||||||
let spec = ChainSpecFile {
|
let spec = ChainSpecFile {
|
||||||
@@ -134,6 +140,7 @@ impl<G: RuntimeGenesis> ChainSpec<G> {
|
|||||||
id: id.to_owned(),
|
id: id.to_owned(),
|
||||||
boot_nodes: boot_nodes,
|
boot_nodes: boot_nodes,
|
||||||
telemetry_url: telemetry_url.map(str::to_owned),
|
telemetry_url: telemetry_url.map(str::to_owned),
|
||||||
|
protocol_id: protocol_id.map(str::to_owned),
|
||||||
};
|
};
|
||||||
ChainSpec {
|
ChainSpec {
|
||||||
spec,
|
spec,
|
||||||
|
|||||||
@@ -131,9 +131,6 @@ pub trait ServiceFactory: 'static {
|
|||||||
/// Other configuration for service members.
|
/// Other configuration for service members.
|
||||||
type Configuration: Default;
|
type Configuration: Default;
|
||||||
|
|
||||||
/// Network protocol id.
|
|
||||||
const NETWORK_PROTOCOL_ID: network::ProtocolId;
|
|
||||||
|
|
||||||
//TODO: replace these with a constructor trait. that TransactionPool implements.
|
//TODO: replace these with a constructor trait. that TransactionPool implements.
|
||||||
/// Extrinsic pool constructor for the full client.
|
/// Extrinsic pool constructor for the full client.
|
||||||
fn build_full_transaction_pool(config: TransactionPoolOptions, client: Arc<FullClient<Self>>)
|
fn build_full_transaction_pool(config: TransactionPoolOptions, client: Arc<FullClient<Self>>)
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ pub use components::{ServiceFactory, FullBackend, FullExecutor, LightBackend,
|
|||||||
ComponentExHash, ComponentExtrinsic,
|
ComponentExHash, ComponentExtrinsic,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEFAULT_PROTOCOL_ID: &'static str = "sup";
|
||||||
|
|
||||||
/// Substrate service.
|
/// Substrate service.
|
||||||
pub struct Service<Components: components::Components> {
|
pub struct Service<Components: components::Components> {
|
||||||
client: Arc<ComponentClient<Components>>,
|
client: Arc<ComponentClient<Components>>,
|
||||||
@@ -171,7 +173,15 @@ impl<Components> Service<Components>
|
|||||||
specialization: network_protocol,
|
specialization: network_protocol,
|
||||||
};
|
};
|
||||||
|
|
||||||
let network = network::Service::new(network_params, Components::Factory::NETWORK_PROTOCOL_ID)?;
|
let mut protocol_id = network::ProtocolId::default();
|
||||||
|
let protocol_id_full = config.chain_spec.protocol_id().unwrap_or(DEFAULT_PROTOCOL_ID).as_bytes();
|
||||||
|
if protocol_id_full.len() > protocol_id.len() {
|
||||||
|
warn!("Protocol ID truncated to {} chars", protocol_id.len());
|
||||||
|
}
|
||||||
|
let id_len = protocol_id_full.len().min(protocol_id.len());
|
||||||
|
&mut protocol_id[0..id_len].copy_from_slice(&protocol_id_full[0..id_len]);
|
||||||
|
|
||||||
|
let network = network::Service::new(network_params, protocol_id)?;
|
||||||
on_demand.map(|on_demand| on_demand.set_service_link(Arc::downgrade(&network)));
|
on_demand.map(|on_demand| on_demand.set_service_link(Arc::downgrade(&network)));
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,9 +43,6 @@ use substrate_network::{message, generic_message};
|
|||||||
use substrate_network::specialization::Specialization;
|
use substrate_network::specialization::Specialization;
|
||||||
use substrate_network::StatusMessage as GenericFullStatus;
|
use substrate_network::StatusMessage as GenericFullStatus;
|
||||||
|
|
||||||
/// Demo protocol id.
|
|
||||||
pub const PROTOCOL_ID: ::substrate_network::ProtocolId = *b"dot";
|
|
||||||
|
|
||||||
type FullStatus = GenericFullStatus<Block>;
|
type FullStatus = GenericFullStatus<Block>;
|
||||||
|
|
||||||
/// Specialization of the network service for the node protocol.
|
/// Specialization of the network service for the node protocol.
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ pub fn staging_testnet_config() -> ChainSpec<GenesisConfig> {
|
|||||||
staging_testnet_config_genesis,
|
staging_testnet_config_genesis,
|
||||||
boot_nodes,
|
boot_nodes,
|
||||||
Some(STAGING_TELEMETRY_URL.into()),
|
Some(STAGING_TELEMETRY_URL.into()),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +215,7 @@ fn development_config_genesis() -> GenesisConfig {
|
|||||||
|
|
||||||
/// Development config (single validator Alice)
|
/// Development config (single validator Alice)
|
||||||
pub fn development_config() -> ChainSpec<GenesisConfig> {
|
pub fn development_config() -> ChainSpec<GenesisConfig> {
|
||||||
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![], None)
|
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![], None, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_testnet_genesis() -> GenesisConfig {
|
fn local_testnet_genesis() -> GenesisConfig {
|
||||||
@@ -226,5 +227,5 @@ fn local_testnet_genesis() -> GenesisConfig {
|
|||||||
|
|
||||||
/// Local testnet config (multivalidator Alice + Bob)
|
/// Local testnet config (multivalidator Alice + Bob)
|
||||||
pub fn local_testnet_config() -> ChainSpec<GenesisConfig> {
|
pub fn local_testnet_config() -> ChainSpec<GenesisConfig> {
|
||||||
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None)
|
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, None)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,8 +102,6 @@ impl service::ServiceFactory for Factory {
|
|||||||
type Genesis = GenesisConfig;
|
type Genesis = GenesisConfig;
|
||||||
type Configuration = CustomConfiguration;
|
type Configuration = CustomConfiguration;
|
||||||
|
|
||||||
const NETWORK_PROTOCOL_ID: network::ProtocolId = ::node_network::PROTOCOL_ID;
|
|
||||||
|
|
||||||
fn build_full_transaction_pool(config: TransactionPoolOptions, client: Arc<service::FullClient<Self>>)
|
fn build_full_transaction_pool(config: TransactionPoolOptions, client: Arc<service::FullClient<Self>>)
|
||||||
-> Result<TransactionPool<service::FullClient<Self>>, Error>
|
-> Result<TransactionPool<service::FullClient<Self>>, Error>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user