Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
addressing low hanging review comments + minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Feb 9, 2024
1 parent fd90010 commit 07d38ae
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 131 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions pulsar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use subspace_sdk::node::{DomainConfigBuilder, DsnBuilder, NetworkBuilder, Node,
use subspace_sdk::{chain_spec, ByteSize, FarmDescription, PublicKey};
use tracing::instrument;

use crate::utils::{provider_storage_dir_getter, IntoEyre};
use crate::utils::IntoEyre;

/// defaults for the user config file
pub(crate) const DEFAULT_FARM_SIZE: ByteSize = ByteSize::gb(2);
Expand Down Expand Up @@ -52,10 +52,7 @@ impl NodeConfig {
ChainConfig::Gemini3h => {
let mut node = Node::gemini_3h()
.network(NetworkBuilder::gemini_3h().name(name))
.dsn(
DsnBuilder::gemini_3h()
.provider_storage_path(provider_storage_dir_getter()),
)
.dsn(DsnBuilder::gemini_3h())
.sync_from_dsn(true)
.enable_subspace_block_relay(true);
if enable_domains {
Expand All @@ -77,7 +74,7 @@ impl NodeConfig {
ChainConfig::DevNet => {
let mut node = Node::devnet()
.network(NetworkBuilder::devnet().name(name))
.dsn(DsnBuilder::devnet().provider_storage_path(provider_storage_dir_getter()))
.dsn(DsnBuilder::devnet())
.sync_from_dsn(true)
.enable_subspace_block_relay(true);
if enable_domains {
Expand Down
4 changes: 0 additions & 4 deletions pulsar/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ pub(crate) fn node_directory_getter() -> PathBuf {
data_dir_getter().join("node")
}

pub(crate) fn provider_storage_dir_getter() -> PathBuf {
node_directory_getter().join("provider-storage")
}

fn data_dir_getter() -> PathBuf {
dirs::data_dir().expect("data folder must be present in every major OS").join("pulsar")
}
Expand Down
11 changes: 0 additions & 11 deletions sdk/dsn/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ pub struct PendingOutConnections(#[derivative(Default(value = "150"))] pub u32);
#[builder(pattern = "immutable", build_fn(private, name = "_build"), name = "DsnBuilder")]
#[non_exhaustive]
pub struct Dsn {
/// Listen on some address for other nodes
#[builder(default, setter(into, strip_option))]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub provider_storage_path: Option<std::path::PathBuf>,
/// Listen on some address for other nodes
#[builder(default, setter(into))]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
Expand Down Expand Up @@ -125,11 +121,6 @@ pub struct Dsn {
#[builder(setter(into), default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub pending_out_connections: PendingOutConnections,
/// Defines target total (in and out) connection number for DSN that
/// should be maintained.
#[builder(setter(into), default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub target_connections: TargetConnections,
}

sdk_utils::generate_builder!(Dsn);
Expand Down Expand Up @@ -237,14 +228,12 @@ impl Dsn {
listen_addresses,
reserved_nodes,
allow_non_global_addresses_in_dht,
provider_storage_path: _,
in_connections: InConnections(max_established_incoming_connections),
out_connections: OutConnections(max_established_outgoing_connections),
pending_in_connections: PendingInConnections(max_pending_incoming_connections),
pending_out_connections: PendingOutConnections(max_pending_outgoing_connections),
boot_nodes,
external_addresses,
..
} = self;

let bootstrap_nodes = boot_nodes.into_iter().map(Into::into).collect::<Vec<_>>();
Expand Down
30 changes: 17 additions & 13 deletions sdk/farmer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use subspace_farmer::utils::{
all_cpu_cores, create_plotting_thread_pool_manager, thread_pool_core_indices,
};
use subspace_farmer::{Identity, KNOWN_PEERS_CACHE_SIZE};
use subspace_farmer_components::plotting::PlottedSector;
use subspace_farmer_components::sector::{sector_size, SectorMetadataChecksummed};
use subspace_networking::libp2p::kad::RecordKey;
use subspace_networking::utils::multihash::ToMultihash;
Expand Down Expand Up @@ -343,20 +344,12 @@ async fn create_readers_and_pieces(
Ok(readers_and_pieces)
}

fn handler_on_sector_update(
sector_update: &SectorUpdate,
fn handler_on_sector_plotted(
plotted_sector: &PlottedSector,
maybe_old_plotted_sector: &Option<PlottedSector>,
disk_farm_index: usize,
readers_and_pieces: Arc<parking_lot::Mutex<Option<ReadersAndPieces>>>,
) {
let (plotted_sector, maybe_old_plotted_sector) = match sector_update {
SectorUpdate::Plotting(SectorPlottingDetails::Finished {
plotted_sector,
old_plotted_sector,
..
}) => (plotted_sector, old_plotted_sector),
_ => return,
};

let disk_farm_index = disk_farm_index
.try_into()
.expect("More than 256 farms are not supported, this is checked above already; qed");
Expand Down Expand Up @@ -632,8 +625,19 @@ impl Config {
sector_plotting_handler_ids.push(single_disk_farm.on_sector_update(Arc::new(
move |(_plotted_sector, sector_update)| {
let _span_guard = span.enter();
handler_on_sector_update(
sector_update,

let (plotted_sector, maybe_old_plotted_sector) = match sector_update {
SectorUpdate::Plotting(SectorPlottingDetails::Finished {
plotted_sector,
old_plotted_sector,
..
}) => (plotted_sector, old_plotted_sector),
_ => return,
};

handler_on_sector_plotted(
plotted_sector,
maybe_old_plotted_sector,
disk_farm_index,
readers_and_pieces.clone(),
)
Expand Down
12 changes: 4 additions & 8 deletions sdk/node/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use derive_more::{Deref, DerefMut, Display, From};
use sc_service::BlocksPruning;
use sdk_dsn::{Dsn, DsnBuilder};
use sdk_substrate::{
Base, BaseBuilder, NetworkBuilder, OffchainWorkerBuilder, PruningMode, Role, RpcBuilder,
StorageMonitor,
Base, BaseBuilder, NetworkBuilder, PruningMode, Role, RpcBuilder, StorageMonitor,
};
use sdk_utils::ByteSize;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -90,7 +89,7 @@ pub struct Config<F: Farmer> {
/// Proof of time entropy
#[builder(setter(into), default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub pot_external_entropy: Option<Vec<u8>>,
pub pot_external_entropy: Option<String>,
}

impl<F: Farmer + 'static> Config<F> {
Expand Down Expand Up @@ -119,7 +118,6 @@ impl<F: Farmer + 'static> Builder<F> {
.network(NetworkBuilder::dev())
.dsn(DsnBuilder::dev())
.rpc(RpcBuilder::dev())
.offchain_worker(OffchainWorkerBuilder::dev())
}

/// Gemini 3g configuration
Expand All @@ -128,9 +126,8 @@ impl<F: Farmer + 'static> Builder<F> {
.network(NetworkBuilder::gemini_3h())
.dsn(DsnBuilder::gemini_3h())
.rpc(RpcBuilder::gemini_3h())
.offchain_worker(OffchainWorkerBuilder::gemini_3h())
.role(Role::Authority)
.state_pruning(PruningMode::ArchiveAll)
.state_pruning(PruningMode::ArchiveCanonical)
.blocks_pruning(BlocksPruning::Some(256))
}

Expand All @@ -140,9 +137,8 @@ impl<F: Farmer + 'static> Builder<F> {
.network(NetworkBuilder::devnet())
.dsn(DsnBuilder::devnet())
.rpc(RpcBuilder::devnet())
.offchain_worker(OffchainWorkerBuilder::devnet())
.role(Role::Authority)
.state_pruning(PruningMode::ArchiveAll)
.state_pruning(PruningMode::ArchiveCanonical)
.blocks_pruning(BlocksPruning::Some(256))
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/node/src/domains/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl DomainConfigBuilder {

/// Dev chain configuration
pub fn dev() -> Self {
Self::new().chain_id("dev").domain_id(DomainId::new(0)).dev_key_seed("//Alice")
Self::new().chain_id("dev").domain_id(DomainId::new(0))
}

/// Gemini 3g configuration
Expand Down
24 changes: 14 additions & 10 deletions sdk/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use sc_utils::mpsc::tracing_unbounded;
use sdk_dsn::{DsnOptions, DsnShared};
use sdk_traits::Farmer;
use sdk_utils::{DestructorSet, MultiaddrWithPeerId, PublicKey, TaskOutput};
use serde_json::Value;
use sp_consensus::SyncOracle;
use sp_consensus_subspace::digests::PreDigest;
use sp_core::traits::SpawnEssentialNamed;
Expand Down Expand Up @@ -70,28 +71,31 @@ const SEGMENT_HEADERS_NUMBER_LIMIT: u64 = MAX_SEGMENT_HEADERS_PER_REQUEST as u64

fn pot_external_entropy(
consensus_chain_config: &Configuration,
config_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),
Value::Null => Ok(String::new()),
_ => Err(sc_service::Error::Other("Failed to decode PoT initial key".to_string())),
})
.transpose()?;
if maybe_chain_spec_pot_external_entropy.is_some()
&& config_pot_external_entropy.is_some()
&& maybe_chain_spec_pot_external_entropy != config_pot_external_entropy
&& maybe_pot_external_entropy.is_some()
&& maybe_chain_spec_pot_external_entropy != maybe_pot_external_entropy
{
tracing::warn!(
"--pot-external-entropy CLI argument was ignored due to chain spec having a different \
explicit value"
);
}
Ok(maybe_chain_spec_pot_external_entropy.or(config_pot_external_entropy).unwrap_or_default())
Ok(maybe_chain_spec_pot_external_entropy
.or(maybe_pot_external_entropy)
.unwrap_or_default()
.into_bytes())
}

impl<F: Farmer + 'static> Config<F> {
Expand Down
9 changes: 3 additions & 6 deletions sdk/subspace-sdk/examples/mini-farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@ async fn main() -> anyhow::Result<()> {
let node_dir = base_path.join("node");
let node = match chain {
Chain::Gemini3h => Node::gemini_3h().dsn(
subspace_sdk::node::DsnBuilder::gemini_3h()
.provider_storage_path(node_dir.join("provider_storage")),
subspace_sdk::node::DsnBuilder::gemini_3h(),
),
Chain::Devnet => Node::devnet().dsn(
subspace_sdk::node::DsnBuilder::devnet()
.provider_storage_path(node_dir.join("provider_storage")),
subspace_sdk::node::DsnBuilder::devnet(),
),
Chain::Dev => Node::dev().dsn(
subspace_sdk::node::DsnBuilder::dev()
.provider_storage_path(node_dir.join("provider_storage")),
subspace_sdk::node::DsnBuilder::dev(),
),
}
.role(node::Role::Authority);
Expand Down
1 change: 0 additions & 1 deletion sdk/substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ sc-state-db = { version = "0.10.0-dev", git = "https://github.com/subspace/polka
sc-storage-monitor = { version = "0.1.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", default-features = false }
sdk-utils = { path = "../utils" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "e8ed377ecee4e1992ffb731d67cd04bf444e6382" }
Loading

0 comments on commit 07d38ae

Please sign in to comment.