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

Commit

Permalink
Merge pull request #249 from subspace/gemini-3f-hotfix
Browse files Browse the repository at this point in the history
update pulsar to gemini-3f-2023-aug-21 snapshot
  • Loading branch information
nazar-pc authored Aug 22, 2023
2 parents db417c7 + 4d11d0f commit 91b4df0
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 118 deletions.
143 changes: 82 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pulsar"
version = "0.6.0"
version = "0.6.1"
edition = "2021"

[dependencies]
Expand Down Expand Up @@ -29,7 +29,7 @@ single-instance = "0.3.3"
sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71", features = ["full_crypto"] }
strum = "0.24.1"
strum_macros = "0.24.3"
subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "cfe095af6bd314e346a26acf08c32ecd21b40964" }
subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "d1860a233643d9e99fdf6bbee6ae39516890e4d3" }
thiserror = "1"
tokio = { version = "1.27", features = ["macros", "rt-multi-thread", "tracing"] }
toml = "0.7"
Expand Down
16 changes: 8 additions & 8 deletions src/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) async fn farm(is_verbose: bool, enable_domains: bool, no_rotation: bo
let node = Arc::new(
node_config
.clone()
.build(chain.clone(), is_verbose, farmer_config.plot_size)
.build(chain.clone(), is_verbose, farmer_config.farm_size)
.await
.context("error building the node")?,
);
Expand All @@ -78,7 +78,7 @@ pub(crate) async fn farm(is_verbose: bool, enable_domains: bool, no_rotation: bo
}
}

let summary_file = SummaryFile::new(Some(farmer_config.plot_size))
let summary_file = SummaryFile::new(Some(farmer_config.farm_size))
.await
.context("constructing new SummaryFile failed")?;

