Skip to content

Commit 65867e6

Browse files
committed
Move plotting-specific data structures into corresponding module
1 parent eff2c27 commit 65867e6

File tree

2 files changed

+54
-53
lines changed

2 files changed

+54
-53
lines changed

crates/subspace-farmer/src/single_disk_farm.rs

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use crate::single_disk_farm::farming::{
1313
};
1414
use crate::single_disk_farm::piece_cache::{DiskPieceCache, DiskPieceCacheError};
1515
use crate::single_disk_farm::piece_reader::PieceReader;
16-
pub use crate::single_disk_farm::plotting::PlottingError;
1716
use crate::single_disk_farm::plotting::{
1817
plotting, plotting_scheduler, PlottingOptions, PlottingSchedulerOptions,
1918
};
19+
pub use crate::single_disk_farm::plotting::{
20+
PlottingError, SectorExpirationDetails, SectorPlottingDetails,
21+
};
2022
use crate::thread_pool_manager::PlottingThreadPoolManager;
2123
use crate::utils::{tokio_rayon_spawn_handler, AsyncJoinOnDrop};
2224
use crate::KNOWN_PEERS_CACHE_SIZE;
@@ -538,55 +540,6 @@ type BackgroundTask = Pin<Box<dyn Future<Output = Result<(), BackgroundTaskError
538540
type HandlerFn<A> = Arc<dyn Fn(&A) + Send + Sync + 'static>;
539541
type Handler<A> = Bag<HandlerFn<A>, A>;
540542

541-
/// Details about sector currently being plotted
542-
#[derive(Debug, Clone, Encode, Decode)]
543-
pub enum SectorPlottingDetails {
544-
/// Starting plotting of a sector
545-
Starting {
546-
/// Progress so far in % (not including this sector)
547-
progress: f32,
548-
/// Whether sector is being replotted
549-
replotting: bool,
550-
/// Whether this is the last sector queued so far
551-
last_queued: bool,
552-
},
553-
/// Downloading sector pieces
554-
Downloading,
555-
/// Downloaded sector pieces
556-
Downloaded(Duration),
557-
/// Encoding sector pieces
558-
Encoding,
559-
/// Encoded sector pieces
560-
Encoded(Duration),
561-
/// Writing sector
562-
Writing,
563-
/// Written sector
564-
Written(Duration),
565-
/// Finished plotting
566-
Finished {
567-
/// Information about plotted sector
568-
plotted_sector: PlottedSector,
569-
/// Information about old plotted sector that was replaced
570-
old_plotted_sector: Option<PlottedSector>,
571-
/// How much time it took to plot a sector
572-
time: Duration,
573-
},
574-
}
575-
576-
/// Details about sector expiration
577-
#[derive(Debug, Clone, Encode, Decode)]
578-
pub enum SectorExpirationDetails {
579-
/// Sector expiration became known
580-
Determined {
581-
/// Segment index at which sector expires
582-
expires_at: SegmentIndex,
583-
},
584-
/// Sector will expire at the next segment index and should be replotted
585-
AboutToExpire,
586-
/// Sector already expired
587-
Expired,
588-
}
589-
590543
/// Various sector updates
591544
#[derive(Debug, Clone, Encode, Decode)]
592545
pub enum SectorUpdate {

crates/subspace-farmer/src/single_disk_farm/plotting.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::single_disk_farm::{
2-
BackgroundTaskError, Handlers, PlotMetadataHeader, SectorExpirationDetails,
3-
SectorPlottingDetails, SectorUpdate, RESERVED_PLOT_METADATA,
2+
BackgroundTaskError, Handlers, PlotMetadataHeader, SectorUpdate, RESERVED_PLOT_METADATA,
43
};
54
use crate::thread_pool_manager::PlottingThreadPoolManager;
65
use crate::utils::AsyncJoinOnDrop;
@@ -10,7 +9,7 @@ use atomic::Atomic;
109
use futures::channel::{mpsc, oneshot};
1110
use futures::{select, FutureExt, SinkExt, StreamExt};
1211
use lru::LruCache;
13-
use parity_scale_codec::Encode;
12+
use parity_scale_codec::{Decode, Encode};
1413
use std::collections::HashMap;
1514
use std::fs::File;
1615
use std::io;
@@ -46,6 +45,55 @@ const ARCHIVED_SEGMENTS_CACHE_SIZE: NonZeroUsize = NonZeroUsize::new(1000).expec
4645
/// Get piece retry attempts number.
4746
const PIECE_GETTER_RETRY_NUMBER: NonZeroU16 = NonZeroU16::new(4).expect("Not zero; qed");
4847

48+
/// Details about sector currently being plotted
49+
#[derive(Debug, Clone, Encode, Decode)]
50+
pub enum SectorPlottingDetails {
51+
/// Starting plotting of a sector
52+
Starting {
53+
/// Progress so far in % (not including this sector)
54+
progress: f32,
55+
/// Whether sector is being replotted
56+
replotting: bool,
57+
/// Whether this is the last sector queued so far
58+
last_queued: bool,
59+
},
60+
/// Downloading sector pieces
61+
Downloading,
62+
/// Downloaded sector pieces
63+
Downloaded(Duration),
64+
/// Encoding sector pieces
65+
Encoding,
66+
/// Encoded sector pieces
67+
Encoded(Duration),
68+
/// Writing sector
69+
Writing,
70+
/// Written sector
71+
Written(Duration),
72+
/// Finished plotting
73+
Finished {
74+
/// Information about plotted sector
75+
plotted_sector: PlottedSector,
76+
/// Information about old plotted sector that was replaced
77+
old_plotted_sector: Option<PlottedSector>,
78+
/// How much time it took to plot a sector
79+
time: Duration,
80+
},
81+
}
82+
83+
/// Details about sector expiration
84+
#[derive(Debug, Clone, Encode, Decode)]
85+
pub enum SectorExpirationDetails {
86+
/// Sector expiration became known
87+
Determined {
88+
/// Segment index at which sector expires
89+
expires_at: SegmentIndex,
90+
},
91+
/// Sector will expire at the next segment index and should be replotted
92+
AboutToExpire,
93+
/// Sector already expired
94+
Expired,
95+
}
96+
4997
pub(super) struct SectorToPlot {
5098
sector_index: SectorIndex,
5199
/// Progress so far in % (not including this sector)

0 commit comments

Comments
 (0)