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

Commit

Permalink
Update sdk (#169)
Browse files Browse the repository at this point in the history
* separate tests

* update sdk revision

* changes related to tokio_unstable 

* small summary revamp

* wipe should not generate error if file is not found

* yank version
  • Loading branch information
ozgunozerk authored Apr 14, 2023
1 parent 72950e7 commit 98dc55e
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 345 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
CARGO_TERM_COLOR: always
# Build smaller artifacts to avoid running out of space in CI
# TODO: Try to remove once https://github.com/paritytech/substrate/issues/11538 is resolved
RUSTFLAGS: -C strip=symbols -C opt-level=s --cfg tokio_unstable
RUSTFLAGS: -C strip=symbols -C opt-level=s
# Remove unnecessary WASM build artefacts
WASM_BUILD_CLEAN_TARGET: 1

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUSTFLAGS: --cfg tokio_unstable

jobs:
rustdoc:
Expand Down
155 changes: 72 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
name = "subspace-cli"
version = "0.3.0"
version = "0.3.1"
edition = "2021"

[dependencies]
bytesize = "1.1"
bytesize-serde = "0.2"
clap = { version = "4.1.1", features = ["derive"] }
color-eyre = "0.6.2"
console-subscriber = "0.1"
derivative = "2.2.0"
dirs = "4.0.0"
fdlimit = "0.2"
Expand All @@ -31,16 +30,16 @@ tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
whoami = "1"

subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "cc3460710f63a431faba7ea1572eda1971e0c9ee" }
subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "2858928134fd497094986b130c0622904561a5f3" }

# The only triple tested and confirmed as working in `jemallocator` crate is `x86_64-unknown-linux-gnu`
[target.'cfg(all(target_arch = "x86_64", target_vendor = "unknown", target_os = "linux", target_env = "gnu"))'.dependencies]
jemallocator = "0.5.0"

[patch.crates-io]
# TODO: Remove once chacha20poly1305 0.10 appears in libp2p's dependencies
chacha20poly1305 = { git = "https://github.com/RustCrypto/AEADs", rev = "06dbfb5571687fd1bbe9d3c9b2193a1ba17f8e99" }
[target.'cfg(tokio_unstable)'.dependencies]
console-subscriber = "0.1"

[patch.crates-io]
# TODO: remove once tracing-appender has a new release
tracing = { git = "https://github.com/tokio-rs/tracing", branch = "v0.1.x" }
tracing-appender = { git = "https://github.com/tokio-rs/tracing", branch = "v0.1.x" }
Expand Down
58 changes: 26 additions & 32 deletions src/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use tokio::task::JoinHandle;
use tracing::instrument;

use crate::config::{validate_config, ChainConfig, Config};
use crate::summary::{Rewards, Summary, SummaryUpdateFields};
use crate::utils::{install_tracing, raise_fd_limit};
use crate::summary::{Rewards, Summary, SummaryFilePointer, SummaryUpdateFields};
use crate::utils::{install_tracing, raise_fd_limit, spawn_task};

/// allows us to detect multiple instances of the farmer and act on it
pub(crate) const SINGLE_INSTANCE: &str = ".subspaceFarmer";
Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) async fn farm(is_verbose: bool, executor: bool) -> Result<()> {
}
}

let summary = Summary::new(Some(farmer_config.plot_size)).await?;
let summary = SummaryFilePointer::new(Some(farmer_config.plot_size.clone())).await?;