Expand Down Expand Up @@ -221,15 +221,15 @@ async fn subscribe_to_plotting_progress(
is_initial_progress_finished: Arc<AtomicBool>,
sector_size_bytes: u64,
) -> Result<()> {
for (plot_id, plot) in farmer.iter_plots().await.enumerate() {
println!("Initial plotting for plot: #{plot_id} ({})", plot.directory().display());
for (farm_id, farm) in farmer.iter_farms().await.enumerate() {
println!("Initial plotting for farm: #{farm_id} ({})", farm.directory().display());

let mut plotting_progress = plot.subscribe_initial_plotting_progress().await;
let mut plotting_progress = farm.subscribe_initial_plotting_progress().await;
let progress_bar;

if let Some(plotting_result) = plotting_progress.next().await {
let current_size = plotting_result.current_sector * sector_size_bytes;
progress_bar = plotting_progress_bar(current_size, plot.allocated_space().as_u64());
progress_bar = plotting_progress_bar(current_size, farm.allocated_space().as_u64());

while let Some(stream_result) = plotting_progress.next().await {
let current_size = stream_result.current_sector * sector_size_bytes;
Expand All @@ -238,8 +238,8 @@ async fn subscribe_to_plotting_progress(
} else {
// means initial plotting was already finished
progress_bar = plotting_progress_bar(
plot.allocated_space().as_u64(),
plot.allocated_space().as_u64(),
farm.allocated_space().as_u64(),
farm.allocated_space().as_u64(),
);
}
progress_bar.set_style(
Expand Down
30 changes: 15 additions & 15 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use zeroize::Zeroizing;

use crate::config::{
create_config, AdvancedFarmerSettings, AdvancedNodeSettings, ChainConfig, Config, FarmerConfig,
NodeConfig, DEFAULT_PLOT_SIZE,
NodeConfig, DEFAULT_FARM_SIZE,
};
use crate::utils::{
directory_parser, get_user_input, node_directory_getter, node_name_parser,
plot_directory_getter, print_ascii_art, print_run_executable_command, print_version,
directory_parser, farm_directory_getter, get_user_input, node_directory_getter,
node_name_parser, print_ascii_art, print_run_executable_command, print_version,
reward_address_parser, size_parser, yes_or_no_parser,
};

Expand Down Expand Up @@ -67,14 +67,14 @@ fn get_config_from_user_inputs() -> Result<Config> {
node_name_parser,
)?;

// get plot directory
let default_plot_loc = plot_directory_getter();
let plot_directory = get_user_input(
// get farm directory
let default_farm_loc = farm_directory_getter();
let farm_directory = get_user_input(
&format!(
"Specify a path for storing plot files (press enter to use the default: \
`{default_plot_loc:?}`): ",
"Specify a path for storing farm files (press enter to use the default: \
`{default_farm_loc:?}`): ",
),
Some(default_plot_loc),
Some(default_farm_loc),
directory_parser,
)?;

Expand All @@ -88,13 +88,13 @@ fn get_config_from_user_inputs() -> Result<Config> {
directory_parser,
)?;

// get plot size
let plot_size = get_user_input(
// get farm size
let farm_size = get_user_input(
&format!(
"Specify a plot size (defaults to `{DEFAULT_PLOT_SIZE}`, press enter to use the \
"Specify a farm size (defaults to `{DEFAULT_FARM_SIZE}`, press enter to use the \
default): "
),
Some(DEFAULT_PLOT_SIZE),
Some(DEFAULT_FARM_SIZE),
size_parser,
)?;

Expand All @@ -111,8 +111,8 @@ fn get_config_from_user_inputs() -> Result<Config> {
)?;

let farmer_config = FarmerConfig {
plot_size,
plot_directory,
farm_size,
farm_directory,
reward_address,
advanced: AdvancedFarmerSettings::default(),
};
Expand Down
14 changes: 7 additions & 7 deletions src/commands/wipe.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use color_eyre::eyre::{Context, Result};
use owo_colors::OwoColorize;
use subspace_sdk::{Node, PlotDescription};
use subspace_sdk::{FarmDescription, Node};

use crate::config::{delete_config, parse_config};
use crate::summary::delete_summary;
use crate::utils::{
get_user_input, node_directory_getter, plot_directory_getter, yes_or_no_parser,
farm_directory_getter, get_user_input, node_directory_getter, yes_or_no_parser,
};

/// wipe configurator
Expand All @@ -15,7 +15,7 @@ use crate::utils::{
pub(crate) async fn wipe_config(farmer: bool, node: bool) -> Result<()> {
if !farmer && !node {
// if user did not supply any argument, ask for everything
let prompt = "Do you want to wipe farmer (delete plot)? [y/n]: ";
let prompt = "Do you want to wipe farmer (delete farm)? [y/n]: ";
let wipe_farmer =
get_user_input(prompt, None, yes_or_no_parser).context("prompt failed")?;

Expand All @@ -41,7 +41,7 @@ pub(crate) async fn wipe_config(farmer: bool, node: bool) -> Result<()> {

/// implementation of the `wipe` command
///
/// can wipe farmer, node, summary and plot
/// can wipe farmer, node, summary and farm
async fn wipe(
wipe_farmer: bool,
wipe_node: bool,
Expand Down Expand Up @@ -69,15 +69,15 @@ async fn wipe(
}
};

// TODO: modify here when supporting multi-plot
// TODO: modify here when supporting multi-farm
// if config can be read, delete the farmer using the path in the config, else,
// delete the default location
if let Some(config) = config {
let _ = PlotDescription::new(config.farmer.plot_directory, config.farmer.plot_size)
let _ = FarmDescription::new(config.farmer.farm_directory, config.farmer.farm_size)
.wipe()
.await;
} else {
let _ = tokio::fs::remove_dir_all(plot_directory_getter()).await;
let _ = tokio::fs::remove_dir_all(farm_directory_getter()).await;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use subspace_sdk::farmer::Farmer;
use subspace_sdk::node::{
DomainConfigBuilder, DsnBuilder, NetworkBuilder, Node, PotConfiguration, Role,
};
use subspace_sdk::{chain_spec, ByteSize, PlotDescription, PublicKey};
use subspace_sdk::{chain_spec, ByteSize, FarmDescription, PublicKey};
use tracing::instrument;

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

/// defaults for the user config file
pub(crate) const DEFAULT_PLOT_SIZE: ByteSize = ByteSize::gb(2);
pub(crate) const MIN_PLOT_SIZE: ByteSize = ByteSize::gb(2);
pub(crate) const DEFAULT_FARM_SIZE: ByteSize = ByteSize::gb(2);
pub(crate) const MIN_FARM_SIZE: ByteSize = ByteSize::gb(2);

/// structure of the config toml file
#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -156,15 +156,15 @@ pub(crate) struct AdvancedFarmerSettings {
#[derive(Deserialize, Serialize, Clone, Debug)]
pub(crate) struct FarmerConfig {
pub(crate) reward_address: PublicKey,
pub(crate) plot_directory: PathBuf,
pub(crate) plot_size: ByteSize,
pub(crate) farm_directory: PathBuf,
pub(crate) farm_size: ByteSize,
#[serde(default, skip_serializing_if = "crate::utils::is_default")]
pub(crate) advanced: AdvancedFarmerSettings,
}

impl FarmerConfig {
pub async fn build(self, node: &Node) -> Result<Farmer> {
let plot_description = &[PlotDescription::new(self.plot_directory, self.plot_size)];
let farm_description = &[FarmDescription::new(self.farm_directory, self.farm_size)];

// currently we do not have different configuration for the farmer w.r.t
// different chains, but we may in the future
Expand All @@ -174,7 +174,7 @@ impl FarmerConfig {
.build(
self.reward_address,
node,
plot_description,
farm_description,
// TODO: Make this configurable via user input
NonZeroU8::new(1).expect("static value should not fail; qed"),
)
Expand Down Expand Up @@ -239,8 +239,8 @@ pub(crate) fn validate_config() -> Result<Config> {
let config = parse_config()?;

// validity checks
if config.farmer.plot_size < MIN_PLOT_SIZE {
return Err(eyre!("plot size should be bigger than {MIN_PLOT_SIZE}!"));
if config.farmer.farm_size < MIN_FARM_SIZE {
return Err(eyre!("farm size should be bigger than {MIN_FARM_SIZE}!"));
}

Ok(config)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum Commands {
#[arg(long, action)]
no_rotation: bool,
},
#[command(about = "wipes the node and farm instance (along with your plots)")]
#[command(about = "wipes the node and farm instance (along with your farms)")]
Wipe {
#[arg(long, action)]
farmer: bool,
Expand Down
18 changes: 9 additions & 9 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use subspace_sdk::ByteSize;
use crate::config::ChainConfig;
use crate::summary::*;
use crate::utils::{
apply_extra_options, custom_log_dir, directory_parser, node_directory_getter, node_name_parser,
plot_directory_getter, reward_address_parser, size_parser, yes_or_no_parser,
apply_extra_options, custom_log_dir, directory_parser, farm_directory_getter,
node_directory_getter, node_name_parser, reward_address_parser, size_parser, yes_or_no_parser,
};

async fn update_summary_file_randomly(summary_file: SummaryFile) {
Expand Down Expand Up @@ -37,9 +37,9 @@ async fn summary_file_integration() {
}

// create summary file
let plot_size = ByteSize::gb(1);
let farm_size = ByteSize::gb(1);
let summary_file =
SummaryFile::new(Some(plot_size)).await.expect("Failed to create summary file");
SummaryFile::new(Some(farm_size)).await.expect("Failed to create summary file");

// sequential update trial
let update_fields = SummaryUpdateFields {
Expand Down Expand Up @@ -139,17 +139,17 @@ fn chain_checker() {
}

#[test]
fn plot_directory_tester() {
let plot_path = plot_directory_getter();
fn farm_directory_tester() {
let farm_path = farm_directory_getter();

#[cfg(target_os = "macos")]
assert!(plot_path.ends_with("Library/Application Support/pulsar/plots"));
assert!(farm_path.ends_with("Library/Application Support/pulsar/farms"));

#[cfg(target_os = "linux")]
assert!(plot_path.ends_with(".local/share/pulsar/plots"));
assert!(farm_path.ends_with(".local/share/pulsar/farms"));

#[cfg(target_os = "windows")]
assert!(plot_path.ends_with("AppData/Roaming/pulsar/plots"));
assert!(farm_path.ends_with("AppData/Roaming/pulsar/farms"));
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter, Layer};

use crate::config::MIN_PLOT_SIZE;
use crate::config::MIN_FARM_SIZE;
use crate::summary::Rewards;

/// for how long a log file should be valid
Expand Down Expand Up @@ -124,8 +124,8 @@ pub(crate) fn size_parser(size: &str) -> Result<ByteSize> {
let Ok(size) = size.parse::<ByteSize>() else {
return Err(eyre!("could not parse the value!"));
};
if size < MIN_PLOT_SIZE {
Err(eyre!(format!("plot size cannot be smaller than {}", MIN_PLOT_SIZE)))
if size < MIN_FARM_SIZE {
Err(eyre!(format!("farm size cannot be smaller than {}", MIN_FARM_SIZE)))
} else {
Ok(size)
}
Expand All @@ -139,9 +139,9 @@ pub(crate) fn yes_or_no_parser(answer: &str) -> Result<bool> {
}
}

/// generates a plot path from the given path
pub(crate) fn plot_directory_getter() -> PathBuf {
data_dir_getter().join("plots")
/// generates a farm path from the given path
pub(crate) fn farm_directory_getter() -> PathBuf {
data_dir_getter().join("farms")
}

/// generates a node path from the given path
Expand Down

0 comments on commit 91b4df0

Please sign in to comment.