Skip to content

Commit 1a45992

Browse files
committed
Add sector expiration updates
1 parent 3cdc6b3 commit 1a45992

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

crates/subspace-farmer/src/single_disk_farm.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,27 @@ pub enum SectorPlottingDetails {
573573
},
574574
}
575575

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+
576590
/// Various sector updates
577591
#[derive(Debug, Clone, Encode, Decode)]
578592
pub enum SectorUpdate {
579593
/// Sector is is being plotted
580594
Plotting(SectorPlottingDetails),
595+
/// Sector expiration information updated
596+
Expiration(SectorExpirationDetails),
581597
}
582598

583599
#[derive(Default, Debug)]
@@ -1013,6 +1029,7 @@ impl SingleDiskFarm {
10131029
last_archived_segment_index: farmer_app_info.protocol_info.history_size.segment_index(),
10141030
min_sector_lifetime: farmer_app_info.protocol_info.min_sector_lifetime,
10151031
node_client: node_client.clone(),
1032+
handlers: Arc::clone(&handlers),
10161033
sectors_metadata: Arc::clone(&sectors_metadata),
10171034
sectors_to_plot_sender,
10181035
initial_plotting_finished: farming_delay_sender,

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::single_disk_farm::{
2-
BackgroundTaskError, Handlers, PlotMetadataHeader, SectorPlottingDetails, SectorUpdate,
3-
RESERVED_PLOT_METADATA,
2+
BackgroundTaskError, Handlers, PlotMetadataHeader, SectorExpirationDetails,
3+
SectorPlottingDetails, SectorUpdate, RESERVED_PLOT_METADATA,
44
};
55
use crate::thread_pool_manager::PlottingThreadPoolManager;
66
use crate::utils::AsyncJoinOnDrop;
@@ -482,6 +482,7 @@ pub(super) struct PlottingSchedulerOptions<NC> {
482482
pub(super) last_archived_segment_index: SegmentIndex,
483483
pub(super) min_sector_lifetime: HistorySize,
484484
pub(super) node_client: NC,
485+
pub(super) handlers: Arc<Handlers>,
485486
pub(super) sectors_metadata: Arc<RwLock<Vec<SectorMetadataChecksummed>>>,
486487
pub(super) sectors_to_plot_sender: mpsc::Sender<SectorToPlot>,
487488
pub(super) initial_plotting_finished: Option<oneshot::Sender<()>>,
@@ -503,6 +504,7 @@ where
503504
last_archived_segment_index,
504505
min_sector_lifetime,
505506
node_client,
507+
handlers,
506508
sectors_metadata,
507509
sectors_to_plot_sender,
508510
initial_plotting_finished,
@@ -550,6 +552,7 @@ where
550552
target_sector_count,
551553
min_sector_lifetime,
552554
&node_client,
555+
&handlers,
553556
sectors_metadata,
554557
&last_archived_segment,
555558
archived_segments_receiver,
@@ -695,6 +698,7 @@ async fn send_plotting_notifications<NC>(
695698
target_sector_count: SectorIndex,
696699
min_sector_lifetime: HistorySize,
697700
node_client: &NC,
701+
handlers: &Handlers,
698702
sectors_metadata: Arc<RwLock<Vec<SectorMetadataChecksummed>>>,
699703
last_archived_segment: &Atomic<SegmentHeader>,
700704
mut archived_segments_receiver: mpsc::Receiver<()>,
@@ -771,6 +775,18 @@ where
771775
%expires_at,
772776
"Sector expires soon #1, scheduling replotting"
773777
);
778+
779+
handlers.sector_update.call_simple(&(
780+
sector_index,
781+
SectorUpdate::Expiration(
782+
if expires_at <= archived_segment_header.segment_index() {
783+
SectorExpirationDetails::Expired
784+
} else {
785+
SectorExpirationDetails::AboutToExpire
786+
},
787+
),
788+
));
789+
774790
// Time to replot
775791
sectors_to_replot.push(SectorToReplot {
776792
sector_index,
@@ -827,24 +843,35 @@ where
827843
metadata; qed",
828844
);
829845

846+
let expires_at = expiration_history_size.segment_index();
847+
830848
trace!(
831849
%sector_index,
832850
%history_size,
833-
sector_expire_at = %expiration_history_size.segment_index(),
851+
sector_expire_at = %expires_at,
834852
"Determined sector expiration segment index"
835853
);
836854
// +1 means we will start replotting a bit before it actually expires to avoid
837855
// storing expired sectors
838-
if expiration_history_size.segment_index()
839-
<= (archived_segment_header.segment_index() + SegmentIndex::ONE)
840-
{
841-
let expires_at = expiration_history_size.segment_index();
856+
if expires_at <= (archived_segment_header.segment_index() + SegmentIndex::ONE) {
842857
debug!(
843858
%sector_index,
844859
%history_size,
845860
%expires_at,
846861
"Sector expires soon #2, scheduling replotting"
847862
);
863+
864+
handlers.sector_update.call_simple(&(
865+
sector_index,
866+
SectorUpdate::Expiration(
867+
if expires_at <= archived_segment_header.segment_index() {
868+
SectorExpirationDetails::Expired
869+
} else {
870+
SectorExpirationDetails::AboutToExpire
871+
},
872+
),
873+
));
874+
848875
// Time to replot
849876
sectors_to_replot.push(SectorToReplot {
850877
sector_index,
@@ -854,12 +881,19 @@ where
854881
trace!(
855882
%sector_index,
856883
%history_size,
857-
sector_expire_at = %expiration_history_size.segment_index(),
884+
sector_expire_at = %expires_at,
858885
"Sector expires later, remembering sector expiration"
859886
);
887+
888+
handlers.sector_update.call_simple(&(
889+
sector_index,
890+
SectorUpdate::Expiration(SectorExpirationDetails::Determined {
891+
expires_at,
892+
}),
893+
));
894+
860895
// Store expiration so we don't have to recalculate it later
861-
sectors_expire_at
862-
.insert(sector_index, expiration_history_size.segment_index());
896+
sectors_expire_at.insert(sector_index, expires_at);
863897
}
864898
}
865899
}

0 commit comments

Comments
 (0)