Quellcode durchsuchen

chainspec builder can specify chain type argument

Mokhtar Naamani vor 4 Jahren
Ursprung
Commit
8659f3dfa8

+ 36 - 0
Cargo.lock

@@ -565,6 +565,7 @@ name = "chain-spec-builder"
 version = "3.0.0"
 dependencies = [
  "ansi_term 0.12.1",
+ "enum-utils",
  "joystream-node",
  "rand 0.7.3",
  "sc-chain-spec",
@@ -927,6 +928,30 @@ dependencies = [
  "syn 0.11.11",
 ]
 
+[[package]]
+name = "enum-utils"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed327f716d0d351d86c9fd3398d20ee39ad8f681873cc081da2ca1c10fed398a"
+dependencies = [
+ "enum-utils-from-str",
+ "failure",
+ "proc-macro2",
+ "quote 1.0.7",
+ "serde_derive_internals",
+ "syn 1.0.17",
+]
+
+[[package]]
+name = "enum-utils-from-str"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d49be08bad6e4ca87b2b8e74146987d4e5cb3b7512efa50ef505b51a22227ee1"
+dependencies = [
+ "proc-macro2",
+ "quote 1.0.7",
+]
+
 [[package]]
 name = "env_logger"
 version = "0.7.1"
@@ -5823,6 +5848,17 @@ dependencies = [
  "syn 1.0.17",
 ]
 
+[[package]]
+name = "serde_derive_internals"
+version = "0.25.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6"
+dependencies = [
+ "proc-macro2",
+ "quote 1.0.7",
+ "syn 1.0.17",
+]
+
 [[package]]
 name = "serde_json"
 version = "1.0.57"

+ 2 - 2
node/src/chain_spec/proposals_config.rs

@@ -8,10 +8,10 @@ pub fn development() -> ProposalsConfigParameters {
 
 /// Staging chain config. Shorter grace periods and voting periods than default.
 pub fn staging() -> ProposalsConfigParameters {
-    ProposalsConfigParameters::with_grace_and_voting_periods(200, 600)
+    ProposalsConfigParameters::with_grace_and_voting_periods(20, 30)
 }
 
 /// The default configuration as defined in the runtime module
-pub fn default() -> ProposalsConfigParameters {
+pub fn production() -> ProposalsConfigParameters {
     ProposalsConfigParameters::default()
 }

+ 1 - 0
utils/chain-spec-builder/Cargo.toml

@@ -15,3 +15,4 @@ sc-chain-spec = { git = 'https://github.com/paritytech/substrate.git', rev = '00
 sp-core = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
 joystream-node = { path = "../../node" }
 
+enum-utils = "0.1.2"

+ 50 - 2
utils/chain-spec-builder/src/main.rs

@@ -39,6 +39,26 @@ use sp_core::{
 
 const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
 
+#[allow(non_camel_case_types)]
+#[derive(Debug, Clone, PartialEq, enum_utils::FromStr)]
+enum ChainDeployment {
+    dev,
+    local,
+    staging,
+    live,
+}
+
+impl Into<ChainType> for ChainDeployment {
+    fn into(self) -> ChainType {
+        match self {
+            ChainDeployment::dev => ChainType::Development,
+            ChainDeployment::local => ChainType::Local,
+            ChainDeployment::staging => ChainType::Live,
+            ChainDeployment::live => ChainType::Live,
+        }
+    }
+}
+
 /// A utility to easily create a testnet chain spec definition with a given set
 /// of authorities and endowed accounts and/or generate random accounts.
 #[derive(StructOpt)]
@@ -68,6 +88,9 @@ enum ChainSpecBuilder {
         /// The path to an initial content directory data file
         #[structopt(long, short)]
         initial_content_path: Option<PathBuf>,
+        /// Deployment type: dev, local, staging, live
+        #[structopt(long, short, default_value = "live")]
+        deployment: String,
     },
     /// Create a new chain spec with the given number of authorities and endowed
     /// accounts. Random keys will be generated as required.
@@ -97,6 +120,9 @@ enum ChainSpecBuilder {
         /// The path to an initial content directory data file
         #[structopt(long, short)]
         initial_content_path: Option<PathBuf>,
+        /// Deployment type: dev, local, staging, live
+        #[structopt(long, short, default_value = "live")]
+        deployment: String,
     },
 }
 
@@ -152,9 +178,21 @@ impl ChainSpecBuilder {
             } => initial_content_path,
         }
     }
+
+    fn chain_deployment(&self) -> ChainDeployment {
+        match self {
+            ChainSpecBuilder::New { deployment, .. } => deployment
+                .parse()
+                .expect("Failed to parse deployment argument"),
+            ChainSpecBuilder::Generate { deployment, .. } => deployment
+                .parse()
+                .expect("Failed to parse deployment argument"),
+        }
+    }
 }
 
 fn genesis_constructor(
+    deployment: &ChainDeployment,
     authority_seeds: &[String],
     endowed_accounts: &[AccountId],
     sudo_account: &AccountId,
@@ -203,11 +241,17 @@ fn genesis_constructor(
         )
     };
 
+    let proposals_cfg = match deployment {
+        ChainDeployment::live => proposals_config::production(),
+        ChainDeployment::staging => proposals_config::staging(),
+        _ => proposals_config::development(),
+    };
+
     chain_spec::testnet_genesis(
         authorities,
         sudo_account.clone(),
         endowed_accounts.to_vec(),
-        proposals_config::default(),
+        proposals_cfg,
         members,
         forum_cfg,
         versioned_store_cfg,
@@ -218,6 +262,7 @@ fn genesis_constructor(
 }
 
 fn generate_chain_spec(
+    deployment: ChainDeployment,
     authority_seeds: Vec<String>,
     endowed_accounts: Vec<String>,
     sudo_account: String,
@@ -247,9 +292,10 @@ fn generate_chain_spec(
     let chain_spec = chain_spec::ChainSpec::from_genesis(
         "Joystream Testnet",
         "joy_testnet",
-        ChainType::Development,
+        deployment.clone().into(),
         move || {
             genesis_constructor(
+                &deployment,
                 &authority_seeds,
                 &endowed_accounts,
                 &sudo_account,
@@ -330,6 +376,7 @@ fn main() -> Result<(), String> {
     let initial_members_path = builder.initial_members_path().clone();
     let initial_forum_path = builder.initial_forum_path().clone();
     let initial_content_path = builder.initial_content_path().clone();
+    let deployment = builder.chain_deployment();
 
     let (authority_seeds, endowed_accounts, sudo_account) = match builder {
         ChainSpecBuilder::Generate {
@@ -373,6 +420,7 @@ fn main() -> Result<(), String> {
     };
 
     let json = generate_chain_spec(
+        deployment,
         authority_seeds,
         endowed_accounts,
         sudo_account,