Skip to content
Snippets Groups Projects
Commit 4d34e6c2 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

fix(#132): feat: use `gdev_client-specs.json` for raw specs

parent 91d3c092
No related branches found
No related tags found
1 merge request!182Resolve "Industrialize Releases production"
Pipeline #34146 waiting for manual action
{
"name": "ĞDev",
"id": "gdev",
"chainType": "Live",
"bootNodes": [],
"telemetryEndpoints": [
[
"/dns/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F",
0
]
],
"properties": {
"tokenDecimals": 2,
"tokenSymbol": "ĞD"
}
}
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -27,7 +27,11 @@ use gdev_runtime::{ ...@@ -27,7 +27,11 @@ use gdev_runtime::{
SessionConfig, SmithCertConfig, SmithMembershipConfig, SudoConfig, SystemConfig, SessionConfig, SmithCertConfig, SmithMembershipConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, UniversalDividendConfig, WASM_BINARY, TechnicalCommitteeConfig, UniversalDividendConfig, WASM_BINARY,
}; };
use jsonrpsee::core::JsonValue;
use sc_network::config::MultiaddrWithPeerId;
use sc_service::ChainType; use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use serde::Deserialize;
use sp_core::sr25519; use sp_core::sr25519;
use sp_runtime::Perbill; use sp_runtime::Perbill;
use std::{env, fs}; use std::{env, fs};
...@@ -123,15 +127,36 @@ pub fn gdev_development_chain_spec(json_file_path: String) -> Result<ChainSpec, ...@@ -123,15 +127,36 @@ pub fn gdev_development_chain_spec(json_file_path: String) -> Result<ChainSpec,
)) ))
} }
// === client specifications ===
/// emulate client specifications to get them from json
#[derive(Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct ClientSpec {
name: String,
id: String,
chain_type: ChainType,
boot_nodes: Vec<MultiaddrWithPeerId>,
telemetry_endpoints: Option<TelemetryEndpoints>,
// protocol_id: Option<String>,
// #[serde(default = "Default::default", skip_serializing_if = "Option::is_none")]
// fork_id: Option<String>,
properties: Option<serde_json::Map<std::string::String, JsonValue>>,
// #[serde(default)]
// code_substitutes: BTreeMap<String, Bytes>,
}
/// generate live network chainspecs /// generate live network chainspecs
pub fn gen_live_conf(json_file_path: String) -> Result<ChainSpec, String> { pub fn gen_live_conf(client_spec: ClientSpec, json_file_path: String) -> Result<ChainSpec, String> {
let wasm_binary = get_wasm_binary().ok_or_else(|| "wasm not available".to_string())?; let wasm_binary = get_wasm_binary().ok_or_else(|| "wasm not available".to_string())?;
Ok(ChainSpec::from_genesis( Ok(ChainSpec::from_genesis(
// Name // Name
"Ğdev", client_spec.name.as_str(),
// ID // ID
"gdev", client_spec.id.as_str(),
sc_service::ChainType::Live, // chain type
client_spec.chain_type,
move || { move || {
let genesis_data = let genesis_data =
gen_genesis_data::generate_genesis_data::<_, _, SessionKeys, GDevSKP>( gen_genesis_data::generate_genesis_data::<_, _, SessionKeys, GDevSKP>(
...@@ -143,29 +168,15 @@ pub fn gen_live_conf(json_file_path: String) -> Result<ChainSpec, String> { ...@@ -143,29 +168,15 @@ pub fn gen_live_conf(json_file_path: String) -> Result<ChainSpec, String> {
genesis_data_to_gdev_genesis_conf(genesis_data, wasm_binary.to_vec()) genesis_data_to_gdev_genesis_conf(genesis_data, wasm_binary.to_vec())
}, },
// Bootnodes // Bootnodes
vec![], client_spec.boot_nodes,
// Telemetry // Telemetry (by default, enable telemetry, can be disabled with argument)
Some( client_spec.telemetry_endpoints,
sc_service::config::TelemetryEndpoints::new(vec![(
"wss://telemetry.polkadot.io/submit/".to_owned(),
0,
)])
.expect("invalid telemetry endpoints"),
),
// Protocol ID // Protocol ID
Some("gdev2"), Some("gdev2"),
//Fork ID //Fork ID
None, None,
// Properties // Properties
Some( client_spec.properties,
serde_json::json!({
"tokenDecimals": TOKEN_DECIMALS,
"tokenSymbol": TOKEN_SYMBOL,
})
.as_object()
.expect("must be a map")
.clone(),
),
// Extensions // Extensions
None, None,
)) ))
......
...@@ -105,9 +105,22 @@ impl SubstrateCli for Cli { ...@@ -105,9 +105,22 @@ impl SubstrateCli for Cli {
// but must have a smith with declared session keys // but must have a smith with declared session keys
// > optionally from DUNITER_GENESIS_CONFIG file to override default gdev configuration // > optionally from DUNITER_GENESIS_CONFIG file to override default gdev configuration
#[cfg(feature = "gdev")] #[cfg(feature = "gdev")]
"gdev_live" => Box::new(chain_spec::gdev::gen_live_conf( "gdev_live" => {
const JSON_CLIENT_SPEC: &str = "./node/specs/gdev_client-specs.json";
let client_spec: chain_spec::gdev::ClientSpec = serde_json::from_slice(
&std::fs::read(
std::env::var("DUNITER_GTEST_CLIENT_SPEC")
.unwrap_or_else(|_| JSON_CLIENT_SPEC.to_string()),
)
.map_err(|e| format!("failed to read {JSON_CLIENT_SPEC} {e}"))?[..],
)
.map_err(|e| format!("failed to parse {e}"))?;
// rebuild chainspecs from these files
Box::new(chain_spec::gdev::gen_live_conf(
client_spec,
"resources/gdev.json".to_string(), "resources/gdev.json".to_string(),
)?), )?)
}
// hardcoded previously generated raw chainspecs // hardcoded previously generated raw chainspecs
// yields a pointlessly heavy binary because of hexadecimal-text-encoded values // yields a pointlessly heavy binary because of hexadecimal-text-encoded values
#[cfg(all(feature = "gdev", feature = "embed"))] #[cfg(all(feature = "gdev", feature = "embed"))]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment