Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add append_receipts function #8718

Merged
merged 14 commits into from
Jun 13, 2024
5 changes: 3 additions & 2 deletions crates/static-file/static-file/src/segments/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ impl<DB: Database> Segment<DB> for Receipts {
let mut receipts_cursor = provider.tx_ref().cursor_read::<tables::Receipts>()?;
let receipts_walker = receipts_cursor.walk_range(block_body_indices.tx_num_range())?;

let receipts = receipts_walker.collect::<Result<Vec<_>, _>>()?;
static_file_writer.append_receipts(receipts.into_iter().map(Ok))?;
static_file_writer.append_receipts(
receipts_walker.map(|result| result.map_err(ProviderError::from)),
)?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ impl StateWriter for BundleStateWithReceipts {
if let Some(static_file_producer) = &mut static_file_producer {
// Increment block on static file header.
static_file_producer.increment_block(StaticFileSegment::Receipts, block_number)?;
let receipts = receipts
.into_iter()
.enumerate()
.map(|(tx_idx, receipt)| {
(
first_tx_index + tx_idx as u64,
receipt.expect(
"receipt should not be filtered when saving to static files.",
),
)
})
.map(Ok);
let receipts = receipts.into_iter().enumerate().map(|(tx_idx, receipt)| {
Ok((
first_tx_index + tx_idx as u64,
receipt
.expect("receipt should not be filtered when saving to static files."),
))
});
static_file_producer.append_receipts(receipts)?;
} else if !receipts.is_empty() {
for (tx_idx, receipt) in receipts.into_iter().enumerate() {
Expand Down
22 changes: 22 additions & 0 deletions crates/storage/provider/src/providers/static_file/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ impl StaticFileProviderMetrics {
.record(duration.as_secs_f64());
}
}

pub(crate) fn record_segment_operations(
&self,
segment: StaticFileSegment,
operation: StaticFileProviderOperation,
count: u64,
duration: Option<Duration>,
) {
self.segment_operations
.get(&(segment, operation))
.expect("segment operation metrics should exist")
.calls_total
.increment(count);

if let Some(duration) = duration {
self.segment_operations
.get(&(segment, operation))
.expect("segment operation metrics should exist")
.write_duration_seconds
.record(duration.as_secs_f64() / count as f64);
}
shekhirin marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
Expand Down
7 changes: 4 additions & 3 deletions crates/storage/provider/src/providers/static_file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl StaticFileProviderRW {

// At this point receipts contains at least one receipt, so this would be overwritten.
let mut tx_number = 0;
let mut count = 0;
let mut count: u64 = 0;

for receipt_result in receipts_iter {
let (tx_num, receipt) = receipt_result?;
Expand All @@ -575,10 +575,11 @@ impl StaticFileProviderRW {
}

if let Some(metrics) = &self.metrics {
metrics.record_segment_operation(
metrics.record_segment_operations(
StaticFileSegment::Receipts,
StaticFileProviderOperation::AppendAverage,
Some(start.elapsed() / count as u32),
count,
Some(start.elapsed()),
);
}

Expand Down
Loading