println!("Starting farmer ...");
let farmer = Arc::new(farmer_config.build(&node).await?);
Expand All @@ -78,19 +78,25 @@ pub(crate) async fn farm(is_verbose: bool, executor: bool) -> Result<()> {
let is_initial_progress_finished = Arc::new(AtomicBool::new(false));
let sector_size_bytes = farmer.get_info().await.map_err(Report::msg)?.sector_size;

let plotting_sub_handle = tokio::spawn(subscribe_to_plotting_progress(
summary.clone(),
farmer.clone(),
is_initial_progress_finished.clone(),
sector_size_bytes,
));
let plotting_sub_handle = spawn_task(
"plotting_subscriber",
subscribe_to_plotting_progress(
summary.clone(),
farmer.clone(),
is_initial_progress_finished.clone(),
sector_size_bytes,
),
);

let solution_sub_handle = tokio::spawn(subscribe_to_solutions(
summary.clone(),
node.clone(),
is_initial_progress_finished.clone(),
reward_address,
));
let solution_sub_handle = spawn_task(
"solution_subscriber",
subscribe_to_solutions(
summary.clone(),
node.clone(),
is_initial_progress_finished.clone(),
reward_address,
),
);

Some((plotting_sub_handle, solution_sub_handle))
} else {
Expand Down Expand Up @@ -132,7 +138,7 @@ async fn wait_on_farmer(
}

// shutting down the farmer and the node
let graceful_close_handle = tokio::spawn(async move {
let graceful_close_handle = spawn_task("graceful_shutdown_listener", async move {
// if one of the subscriptions have not aborted yet, wait
// Plotting might end, so we ignore result here

Expand Down Expand Up @@ -186,7 +192,7 @@ async fn subscribe_to_node_syncing(node: &Node) -> Result<()> {
}

async fn subscribe_to_plotting_progress(
summary: Summary,
summary: SummaryFilePointer,
farmer: Arc<Farmer>,
is_initial_progress_finished: Arc<AtomicBool>,
sector_size_bytes: u64,
Expand Down Expand Up @@ -231,7 +237,7 @@ async fn subscribe_to_plotting_progress(
}

async fn subscribe_to_solutions(
summary: Summary,
summary: SummaryFilePointer,
node: Arc<Node>,
is_initial_progress_finished: Arc<AtomicBool>,
reward_address: PublicKey,
Expand Down Expand Up @@ -277,20 +283,8 @@ async fn subscribe_to_solutions(
// error, we will
// abandon this
// mechanism
let (farmed_block_count, vote_count, total_rewards) = (
summary
.get_farmed_block_count()
.await
.context("couldn't read farmed block count value, summary was corrupted")?,
summary
.get_vote_count()
.await
.context("couldn't read vote count value, summary was corrupted")?,
summary
.get_total_rewards()
.await
.context("couldn't read total rewards value, summary was corrupted")?,
);
let Summary { total_rewards, farmed_block_count, vote_count, .. } =
summary.parse_summary().await.context("couldn't parse summary")?;

if is_initial_progress_finished.load(Ordering::Relaxed) {
print!(
Expand Down
49 changes: 14 additions & 35 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use color_eyre::eyre::{Context, Result};
use single_instance::SingleInstance;

use crate::commands::farm::SINGLE_INSTANCE;
use crate::summary::Summary;
use crate::summary::{Summary, SummaryFilePointer};

/// implementation of the `init` command.
///
Expand All @@ -16,45 +16,24 @@ pub(crate) async fn info() -> Result<()> {
println!("There is no active farmer instance...");
}

let summary = Summary::new(None).await?;
let summary = SummaryFilePointer::new(None).await?;
let Summary {
user_space_pledged,
farmed_block_count,
vote_count,
total_rewards,
initial_plotting_finished,
} = summary.parse_summary().await.context("couldn't parse summary file")?;

println!(
"You have pledged to the network: {}",
summary
.get_user_space_pledged()
.await
.context("Couldn't read the summary file, are you sure you ran the farm command?")?
);
println!("You have pledged to the network: {user_space_pledged}");

println!(
"Farmed {} block(s)",
summary
.get_farmed_block_count()
.await
.context("Couldn't read the summary file, are you sure you ran the farm command?")?
);
println!("Farmed {farmed_block_count} block(s)");

println!(
"Voted on {} block(s)",
summary
.get_vote_count()
.await
.context("Couldn't read the summary file, are you sure you ran the farm command?")?
);
println!("Voted on {vote_count} block(s)");

println!(
"{} SSC(s) earned!",
summary
.get_total_rewards()
.await
.context("Couldn't read the summary file, are you sure you ran the farm command?")?
);
println!("{total_rewards} SSC(s) earned!",);

if summary
.get_initial_plotting_progress()
.await
.context("Couldn't read the summary file, are you sure you ran the farm command?")?
{
if initial_plotting_finished {
println!("Initial plotting is finished!");
} else {
println!("Initial plotting is not finished...");
Expand Down
12 changes: 9 additions & 3 deletions src/commands/wipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ pub(crate) async fn wipe(
}

if wipe_summary {
delete_summary()?
match delete_summary() {
Ok(_) => println!("deleted the summary file"),
Err(_) => println!("Skipping wiping summary, could not find the file..."),
}
}

if wipe_config {
delete_config()?
match delete_config() {
Ok(_) => println!("deleted the config file"),
Err(_) => println!("Skipping wiping config, could not find the file..."),
}
}

println!("Wipe successful!");
println!("Wipe finished!");

Ok(())
}
12 changes: 5 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ use std::fs::{create_dir_all, remove_file, File};
use std::path::PathBuf;
use std::str::FromStr;

use bytesize::ByteSize;
use color_eyre::eyre::{eyre, Report, Result, WrapErr};
use derivative::Derivative;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use subspace_sdk::farmer::{CacheDescription, Farmer};
use subspace_sdk::node::domains::core::ConfigBuilder;
use subspace_sdk::node::{domains, DsnBuilder, NetworkBuilder, Node, Role};
use subspace_sdk::{chain_spec, PlotDescription, PublicKey};
use subspace_sdk::{chain_spec, ByteSize, PlotDescription, PublicKey};
use tracing::instrument;

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

/// defaults for the user config file
pub(crate) const DEFAULT_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::gb(1);
pub(crate) const MIN_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::mib(32);
pub(crate) const DEFAULT_PLOT_SIZE: ByteSize = ByteSize::gb(1);
pub(crate) const MIN_PLOT_SIZE: ByteSize = ByteSize::mib(32);

/// structure of the config toml file
#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -97,8 +96,8 @@ impl NodeConfig {
#[derive(Deserialize, Serialize, Clone, Derivative, Debug, PartialEq)]
#[derivative(Default)]
pub(crate) struct AdvancedFarmerSettings {
#[serde(with = "bytesize_serde", default, skip_serializing_if = "crate::utils::is_default")]
#[derivative(Default(value = "bytesize::ByteSize::gb(1)"))]
#[serde(default, skip_serializing_if = "crate::utils::is_default")]
#[derivative(Default(value = "subspace_sdk::ByteSize::gb(1)"))]
pub(crate) cache_size: ByteSize,
#[serde(default, flatten)]
pub(crate) extra: toml::Table,
Expand All @@ -109,7 +108,6 @@ pub(crate) struct AdvancedFarmerSettings {
pub(crate) struct FarmerConfig {
pub(crate) reward_address: PublicKey,
pub(crate) plot_directory: PathBuf,
#[serde(with = "bytesize_serde")]
pub(crate) plot_size: ByteSize,
#[serde(default, skip_serializing_if = "crate::utils::is_default")]
pub(crate) advanced: AdvancedFarmerSettings,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ mod config;
mod summary;
mod utils;

#[cfg(test)]
mod tests;

use clap::{Parser, Subcommand};
use color_eyre::eyre::{Context, Report};
use color_eyre::Help;
Expand Down
Loading

0 comments on commit 98dc55e

Please sign in to comment.