Skip to content

Commit 8450200

Browse files
committed
Expose information about plot updates (downloading/encoding/writing)
1 parent e0fe46d commit 8450200

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ where
661661
if let SectorUpdate::Plotting(SectorPlottingDetails::Finished {
662662
plotted_sector,
663663
old_plotted_sector,
664+
..
664665
}) = sector_state
665666
{
666667
on_plotted_sector_callback(plotted_sector, old_plotted_sector);

crates/subspace-farmer/src/single_disk_farm.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,26 @@ pub enum SectorPlottingDetails {
550550
/// Whether this is the last sector queued so far
551551
last_queued: bool,
552552
},
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),
553565
/// Finished plotting
554566
Finished {
555567
/// Information about plotted sector
556568
plotted_sector: PlottedSector,
557569
/// Information about old plotted sector that was replaced
558570
old_plotted_sector: Option<PlottedSector>,
571+
/// How much time it took to plot a sector
572+
time: Duration,
559573
},
560574
}
561575

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

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::ops::Range;
1919
use std::pin::pin;
2020
use std::sync::atomic::Ordering;
2121
use std::sync::Arc;
22-
use std::time::Duration;
22+
use std::time::{Duration, Instant};
2323
use subspace_core_primitives::crypto::kzg::Kzg;
2424
use subspace_core_primitives::{
2525
Blake3Hash, HistorySize, PieceOffset, PublicKey, SectorId, SectorIndex, SegmentHeader,
@@ -193,6 +193,8 @@ where
193193
.sector_update
194194
.call_simple(&(sector_index, sector_state));
195195

196+
let start = Instant::now();
197+
196198
// This `loop` is a workaround for edge-case in local setup if expiration is configured to
197199
// 1. In that scenario we get replotting notification essentially straight from block import
198200
// pipeline of the node, before block is imported. This can result in subsequent request for
@@ -231,6 +233,13 @@ where
231233
.await
232234
.map_err(plotting::PlottingError::from)?;
233235

236+
handlers.sector_update.call_simple(&(
237+
sector_index,
238+
SectorUpdate::Plotting(SectorPlottingDetails::Downloading),
239+
));
240+
241+
let start = Instant::now();
242+
234243
let downloaded_sector_fut = download_sector(DownloadSectorOptions {
235244
public_key: &public_key,
236245
sector_index,
@@ -243,13 +252,21 @@ where
243252
pieces_in_sector,
244253
});
245254

246-
(downloading_permit, downloaded_sector_fut.await?)
255+
let downloaded_sector = downloaded_sector_fut.await?;
256+
257+
handlers.sector_update.call_simple(&(
258+
sector_index,
259+
SectorUpdate::Plotting(SectorPlottingDetails::Downloaded(start.elapsed())),
260+
));
261+
262+
(downloading_permit, downloaded_sector)
247263
};
248264

249265
// Initiate downloading of pieces for the next segment index if already known
250266
if let Some(sector_index) = next_segment_index_hint {
251267
let piece_getter = piece_getter.clone();
252268
let downloading_semaphore = Arc::clone(&downloading_semaphore);
269+
let handlers = Arc::clone(&handlers);
253270
let kzg = kzg.clone();
254271

255272
maybe_next_downloaded_sector_fut.replace(AsyncJoinOnDrop::new(
@@ -260,6 +277,13 @@ where
260277
.await
261278
.map_err(plotting::PlottingError::from)?;
262279

280+
handlers.sector_update.call_simple(&(
281+
sector_index,
282+
SectorUpdate::Plotting(SectorPlottingDetails::Downloading),
283+
));
284+
285+
let start = Instant::now();
286+
263287
let downloaded_sector_fut = download_sector(DownloadSectorOptions {
264288
public_key: &public_key,
265289
sector_index,
@@ -272,7 +296,16 @@ where
272296
pieces_in_sector,
273297
});
274298

275-
Ok((downloading_permit, downloaded_sector_fut.await?))
299+
let downloaded_sector = downloaded_sector_fut.await?;
300+
301+
handlers.sector_update.call_simple(&(
302+
sector_index,
303+
SectorUpdate::Plotting(SectorPlottingDetails::Downloaded(
304+
start.elapsed(),
305+
)),
306+
));
307+
308+
Ok((downloading_permit, downloaded_sector))
276309
}
277310
.in_current_span(),
278311
),
@@ -293,6 +326,13 @@ where
293326
let mut sector = Vec::new();
294327
let mut sector_metadata = Vec::new();
295328

329+
handlers.sector_update.call_simple(&(
330+
sector_index,
331+
SectorUpdate::Plotting(SectorPlottingDetails::Encoding),
332+
));
333+
334+
let start = Instant::now();
335+
296336
let plotted_sector = {
297337
let plot_sector_fut = pin!(encode_sector::<PosTable>(
298338
downloaded_sector,
@@ -318,6 +358,11 @@ where
318358
})?
319359
};
320360

361+
handlers.sector_update.call_simple(&(
362+
sector_index,
363+
SectorUpdate::Plotting(SectorPlottingDetails::Encoded(start.elapsed())),
364+
));
365+
321366
Ok((sector, sector_metadata, table_generator, plotted_sector))
322367
})
323368
};
@@ -341,11 +386,25 @@ where
341386
plotting_result?
342387
};
343388

344-
plot_file.write_all_at(&sector, (sector_index as usize * sector_size) as u64)?;
345-
metadata_file.write_all_at(
346-
&sector_metadata,
347-
RESERVED_PLOT_METADATA + (u64::from(sector_index) * sector_metadata_size as u64),
348-
)?;
389+
{
390+
handlers.sector_update.call_simple(&(
391+
sector_index,
392+
SectorUpdate::Plotting(SectorPlottingDetails::Writing),
393+
));
394+
395+
let start = Instant::now();
396+
397+
plot_file.write_all_at(&sector, (sector_index as usize * sector_size) as u64)?;
398+
metadata_file.write_all_at(
399+
&sector_metadata,
400+
RESERVED_PLOT_METADATA + (u64::from(sector_index) * sector_metadata_size as u64),
401+
)?;
402+
403+
handlers.sector_update.call_simple(&(
404+
sector_index,
405+
SectorUpdate::Plotting(SectorPlottingDetails::Wrote(start.elapsed())),
406+
));
407+
}
349408

350409
if sector_index + 1 > metadata_header.plotted_sector_count {
351410
metadata_header.plotted_sector_count = sector_index + 1;
@@ -406,6 +465,7 @@ where
406465
let sector_state = SectorUpdate::Plotting(SectorPlottingDetails::Finished {
407466
plotted_sector,
408467
old_plotted_sector: maybe_old_plotted_sector,
468+
time: start.elapsed(),
409469
});
410470
handlers
411471
.sector_update

0 commit comments

Comments
 (0)