Skip to content

Commit

Permalink
Merge branch 'main' into extract_archive_block
Browse files Browse the repository at this point in the history
  • Loading branch information
shamil-gadelshin authored May 9, 2024
2 parents f0bb77c + 3d749ab commit 6cd744f
Show file tree
Hide file tree
Showing 18 changed files with 543 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn audit(
NonZeroUsize::new(Record::NUM_S_BUCKETS.next_power_of_two().ilog2() as usize)
.expect("Not zero; qed"),
)
.map_err(|error| anyhow::anyhow!(error))?;
.map_err(|error| anyhow!("Failed to instantiate erasure coding: {error}"))?;
let table_generator = Mutex::new(PosTable::generator());

let sectors_metadata = SingleDiskFarm::read_all_sectors_metadata(&disk_farm)
Expand Down Expand Up @@ -276,7 +276,7 @@ fn prove(
NonZeroUsize::new(Record::NUM_S_BUCKETS.next_power_of_two().ilog2() as usize)
.expect("Not zero; qed"),
)
.map_err(|error| anyhow::anyhow!(error))?;
.map_err(|error| anyhow!("Failed to instantiate erasure coding: {error}"))?;
let table_generator = Mutex::new(PosTable::generator());

let mut sectors_metadata = SingleDiskFarm::read_all_sectors_metadata(&disk_farm)
Expand Down
24 changes: 13 additions & 11 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use subspace_farmer::farm::{
Farm, FarmingNotification, SectorExpirationDetails, SectorPlottingDetails, SectorUpdate,
};
use subspace_farmer::farmer_cache::FarmerCache;
use subspace_farmer::node_client::node_rpc_client::NodeRpcClient;
use subspace_farmer::node_client::NodeClient;
use subspace_farmer::plotter::cpu::CpuPlotter;
use subspace_farmer::single_disk_farm::{
SingleDiskFarm, SingleDiskFarmError, SingleDiskFarmOptions,
Expand All @@ -39,7 +41,7 @@ use subspace_farmer::utils::{
recommended_number_of_farming_threads, run_future_in_dedicated_thread,
thread_pool_core_indices, AsyncJoinOnDrop,
};
use subspace_farmer::{Identity, NodeClient, NodeRpcClient};
use subspace_farmer::Identity;
use subspace_farmer_components::plotting::PlottedSector;
use subspace_metrics::{start_prometheus_metrics_server, RegistryAdapter};
use subspace_networking::utils::piece_provider::PieceProvider;
Expand Down Expand Up @@ -73,7 +75,7 @@ pub(crate) struct FarmingArgs {
///
/// `size` is max allocated size in human-readable format (e.g. 10GB, 2TiB) or just bytes that
/// farmer will make sure to not exceed (and will pre-allocated all the space on startup to
/// ensure it will not run out of space in runtime). Also optionally `record-chunks-mode` can be
/// ensure it will not run out of space in runtime). Optionally, `record-chunks-mode` can be
/// set to `ConcurrentChunks` or `WholeSector` in order to avoid internal benchmarking during
/// startup.
disk_farms: Vec<DiskFarm>,
Expand All @@ -90,8 +92,8 @@ pub(crate) struct FarmingArgs {
#[arg(long)]
dev: bool,
/// Run temporary farmer with specified plot size in human-readable format (e.g. 10GB, 2TiB) or
/// just bytes (e.g. 4096), this will create a temporary directory for storing farmer data that
/// will be deleted at the end of the process.
/// just bytes (e.g. 4096), this will create a temporary directory that will be deleted at the
/// end of the process.
#[arg(long, conflicts_with = "disk_farms")]
tmp: Option<ByteSize>,
/// Maximum number of pieces in sector (can override protocol value to something lower).
Expand Down Expand Up @@ -257,7 +259,7 @@ where
!cfg!(windows)
|| disk_farms
.iter()
.map(|farm| farm.allocated_plotting_space)
.map(|farm| farm.allocated_space)
.sum::<u64>()
<= MAX_SPACE_PLEDGED_FOR_PLOT_CACHE_ON_WINDOWS
});
Expand All @@ -272,7 +274,7 @@ where

disk_farms = vec![DiskFarm {
directory: tmp_directory.as_ref().to_path_buf(),
allocated_plotting_space: plot_size.as_u64(),
allocated_space: plot_size.as_u64(),
read_sector_record_chunks_mode: None,
}];

Expand Down Expand Up @@ -304,7 +306,7 @@ where
let farmer_app_info = node_client
.farmer_app_info()
.await
.map_err(|error| anyhow!(error))?;
.map_err(|error| anyhow!("Failed to get farmer app info: {error}"))?;

let first_farm_directory = &disk_farms
.first()
Expand Down Expand Up @@ -370,7 +372,7 @@ where
NonZeroUsize::new(Record::NUM_S_BUCKETS.next_power_of_two().ilog2() as usize)
.expect("Not zero; qed"),
)
.map_err(|error| anyhow!(error))?;
.map_err(|error| anyhow!("Failed to instantiate erasure coding: {error}"))?;
let validator = Some(SegmentCommitmentPieceValidator::new(
node.clone(),
node_client.clone(),
Expand Down Expand Up @@ -542,7 +544,7 @@ where
SingleDiskFarmOptions {
directory: disk_farm.directory.clone(),
farmer_app_info,
allocated_space: disk_farm.allocated_plotting_space,
allocated_space: disk_farm.allocated_space,
max_pieces_in_sector,
node_client,
reward_address,
Expand Down Expand Up @@ -679,7 +681,7 @@ where

plotted_pieces.add_farm(farm_index, farm.piece_reader());

let total_sector_count = farm.total_sectors_count();
let total_sectors_count = farm.total_sectors_count();
let mut plotted_sectors_count = 0;
let plotted_sectors = farm.plotted_sectors();
let mut plotted_sectors = plotted_sectors.get().await.map_err(|error| {
Expand All @@ -698,7 +700,7 @@ where
)
}

total_and_plotted_sectors.push((total_sector_count, plotted_sectors_count));
total_and_plotted_sectors.push((total_sectors_count, plotted_sectors_count));
}

info!("Finished collecting already plotted pieces successfully");
Expand Down
20 changes: 9 additions & 11 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl From<PlottingThreadPriority> for Option<ThreadPriority> {

#[derive(Debug, Clone)]
pub(in super::super) struct DiskFarm {
/// Path to directory where data is stored.
/// Path to directory where farm is stored
pub(in super::super) directory: PathBuf,
/// How much space in bytes can farm use for plots (metadata space is not included)
pub(in super::super) allocated_plotting_space: u64,
/// How much space in bytes can farm use
pub(in super::super) allocated_space: u64,
/// Which mode to use for reading of sector record chunks
pub(in super::super) read_sector_record_chunks_mode: Option<ReadSectorRecordChunksMode>,
}
Expand All @@ -76,7 +76,7 @@ impl FromStr for DiskFarm {
}

let mut plot_directory = None;
let mut allocated_plotting_space = None;
let mut allocated_space = None;
let mut read_sector_record_chunks_mode = None;

for part in parts {
Expand All @@ -93,7 +93,7 @@ impl FromStr for DiskFarm {
plot_directory.replace(PathBuf::from(value));
}
"size" => {
allocated_plotting_space.replace(
allocated_space.replace(
value
.parse::<ByteSize>()
.map_err(|error| {
Expand Down Expand Up @@ -121,12 +121,10 @@ impl FromStr for DiskFarm {
}

Ok(DiskFarm {
directory: plot_directory.ok_or({
"`path` key is required with path to directory where plots will be stored"
})?,
allocated_plotting_space: allocated_plotting_space.ok_or({
"`size` key is required with path to directory where plots will be stored"
})?,
directory: plot_directory
.ok_or("`path` key is required with path to directory where farm will be stored")?,
allocated_space: allocated_space
.ok_or("`size` key is required with allocated amount of disk space")?,
read_sector_record_chunks_mode,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::Path;
use std::sync::{Arc, Weak};
use subspace_farmer::farmer_cache::FarmerCache;
use subspace_farmer::node_client::NodeClientExt;
use subspace_farmer::node_client::node_rpc_client::NodeRpcClient;
use subspace_farmer::node_client::{NodeClient, NodeClientExt};
use subspace_farmer::utils::plotted_pieces::PlottedPieces;
use subspace_farmer::{NodeClient, NodeRpcClient, KNOWN_PEERS_CACHE_SIZE};
use subspace_farmer::KNOWN_PEERS_CACHE_SIZE;
use subspace_networking::libp2p::identity::Keypair;
use subspace_networking::libp2p::kad::RecordKey;
use subspace_networking::libp2p::multiaddr::Protocol;
Expand Down Expand Up @@ -137,8 +138,7 @@ where

let read_piece_fut = match weak_plotted_pieces.upgrade() {
Some(plotted_pieces) => plotted_pieces
.read()
.await
.try_read()?
.read_piece(piece_index)?
.in_current_span(),
None => {
Expand Down
Loading

0 comments on commit 6cd744f

Please sign in to comment.