@@ -539,21 +539,66 @@ type HandlerFn<A> = Arc<dyn Fn(&A) + Send + Sync + 'static>;
539539type Handler < A > = Bag < HandlerFn < A > , A > ;
540540
541541/// Details about sector currently being plotted
542- pub struct SectorPlottingDetails {
543- /// Sector index
544- pub sector_index : SectorIndex ,
545- /// Progress so far in % (not including this sector)
546- pub progress : f32 ,
547- /// Whether sector is being replotted
548- pub replotting : bool ,
549- /// Whether this is the last sector queued so far
550- pub last_queued : bool ,
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+ /// Wrote sector
564+ Wrote ( 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+
590+ /// Various sector updates
591+ #[ derive( Debug , Clone , Encode , Decode ) ]
592+ pub enum SectorUpdate {
593+ /// Sector is is being plotted
594+ Plotting ( SectorPlottingDetails ) ,
595+ /// Sector expiration information updated
596+ Expiration ( SectorExpirationDetails ) ,
551597}
552598
553599#[ derive( Default , Debug ) ]
554600struct Handlers {
555- sector_plotting : Handler < SectorPlottingDetails > ,
556- sector_plotted : Handler < ( PlottedSector , Option < PlottedSector > ) > ,
601+ sector_update : Handler < ( SectorIndex , SectorUpdate ) > ,
557602 solution : Handler < SolutionResponse > ,
558603 plot_audited : Handler < AuditEvent > ,
559604}
@@ -984,6 +1029,7 @@ impl SingleDiskFarm {
9841029 last_archived_segment_index : farmer_app_info. protocol_info . history_size . segment_index ( ) ,
9851030 min_sector_lifetime : farmer_app_info. protocol_info . min_sector_lifetime ,
9861031 node_client : node_client. clone ( ) ,
1032+ handlers : Arc :: clone ( & handlers) ,
9871033 sectors_metadata : Arc :: clone ( & sectors_metadata) ,
9881034 sectors_to_plot_sender,
9891035 initial_plotting_finished : farming_delay_sender,
@@ -1316,17 +1362,9 @@ impl SingleDiskFarm {
13161362 self . piece_reader . clone ( )
13171363 }
13181364
1319- /// Subscribe to sector plotting notification
1320- pub fn on_sector_plotting ( & self , callback : HandlerFn < SectorPlottingDetails > ) -> HandlerId {
1321- self . handlers . sector_plotting . add ( callback)
1322- }
1323-
1324- /// Subscribe to notification about plotted sectors
1325- pub fn on_sector_plotted (
1326- & self ,
1327- callback : HandlerFn < ( PlottedSector , Option < PlottedSector > ) > ,
1328- ) -> HandlerId {
1329- self . handlers . sector_plotted . add ( callback)
1365+ /// Subscribe to sector updates
1366+ pub fn on_sector_update ( & self , callback : HandlerFn < ( SectorIndex , SectorUpdate ) > ) -> HandlerId {
1367+ self . handlers . sector_update . add ( callback)
13301368 }
13311369
13321370 /// Subscribe to notification about audited plots
0 commit comments