Skip to content

Commit bc61fc5

Browse files
committed
starknet_committer,apollo_committer: add timers for fetch patricia paths
1 parent 9d6106e commit bc61fc5

3 files changed

Lines changed: 55 additions & 6 deletions

File tree

crates/apollo_committer/src/committer.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use async_trait::async_trait;
2121
use starknet_api::block::BlockNumber;
2222
use starknet_api::block_hash::state_diff_hash::calculate_state_diff_hash;
2323
use starknet_api::core::{GlobalRoot, StateDiffCommitment};
24-
use starknet_api::hash::PoseidonHash;
24+
use starknet_api::hash::{HashOutput, PoseidonHash};
2525
use starknet_api::state::ThinStateDiff;
2626
use starknet_committer::block_committer::commit::commit_block;
2727
use starknet_committer::block_committer::input::Input;
@@ -532,6 +532,9 @@ where
532532
.read_roots(ForestDB::InitialReadContext::create_empty())
533533
.await
534534
.map_err(|e| self.map_internal_error(e))?;
535+
let mut block_measurements = SingleBlockMeasurements::default();
536+
let pre_global_root = HashOutput(pre_roots.global_root().0);
537+
block_measurements.start_measurement(Action::FetchPatriciaPaths(pre_global_root));
535538
let mut patricia_proofs = self
536539
.forest_storage
537540
.fetch_patricia_witnesses(
@@ -547,8 +550,13 @@ where
547550
height,
548551
message: format!("pre-commit witness paths: {e:?}"),
549552
})?;
553+
block_measurements
554+
.attempt_to_stop_measurement(
555+
Action::FetchPatriciaPaths(pre_global_root),
556+
patricia_proofs.len(),
557+
)
558+
.ok();
550559

551-
let mut block_measurements = SingleBlockMeasurements::default();
552560
block_measurements.start_measurement(Action::EndToEnd);
553561
let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } =
554562
self.commit_state_diff(state_diff, &mut block_measurements).await?;
@@ -557,6 +565,8 @@ where
557565
let forest_updates = ForestDB::serialize_forest(&filled_forest)
558566
.map_err(|e| self.map_internal_error(e))?;
559567

568+
let post_global_root = HashOutput(post_roots.global_root().0);
569+
block_measurements.start_measurement(Action::FetchPatriciaPaths(post_global_root));
560570
let proof_after = self
561571
.forest_storage
562572
.fetch_patricia_witnesses(
@@ -572,15 +582,23 @@ where
572582
height,
573583
message: format!("post-commit witness paths: {e:?}"),
574584
})?;
585+
block_measurements
586+
.attempt_to_stop_measurement(
587+
Action::FetchPatriciaPaths(post_global_root),
588+
proof_after.len(),
589+
)
590+
.ok();
575591

576592
patricia_proofs.extend(proof_after);
577593

578594
let (metadata, next_offset) =
579595
commit_tip_metadata_bundle(height, global_root, state_diff_commitment);
580596
info!(
581-
"For block number {height}, writing filled forest and witnesses to storage \
582-
with metadata: {metadata:?}, delete {} nodes",
583-
deleted_nodes.len()
597+
"For block number {height}, writing filled forest and {witness_count} \
598+
witnesses to storage with metadata: {metadata:?}, delete \
599+
{deleted_nodes_count} nodes",
600+
witness_count = patricia_proofs.len(),
601+
deleted_nodes_count = deleted_nodes.len(),
584602
);
585603
block_measurements.start_measurement(Action::Write);
586604
let n_write_entries = self
@@ -638,7 +656,7 @@ impl ComponentStarter for ApolloCommitter {
638656
#[allow(clippy::as_conversions)]
639657
fn update_metrics(
640658
height: BlockNumber,
641-
BlockMeasurement { n_reads, n_writes, durations, modifications_counts }: &BlockMeasurement,
659+
BlockMeasurement { n_reads, n_writes, durations, modifications_counts, .. }: &BlockMeasurement,
642660
) {
643661
BLOCKS_COMMITTED.increment(1);
644662
TOTAL_BLOCK_DURATION.increment((durations.block * 1000.0) as u64);

crates/starknet_committer/src/block_committer/measurements_util.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use std::collections::HashMap;
12
use std::time::Instant;
23

4+
use starknet_api::hash::HashOutput;
35
use tracing::error;
46

57
#[derive(Debug)]
@@ -11,6 +13,7 @@ pub enum Action {
1113
Read,
1214
Compute,
1315
Write,
16+
FetchPatriciaPaths(HashOutput),
1417
}
1518

1619
#[derive(Default)]
@@ -19,6 +22,7 @@ pub struct BlockTimers {
1922
pub read_timer: Option<Instant>,
2023
pub compute_timer: Option<Instant>,
2124
pub writer_timer: Option<Instant>,
25+
pub fetch_patricia_paths_timers: HashMap<HashOutput, Option<Instant>>,
2226
}
2327

2428
impl BlockTimers {
@@ -28,6 +32,9 @@ impl BlockTimers {
2832
Action::Read => &mut self.read_timer,
2933
Action::Compute => &mut self.compute_timer,
3034
Action::Write => &mut self.writer_timer,
35+
Action::FetchPatriciaPaths(root) => {
36+
self.fetch_patricia_paths_timers.entry(*root).or_default()
37+
}
3138
}
3239
}
3340

@@ -107,12 +114,20 @@ impl BlockModificationsCounts {
107114
}
108115
}
109116

117+
#[derive(Clone, Debug, PartialEq)]
118+
pub struct FetchPatriciaPathsMeasurement {
119+
pub root: HashOutput,
120+
pub duration: f64,
121+
pub n_entries: usize,
122+
}
123+
110124
#[derive(Default, Clone)]
111125
pub struct BlockMeasurement {
112126
pub n_writes: usize,
113127
pub n_reads: usize,
114128
pub durations: BlockDurations,
115129
pub modifications_counts: BlockModificationsCounts,
130+
pub fetch_patricia_paths_measurements: Vec<FetchPatriciaPathsMeasurement>,
116131
}
117132

118133
impl BlockMeasurement {
@@ -137,6 +152,13 @@ impl BlockMeasurement {
137152
Action::EndToEnd => {
138153
self.durations.block = duration_in_seconds;
139154
}
155+
Action::FetchPatriciaPaths(root) => {
156+
self.fetch_patricia_paths_measurements.push(FetchPatriciaPathsMeasurement {
157+
root: *root,
158+
duration: duration_in_seconds,
159+
n_entries: entries_count,
160+
});
161+
}
140162
}
141163
}
142164
}

crates/starknet_committer/src/patricia_merkle_tree/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ impl StarknetForestProofs {
8585
}
8686
}
8787

88+
pub fn len(&self) -> usize {
89+
self.classes_trie_proof.len()
90+
+ self.contracts_trie_proof.nodes.len()
91+
+ self
92+
.contracts_trie_storage_proofs
93+
.values()
94+
.fold(0, |count, proofs| count + proofs.len())
95+
}
96+
8897
/// Bincode payload for the OS-input witness KV (structured proofs, round-trips with
8998
/// [`Self::deserialize`]).
9099
///

0 commit comments

Comments
 (0)