diff --git a/crates/pallet-subspace/src/mock.rs b/crates/pallet-subspace/src/mock.rs index a58a20382e..fecfdc034b 100644 --- a/crates/pallet-subspace/src/mock.rs +++ b/crates/pallet-subspace/src/mock.rs @@ -410,13 +410,12 @@ pub fn create_signed_vote( let pieces_in_sector = farmer_protocol_info.max_pieces_in_sector; let sector_size = sector_size(pieces_in_sector); - for (sector_offset, sector_index) in iter::from_fn(|| Some(rand::random())).enumerate() { + for sector_index in iter::from_fn(|| Some(rand::random())) { let mut plotted_sector_bytes = vec![0; sector_size]; let mut plotted_sector_metadata_bytes = vec![0; SectorMetadata::encoded_size()]; let plotted_sector = block_on(plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, archived_history_segment, PieceGetterRetryPolicy::default(), diff --git a/crates/sp-lightclient/src/tests.rs b/crates/sp-lightclient/src/tests.rs index 39767ab8e6..ad467d54ff 100644 --- a/crates/sp-lightclient/src/tests.rs +++ b/crates/sp-lightclient/src/tests.rs @@ -153,13 +153,12 @@ fn valid_header( let pieces_in_sector = farmer_parameters.farmer_protocol_info.max_pieces_in_sector; let sector_size = sector_size(pieces_in_sector); - for (sector_offset, sector_index) in iter::from_fn(|| Some(rand::random())).enumerate() { + for sector_index in iter::from_fn(|| Some(rand::random())) { let mut plotted_sector_bytes = vec![0; sector_size]; let mut plotted_sector_metadata_bytes = vec![0; SectorMetadata::encoded_size()]; let plotted_sector = block_on(plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &farmer_parameters.archived_segment.pieces, PieceGetterRetryPolicy::default(), diff --git a/crates/subspace-farmer-components/benches/auditing.rs b/crates/subspace-farmer-components/benches/auditing.rs index 07c3b6e6e0..a31606b401 100644 --- a/crates/subspace-farmer-components/benches/auditing.rs +++ b/crates/subspace-farmer-components/benches/auditing.rs @@ -42,7 +42,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { .unwrap_or(10); let public_key = PublicKey::default(); - let sector_offset = 0; let sector_index = 0; let mut input = RecordedHistorySegment::new_boxed(); StdRng::seed_from_u64(42).fill(AsMut::<[u8]>::as_mut(input.as_mut())); @@ -116,7 +115,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { let plotted_sector = block_on(plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &archived_history_segment, PieceGetterRetryPolicy::default(), diff --git a/crates/subspace-farmer-components/benches/plotting.rs b/crates/subspace-farmer-components/benches/plotting.rs index 185574143f..6302927c43 100644 --- a/crates/subspace-farmer-components/benches/plotting.rs +++ b/crates/subspace-farmer-components/benches/plotting.rs @@ -26,7 +26,6 @@ fn criterion_benchmark(c: &mut Criterion) { .unwrap_or_else(|_error| MAX_PIECES_IN_SECTOR); let public_key = PublicKey::default(); - let sector_offset = 0; let sector_index = 0; let mut input = RecordedHistorySegment::new_boxed(); StdRng::seed_from_u64(42).fill(AsMut::<[u8]>::as_mut(input.as_mut())); @@ -67,7 +66,6 @@ fn criterion_benchmark(c: &mut Criterion) { b.iter(|| { block_on(plot_sector::<_, PosTable>( black_box(&public_key), - black_box(sector_offset), black_box(sector_index), black_box(&archived_history_segment), black_box(PieceGetterRetryPolicy::default()), diff --git a/crates/subspace-farmer-components/benches/proving.rs b/crates/subspace-farmer-components/benches/proving.rs index 9b932adfbc..22daef0efa 100644 --- a/crates/subspace-farmer-components/benches/proving.rs +++ b/crates/subspace-farmer-components/benches/proving.rs @@ -44,7 +44,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { let keypair = Keypair::from_bytes(&[0; 96]).unwrap(); let public_key = PublicKey::from(keypair.public.to_bytes()); - let sector_offset = 0; let sector_index = 0; let mut input = RecordedHistorySegment::new_boxed(); let mut rng = StdRng::seed_from_u64(42); @@ -119,7 +118,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { let plotted_sector = block_on(plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &archived_history_segment, PieceGetterRetryPolicy::default(), diff --git a/crates/subspace-farmer-components/benches/reading.rs b/crates/subspace-farmer-components/benches/reading.rs index 425475a42c..7142e589e4 100644 --- a/crates/subspace-farmer-components/benches/reading.rs +++ b/crates/subspace-farmer-components/benches/reading.rs @@ -41,7 +41,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { .unwrap_or(10); let public_key = PublicKey::default(); - let sector_offset = 0; let sector_index = 0; let mut input = RecordedHistorySegment::new_boxed(); StdRng::seed_from_u64(42).fill(AsMut::<[u8]>::as_mut(input.as_mut())); @@ -113,7 +112,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { let plotted_sector = block_on(plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &archived_history_segment, PieceGetterRetryPolicy::default(), diff --git a/crates/subspace-farmer-components/src/plotting.rs b/crates/subspace-farmer-components/src/plotting.rs index ef161fd420..fe04112bcb 100644 --- a/crates/subspace-farmer-components/src/plotting.rs +++ b/crates/subspace-farmer-components/src/plotting.rs @@ -160,7 +160,6 @@ pub enum PlottingError { #[allow(clippy::too_many_arguments)] pub async fn plot_sector( public_key: &PublicKey, - sector_offset: usize, sector_index: u64, piece_getter: &PG, piece_getter_retry_policy: PieceGetterRetryPolicy, @@ -230,7 +229,6 @@ where .await { warn!( - %sector_offset, %sector_index, %error, "Sector plotting attempt failed, will retry later" @@ -239,7 +237,7 @@ where return Err(BackoffError::transient(error)); } - debug!(%sector_offset, %sector_index, "Sector downloaded successfully"); + debug!(%sector_index, "Sector downloaded successfully"); Ok(()) }) diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs index 3fef15fae2..a53070cd5f 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs @@ -17,7 +17,8 @@ use std::sync::Arc; use std::time::Duration; use subspace_core_primitives::crypto::kzg::{embedded_kzg_settings, Kzg}; use subspace_core_primitives::{ - ArchivedHistorySegment, Piece, PieceIndex, PieceIndexHash, PieceOffset, Record, SegmentIndex, + ArchivedHistorySegment, Piece, PieceIndex, PieceIndexHash, PieceOffset, Record, SectorIndex, + SegmentIndex, }; use subspace_erasure_coding::ErasureCoding; use subspace_farmer::single_disk_plot::{ @@ -253,23 +254,22 @@ where .iter() .enumerate() .flat_map(|(disk_farm_index, single_disk_plot)| { - single_disk_plot - .plotted_sectors() - .enumerate() - .filter_map(move |(sector_offset, plotted_sector_result)| { - match plotted_sector_result { + (0 as SectorIndex..) + .zip(single_disk_plot.plotted_sectors()) + .filter_map( + move |(sector_index, plotted_sector_result)| match plotted_sector_result { Ok(plotted_sector) => Some(plotted_sector), Err(error) => { error!( %error, %disk_farm_index, - %sector_offset, + %sector_index, "Failed reading plotted sector on startup, skipping" ); None } - } - }) + }, + ) .flat_map(move |plotted_sector| { (PieceOffset::ZERO..).zip(plotted_sector.piece_indexes).map( move |(piece_offset, piece_index)| { @@ -310,95 +310,87 @@ where // Collect newly plotted pieces // TODO: Once we have replotting, this will have to be updated single_disk_plot - .on_sector_plotted(Arc::new( - move |(sector_offset, plotted_sector, plotting_permit)| { - let _span_guard = span.enter(); - let plotting_permit = Arc::clone(plotting_permit); - let node = node.clone(); - let sector_offset = *sector_offset; - let sector_index = plotted_sector.sector_index; - - let mut dropped_receiver = dropped_sender.subscribe(); - - let new_pieces = { - let mut readers_and_pieces = readers_and_pieces.lock(); - let readers_and_pieces = readers_and_pieces - .as_mut() - .expect("Initial value was populated above; qed"); - - let new_pieces = plotted_sector - .piece_indexes - .iter() - .filter(|&&piece_index| { - // Skip pieces that are already plotted and thus were announced - // before - !readers_and_pieces.contains_piece(&piece_index.hash()) - }) - .copied() - .collect::>(); - - readers_and_pieces.add_pieces( - (PieceOffset::ZERO..) - .zip(plotted_sector.piece_indexes.iter().copied()) - .map(|(piece_offset, piece_index)| { - ( - piece_index.hash(), - PieceDetails { - disk_farm_index, - sector_index, - piece_offset, - }, - ) - }), - ); - - new_pieces - }; + .on_sector_plotted(Arc::new(move |(plotted_sector, plotting_permit)| { + let _span_guard = span.enter(); + let plotting_permit = Arc::clone(plotting_permit); + let node = node.clone(); + let sector_index = plotted_sector.sector_index; + + let mut dropped_receiver = dropped_sender.subscribe(); + + let new_pieces = { + let mut readers_and_pieces = readers_and_pieces.lock(); + let readers_and_pieces = readers_and_pieces + .as_mut() + .expect("Initial value was populated above; qed"); + + let new_pieces = plotted_sector + .piece_indexes + .iter() + .filter(|&&piece_index| { + // Skip pieces that are already plotted and thus were announced + // before + !readers_and_pieces.contains_piece(&piece_index.hash()) + }) + .copied() + .collect::>(); + + readers_and_pieces.add_pieces( + (PieceOffset::ZERO..) + .zip(plotted_sector.piece_indexes.iter().copied()) + .map(|(piece_offset, piece_index)| { + ( + piece_index.hash(), + PieceDetails { + disk_farm_index, + sector_index, + piece_offset, + }, + ) + }), + ); - if new_pieces.is_empty() { - // None of the pieces are new, nothing left to do here - return; - } + new_pieces + }; - archival_storage_pieces.add_pieces(&new_pieces); + if new_pieces.is_empty() { + // None of the pieces are new, nothing left to do here + return; + } - // TODO: Skip those that were already announced (because they cached) - let publish_fut = async move { - let mut pieces_publishing_futures = new_pieces - .into_iter() - .map(|piece_index| { - announce_single_piece_index_hash_with_backoff( - piece_index.hash(), - &node, - ) - }) - .collect::>(); + archival_storage_pieces.add_pieces(&new_pieces); + + // TODO: Skip those that were already announced (because they cached) + let publish_fut = async move { + let mut pieces_publishing_futures = new_pieces + .into_iter() + .map(|piece_index| { + announce_single_piece_index_hash_with_backoff( + piece_index.hash(), + &node, + ) + }) + .collect::>(); + + while pieces_publishing_futures.next().await.is_some() { + // Nothing is needed here, just driving all futures to completion + } - while pieces_publishing_futures.next().await.is_some() { - // Nothing is needed here, just driving all futures to completion - } + info!(?sector_index, "Sector publishing was successful."); - info!( - %sector_offset, - ?sector_index, - "Sector publishing was successful." - ); + // Release only after publishing is finished + drop(plotting_permit); + } + .in_current_span(); - // Release only after publishing is finished - drop(plotting_permit); + tokio::spawn(async move { + let result = + select(Box::pin(publish_fut), Box::pin(dropped_receiver.recv())).await; + if matches!(result, Either::Right(_)) { + debug!("Piece publishing was cancelled due to shutdown."); } - .in_current_span(); - - tokio::spawn(async move { - let result = - select(Box::pin(publish_fut), Box::pin(dropped_receiver.recv())) - .await; - if matches!(result, Either::Right(_)) { - debug!("Piece publishing was cancelled due to shutdown."); - } - }); - }, - )) + }); + })) .detach(); single_disk_plot.run() diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs b/crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs index a4c4bb8adb..484e454a5f 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs @@ -8,7 +8,6 @@ pub(crate) fn print_disk_farm_info(directory: PathBuf, disk_farm_index: usize) { println!(" ID: {}", info.id()); println!(" Genesis hash: 0x{}", hex::encode(info.genesis_hash())); println!(" Public key: 0x{}", hex::encode(info.public_key())); - println!(" First sector index: {}", info.first_sector_index()); println!( " Allocated space: {} ({})", bytesize::to_string(info.allocated_space(), true), diff --git a/crates/subspace-farmer/src/single_disk_plot.rs b/crates/subspace-farmer/src/single_disk_plot.rs index 756d52b3ab..a86ee9394d 100644 --- a/crates/subspace-farmer/src/single_disk_plot.rs +++ b/crates/subspace-farmer/src/single_disk_plot.rs @@ -30,7 +30,6 @@ use std::num::NonZeroU16; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::Arc; -use std::time::SystemTime; use std::{fmt, fs, io, thread}; use std_semaphore::{Semaphore, SemaphoreGuard}; use subspace_core_primitives::crypto::kzg::Kzg; @@ -116,12 +115,6 @@ pub enum SingleDiskPlotInfo { genesis_hash: [u8; 32], /// Public key of identity used for plot creation public_key: PublicKey, - /// First sector index in this plot - /// - /// Multiple plots can reuse the same identity, but they have to use different ranges for - /// sector indexes or else they'll essentially plot the same data and will not result in - /// increased probability of winning the reward. - first_sector_index: SectorIndex, /// How many pieces does one sector contain. pieces_in_sector: u16, /// How much space in bytes is allocated for this plot @@ -136,7 +129,6 @@ impl SingleDiskPlotInfo { id: SingleDiskPlotId, genesis_hash: [u8; 32], public_key: PublicKey, - first_sector_index: SectorIndex, pieces_in_sector: u16, allocated_space: u64, ) -> Self { @@ -144,7 +136,6 @@ impl SingleDiskPlotInfo { id, genesis_hash, public_key, - first_sector_index, pieces_in_sector, allocated_space, } @@ -195,18 +186,6 @@ impl SingleDiskPlotInfo { public_key } - /// First sector index in this plot - /// - /// Multiple plots can reuse the same identity, but they have to use different ranges for - /// sector indexes or else they'll essentially plot the same data and will not result in - /// increased probability of winning the reward. - pub fn first_sector_index(&self) -> SectorIndex { - let Self::V0 { - first_sector_index, .. - } = self; - *first_sector_index - } - /// How many pieces does one sector contain. pub fn pieces_in_sector(&self) -> u16 { let Self::V0 { @@ -250,7 +229,7 @@ pub enum SingleDiskPlotSummary { #[derive(Debug, Encode, Decode)] struct PlotMetadataHeader { version: u8, - sector_count: u64, + sector_count: SectorIndex, } impl PlotMetadataHeader { @@ -390,7 +369,7 @@ type Handler = Bag, A>; #[derive(Default, Debug)] struct Handlers { - sector_plotted: Handler<(usize, PlottedSector, Arc)>, + sector_plotted: Handler<(PlottedSector, Arc)>, solution: Handler, } @@ -529,19 +508,10 @@ impl SingleDiskPlot { }); } - // TODO: Global generator that makes sure to avoid returning the same sector index - // for multiple disks - let first_sector_index = SystemTime::UNIX_EPOCH - .elapsed() - .expect("Unix epoch is always in the past; qed") - .as_secs() - .wrapping_mul(u64::from(u32::MAX)); - let single_disk_plot_info = SingleDiskPlotInfo::new( SingleDiskPlotId::new(), farmer_app_info.genesis_hash, public_key, - first_sector_index, max_pieces_in_sector, allocated_space, ); @@ -555,11 +525,10 @@ impl SingleDiskPlot { let pieces_in_sector = single_disk_plot_info.pieces_in_sector(); let sector_size = sector_size(max_pieces_in_sector); let sector_metadata_size = SectorMetadata::encoded_size(); - let target_sector_count = - (single_disk_plot_info.allocated_space() / sector_size as u64) as usize; - let first_sector_index = single_disk_plot_info.first_sector_index(); + let target_sector_count: SectorIndex = + single_disk_plot_info.allocated_space() / sector_size as u64; - // TODO: Consider file locking to prevent other apps from modifying it + // TODO: Consider file locking to prevent other apps from modifying itS let mut metadata_file = OpenOptions::new() .read(true) .write(true) @@ -574,7 +543,7 @@ impl SingleDiskPlot { }; metadata_file.preallocate( - RESERVED_PLOT_METADATA + sector_metadata_size as u64 * target_sector_count as u64, + RESERVED_PLOT_METADATA + sector_metadata_size as u64 * target_sector_count, )?; metadata_file.write_all_at(metadata_header.encode().as_slice(), 0)?; @@ -608,11 +577,12 @@ impl SingleDiskPlot { let metadata_mmap = unsafe { MmapOptions::new() .offset(RESERVED_PLOT_METADATA) - .len(sector_metadata_size * target_sector_count) + .len(sector_metadata_size * target_sector_count as usize) .map(&metadata_file)? }; - let mut sectors_metadata = Vec::::with_capacity(target_sector_count); + let mut sectors_metadata = + Vec::::with_capacity(target_sector_count as usize); for mut sector_metadata_bytes in metadata_mmap .chunks_exact(sector_metadata_size) @@ -635,7 +605,7 @@ impl SingleDiskPlot { .open(directory.join(Self::PLOT_FILE))?, ); - plot_file.preallocate(sector_size as u64 * target_sector_count as u64)?; + plot_file.preallocate(sector_size as u64 * target_sector_count)?; let (error_sender, error_receiver) = oneshot::channel(); let error_sender = Arc::new(Mutex::new(Some(error_sender))); @@ -684,7 +654,6 @@ impl SingleDiskPlot { plotting::<_, _, PosTable>( public_key, - first_sector_index, node_client, pieces_in_sector, sector_size, @@ -781,7 +750,6 @@ impl SingleDiskPlot { farming::<_, PosTable>( public_key, reward_address, - first_sector_index, node_client, sector_size, plot_mmap, @@ -813,7 +781,6 @@ impl SingleDiskPlot { let (piece_reader, reading_fut) = PieceReader::new::( public_key, pieces_in_sector, - first_sector_index, unsafe { Mmap::map(&*plot_file)? }, Arc::clone(§ors_metadata), erasure_coding, @@ -895,11 +862,9 @@ impl SingleDiskPlot { &self, ) -> impl Iterator> + '_ { let public_key = self.single_disk_plot_info.public_key(); - let first_sector_index = self.single_disk_plot_info.first_sector_index(); - (first_sector_index..) - .zip(self.sectors_metadata.read().clone()) - .map(move |(sector_index, sector_metadata)| { + (0..).zip(self.sectors_metadata.read().clone()).map( + move |(sector_index, sector_metadata)| { let sector_id = SectorId::new(public_key.hash(), sector_index); let mut piece_indexes = Vec::with_capacity(self.pieces_in_sector.into()); @@ -922,7 +887,8 @@ impl SingleDiskPlot { sector_metadata, piece_indexes, }) - }) + }, + ) } /// Get piece reader to read plot pieces later @@ -936,7 +902,7 @@ impl SingleDiskPlot { /// throttling of the plotting process is desired. pub fn on_sector_plotted( &self, - callback: HandlerFn<(usize, PlottedSector, Arc)>, + callback: HandlerFn<(PlottedSector, Arc)>, ) -> HandlerId { self.handlers.sector_plotted.add(callback) } diff --git a/crates/subspace-farmer/src/single_disk_plot/farming.rs b/crates/subspace-farmer/src/single_disk_plot/farming.rs index f5a1811742..71fdb28e12 100644 --- a/crates/subspace-farmer/src/single_disk_plot/farming.rs +++ b/crates/subspace-farmer/src/single_disk_plot/farming.rs @@ -69,7 +69,6 @@ pub enum FarmingError { pub(super) async fn farming( public_key: PublicKey, reward_address: PublicKey, - first_sector_index: SectorIndex, node_client: NC, sector_size: usize, plot_mmap: Mmap, @@ -95,7 +94,7 @@ where let maybe_sector_being_modified = modifying_sector_guard.as_ref().copied(); let mut solutions = Vec::>::new(); - for ((sector_index, sector_metadata), sector) in (first_sector_index..) + for ((sector_index, sector_metadata), sector) in (0..) .zip(&*sectors_metadata) .zip(plot_mmap.chunks_exact(sector_size)) { diff --git a/crates/subspace-farmer/src/single_disk_plot/piece_reader.rs b/crates/subspace-farmer/src/single_disk_plot/piece_reader.rs index b49b471bbe..21efe3065f 100644 --- a/crates/subspace-farmer/src/single_disk_plot/piece_reader.rs +++ b/crates/subspace-farmer/src/single_disk_plot/piece_reader.rs @@ -32,7 +32,6 @@ impl PieceReader { pub(super) fn new( public_key: PublicKey, pieces_in_sector: u16, - first_sector_index: SectorIndex, global_plot_mmap: Mmap, sectors_metadata: Arc>>, erasure_coding: ErasureCoding, @@ -46,7 +45,6 @@ impl PieceReader { let reading_fut = read_pieces::( public_key, pieces_in_sector, - first_sector_index, global_plot_mmap, sectors_metadata, erasure_coding, @@ -85,7 +83,6 @@ impl PieceReader { async fn read_pieces( public_key: PublicKey, pieces_in_sector: u16, - first_sector_index: SectorIndex, global_plot_mmap: Mmap, sectors_metadata: Arc>>, erasure_coding: ErasureCoding, @@ -122,15 +119,13 @@ async fn read_pieces( let (sector_metadata, sector_count) = { let sectors_metadata = sectors_metadata.read(); - let sector_offset = (sector_index - first_sector_index) as usize; - let sector_count = sectors_metadata.len(); + let sector_count = sectors_metadata.len() as SectorIndex; - let sector_metadata = match sectors_metadata.get(sector_offset) { + let sector_metadata = match sectors_metadata.get(sector_index as usize) { Some(sector_metadata) => sector_metadata.clone(), None => { error!( %sector_index, - %first_sector_index, %sector_count, "Tried to read piece from sector that is not yet \ plotted" @@ -147,7 +142,6 @@ async fn read_pieces( piece_offset, pieces_in_sector, sector_count, - first_sector_index, §or_metadata, &global_plot_mmap, &erasure_coding, @@ -163,8 +157,7 @@ fn read_piece( public_key: &PublicKey, piece_offset: PieceOffset, pieces_in_sector: u16, - sector_count: usize, - first_sector_index: SectorIndex, + sector_count: SectorIndex, sector_metadata: &SectorMetadata, global_plot: &[u8], erasure_coding: &ErasureCoding, @@ -173,24 +166,12 @@ where PosTable: Table, { let sector_index = sector_metadata.sector_index; - if sector_index < first_sector_index { - warn!( - %sector_index, - %piece_offset, - %sector_count, - %first_sector_index, - "Incorrect first sector index" - ); - return None; - } - let sector_offset = (sector_index - first_sector_index) as usize; // Sector must be plotted - if sector_offset >= sector_count { + if sector_index >= sector_count { warn!( %sector_index, %piece_offset, %sector_count, - %first_sector_index, "Incorrect sector offset" ); return None; @@ -201,7 +182,6 @@ where %sector_index, %piece_offset, %sector_count, - %first_sector_index, "Incorrect piece offset" ); return None; @@ -210,7 +190,7 @@ where let sector_id = SectorId::new(public_key.hash(), sector_index); let sector_size = sector_size(pieces_in_sector); // TODO: Would be nicer to have list of plots here and just index it - let sector = &global_plot[sector_size * sector_offset..][..sector_size]; + let sector = &global_plot[sector_index as usize * sector_size..][..sector_size]; let piece = match reading::read_piece::( piece_offset, @@ -225,7 +205,6 @@ where %sector_index, %piece_offset, %sector_count, - %first_sector_index, %error, "Failed to read piece from sector" ); diff --git a/crates/subspace-farmer/src/single_disk_plot/plotting.rs b/crates/subspace-farmer/src/single_disk_plot/plotting.rs index eb0f34b0fb..542ba62fc9 100644 --- a/crates/subspace-farmer/src/single_disk_plot/plotting.rs +++ b/crates/subspace-farmer/src/single_disk_plot/plotting.rs @@ -45,12 +45,11 @@ pub enum PlottingError { #[allow(clippy::too_many_arguments)] pub(super) async fn plotting( public_key: PublicKey, - first_sector_index: SectorIndex, node_client: NC, pieces_in_sector: u16, sector_size: usize, sector_metadata_size: usize, - target_sector_count: usize, + target_sector_count: SectorIndex, mut metadata_header: PlotMetadataHeader, mut metadata_header_mmap: MmapMut, plot_file: Arc, @@ -69,22 +68,21 @@ where PosTable: Table, { // Some sectors may already be plotted, skip them - let sectors_offsets_left_to_plot = metadata_header.sector_count as usize..target_sector_count; + let sectors_indices_left_to_plot = metadata_header.sector_count..target_sector_count; // TODO: Concurrency - for sector_offset in sectors_offsets_left_to_plot { - let sector_index = sector_offset as u64 + first_sector_index; - trace!(%sector_offset, %sector_index, "Preparing to plot sector"); + for sector_index in sectors_indices_left_to_plot { + trace!(%sector_index, "Preparing to plot sector"); let mut sector = unsafe { MmapOptions::new() - .offset((sector_offset * sector_size) as u64) + .offset((sector_index as usize * sector_size) as u64) .len(sector_size) .map_mut(&*plot_file)? }; let mut sector_metadata = unsafe { MmapOptions::new() - .offset(RESERVED_PLOT_METADATA + (sector_offset * sector_metadata_size) as u64) + .offset(RESERVED_PLOT_METADATA + (sector_index * sector_metadata_size as u64)) .len(sector_metadata_size) .map_mut(&metadata_file)? }; @@ -92,7 +90,6 @@ where Ok(plotting_permit) => plotting_permit, Err(error) => { warn!( - %sector_offset, %sector_index, %error, "Semaphore was closed, interrupting plotting" @@ -101,7 +98,7 @@ where } }; - debug!(%sector_offset, %sector_index, "Plotting sector"); + debug!(%sector_index, "Plotting sector"); let farmer_app_info = node_client .farmer_app_info() @@ -110,7 +107,6 @@ where let plot_sector_fut = plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &piece_getter, PieceGetterRetryPolicy::Limited(PIECE_GETTER_RETRY_NUMBER.get()), @@ -138,13 +134,11 @@ where // Inform others that this sector is no longer being modified modifying_sector_index.write().take(); - info!(%sector_offset, %sector_index, "Sector plotted successfully"); + info!(%sector_index, "Sector plotted successfully"); - handlers.sector_plotted.call_simple(&( - sector_offset, - plotted_sector, - Arc::new(plotting_permit), - )); + handlers + .sector_plotted + .call_simple(&(plotted_sector, Arc::new(plotting_permit))); } Ok(()) diff --git a/test/subspace-test-client/src/lib.rs b/test/subspace-test-client/src/lib.rs index fb3543df97..89931cf800 100644 --- a/test/subspace-test-client/src/lib.rs +++ b/test/subspace-test-client/src/lib.rs @@ -226,7 +226,6 @@ where let history_size = HistorySize::from(SegmentIndex::ZERO); let mut sector = vec![0u8; sector_size(pieces_in_sector)]; let mut sector_metadata = vec![0u8; SectorMetadata::encoded_size()]; - let sector_offset = 0; let sector_index = 0; let public_key = PublicKey::from(keypair.public.to_bytes()); let farmer_protocol_info = FarmerProtocolInfo { @@ -242,7 +241,6 @@ where let plotted_sector = plot_sector::<_, PosTable>( &public_key, - sector_offset, sector_index, &archived_segment.pieces, PieceGetterRetryPolicy::default(),