Skip to content

Commit

Permalink
Merge pull request #2491 from subspace/gemini-3h-pot-seed
Browse files Browse the repository at this point in the history
Add Gemini 3h PoT seed to chain spec
  • Loading branch information
nazar-pc committed Jan 31, 2024
2 parents c14a319 + 2c6fe4e commit 56cf1fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"/dns/bootstrap-0.gemini-3h.subspace.network/tcp/30533/p2p/12D3KooWK7NuL4S6aEdy5gELnvhCGo6EyrWVARnBy7W4AJTVkaF1",
"/dns/bootstrap-1.gemini-3h.subspace.network/tcp/30533/p2p/12D3KooWQK33n2raSXzjH8JyqbFtczBmbwZiK9Tpicdw3rveJesj"
],
"potExternalEntropy": null,
"potExternalEntropy": "000000000000000000037bbc7fae1cd2c91dba8312b65f71352630e938cc4dda",
"ss58Format": 2254,
"tokenDecimals": 18,
"tokenSymbol": "tSSC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use sc_consensus_slots::SlotProportion;
use sc_network::config::MultiaddrWithPeerId;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_utils::mpsc::tracing_unbounded;
use serde_json::Value;
use sp_core::crypto::Ss58AddressFormat;
use sp_core::traits::SpawnEssentialNamed;
use sp_domains::DomainId;
Expand Down Expand Up @@ -133,12 +134,13 @@ fn main() -> Result<(), Error> {
.chain_spec
.properties()
.get("potExternalEntropy")
.map(|d| serde_json::from_value(d.clone()))
.transpose()
.map_err(|error| {
sc_service::Error::Other(format!("Failed to decode PoT initial key: {error:?}"))
})?
.flatten()
.map(|d| match d.clone() {
Value::String(s) => Ok(s.into_bytes()),
_ => Err(sc_service::Error::Other(
"Failed to decode PoT initial key".to_string(),
)),
})
.transpose()?
.unwrap_or_default();

let dsn_config = {
Expand Down
8 changes: 2 additions & 6 deletions crates/subspace-node/src/commands/run/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ use subspace_service::dsn::DsnConfig;
use tempfile::TempDir;
use tracing::warn;

fn parse_pot_external_entropy(s: &str) -> Result<Vec<u8>, hex::FromHexError> {
hex::decode(s)
}

fn parse_timekeeper_cpu_cores(
s: &str,
) -> Result<HashSet<usize>, Box<dyn std::error::Error + Send + Sync>> {
Expand Down Expand Up @@ -276,8 +272,8 @@ pub(super) struct ConsensusChainOptions {
force_authoring: bool,

/// External entropy, used initially when PoT chain starts to derive the first seed
#[arg(long, value_parser = parse_pot_external_entropy)]
pot_external_entropy: Option<Vec<u8>>,
#[arg(long)]
pot_external_entropy: Option<String>,

/// Options for DSN
#[clap(flatten)]
Expand Down
19 changes: 11 additions & 8 deletions crates/subspace-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use frame_benchmarking_cli::BenchmarkCmd;
use futures::future::TryFutureExt;
use sc_cli::{ChainSpec, SubstrateCli};
use sc_service::{Configuration, PartialComponents};
use serde_json::Value;
use sp_core::crypto::Ss58AddressFormat;
use subspace_proof_of_space::chia::ChiaTable;
use subspace_runtime::{Block, RuntimeApi};
Expand Down Expand Up @@ -95,18 +96,19 @@ where

fn derive_pot_external_entropy(
consensus_chain_config: &Configuration,
maybe_pot_external_entropy: Option<Vec<u8>>,
maybe_pot_external_entropy: Option<String>,
) -> Result<Vec<u8>, sc_service::Error> {
let maybe_chain_spec_pot_external_entropy = consensus_chain_config
.chain_spec
.properties()
.get("potExternalEntropy")
.map(|d| serde_json::from_value(d.clone()))
.transpose()
.map_err(|error| {
sc_service::Error::Other(format!("Failed to decode PoT initial key: {error:?}"))
})?
.flatten();
.map(|d| match d.clone() {
Value::String(s) => Ok(s),
_ => Err(sc_service::Error::Other(
"Failed to decode PoT initial key".to_string(),
)),
})
.transpose()?;
if maybe_chain_spec_pot_external_entropy.is_some()
&& maybe_pot_external_entropy.is_some()
&& maybe_chain_spec_pot_external_entropy != maybe_pot_external_entropy
Expand All @@ -118,7 +120,8 @@ fn derive_pot_external_entropy(
}
Ok(maybe_chain_spec_pot_external_entropy
.or(maybe_pot_external_entropy)
.unwrap_or_default())
.unwrap_or_default()
.into_bytes())
}

fn main() -> Result<(), Error> {
Expand Down

0 comments on commit 56cf1fb

Please sign in to comment.