Skip to content

Commit b3e1cb3

Browse files
committed
starknet_committer,apollo_committer: add timers for fetch patricia paths
1 parent 574e6b3 commit b3e1cb3

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

crates/apollo_committer/src/committer.rs

Lines changed: 25 additions & 14 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;
@@ -540,6 +540,9 @@ where
540540
.read_roots(ForestDB::InitialReadContext::create_empty())
541541
.await
542542
.map_err(|e| self.map_internal_error(e))?;
543+
let mut block_measurements = SingleBlockMeasurements::default();
544+
let pre_global_root = HashOutput(pre_roots.global_root().0);
545+
block_measurements.start_measurement(Action::FetchPatriciaPaths(pre_global_root));
543546
let mut patricia_proofs = self
544547
.forest_storage
545548
.fetch_patricia_witnesses(
@@ -555,8 +558,13 @@ where
555558
height,
556559
message: format!("pre-commit witness paths: {e:?}"),
557560
})?;
561+
block_measurements
562+
.attempt_to_stop_measurement(
563+
Action::FetchPatriciaPaths(pre_global_root),
564+
patricia_proofs.len(),
565+
)
566+
.ok();
558567

559-
let mut block_measurements = SingleBlockMeasurements::default();
560568
block_measurements.start_measurement(Action::EndToEnd);
561569
let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } =
562570
self.commit_state_diff(state_diff, &mut block_measurements).await?;
@@ -565,6 +573,8 @@ where
565573
let forest_updates = ForestDB::serialize_forest(&filled_forest)
566574
.map_err(|e| self.map_internal_error(e))?;
567575

576+
let post_global_root = HashOutput(post_roots.global_root().0);
577+
block_measurements.start_measurement(Action::FetchPatriciaPaths(post_global_root));
568578
let proof_after = self
569579
.forest_storage
570580
.fetch_patricia_witnesses(
@@ -580,23 +590,24 @@ where
580590
height,
581591
message: format!("post-commit witness paths: {e:?}"),
582592
})?;
593+
block_measurements
594+
.attempt_to_stop_measurement(
595+
Action::FetchPatriciaPaths(post_global_root),
596+
proof_after.len(),
597+
)
598+
.ok();
583599

584600
patricia_proofs.extend(proof_after);
585601

586602
let (metadata, next_offset) =
587603
commit_tip_metadata_bundle(height, global_root, state_diff_commitment);
588-
let witness_node_count = patricia_proofs.classes_trie_proof.len()
589-
+ patricia_proofs.contracts_trie_proof.nodes.len()
590-
+ patricia_proofs.contracts_trie_proof.leaves.len()
591-
+ patricia_proofs
592-
.contracts_trie_storage_proofs
593-
.values()
594-
.map(|proof| proof.len())
595-
.sum::<usize>();
604+
596605
info!(
597-
"For block number {height}, writing filled forest and {witness_node_count} \
598-
witness nodes to storage with metadata: {metadata:?}, delete {} nodes",
599-
deleted_nodes.len()
606+
"For block number {height}, writing filled forest and {witness_count} \
607+
witnesses to storage with metadata: {metadata:?}, delete \
608+
{deleted_nodes_count} nodes",
609+
witness_count = patricia_proofs.len(),
610+
deleted_nodes_count = deleted_nodes.len(),
600611
);
601612
block_measurements.start_measurement(Action::Write);
602613
let n_write_entries = self
@@ -657,7 +668,7 @@ impl ComponentStarter for ApolloCommitter {
657668
#[allow(clippy::as_conversions)]
658669
fn update_metrics(
659670
height: BlockNumber,
660-
BlockMeasurement { n_reads, n_writes, durations, modifications_counts }: &BlockMeasurement,
671+
BlockMeasurement { n_reads, n_writes, durations, modifications_counts, .. }: &BlockMeasurement,
661672
) {
662673
BLOCKS_COMMITTED.increment(1);
663674
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
@@ -58,6 +58,15 @@ impl StarknetForestProofs {
5858
self.contracts_trie_storage_proofs.entry(address).or_default().extend(proof);
5959
}
6060
}
61+
62+
pub fn len(&self) -> usize {
63+
self.classes_trie_proof.len()
64+
+ self.contracts_trie_proof.nodes.len()
65+
+ self
66+
.contracts_trie_storage_proofs
67+
.values()
68+
.fold(0, |count, proofs| count + proofs.len())
69+
}
6170
}
6271

6372
pub struct RootHashes {

0 commit comments

Comments
 (0)