@@ -549,11 +549,15 @@ where
549549 // 4. Merge the two sets of patricia paths and write the result to the storage.
550550 // 5. Update the commitment offset and return the global root and the patricia proofs.
551551 CommitBlockHeightPlan :: CommitTip { state_diff_commitment } => {
552+ let mut block_measurements = SingleBlockMeasurements :: default ( ) ;
553+ block_measurements. start_measurement ( Action :: EndToEnd ) ;
554+
552555 let pre_roots = self
553556 . forest_storage
554557 . read_roots ( ForestDB :: InitialReadContext :: create_empty ( ) )
555558 . await
556559 . map_err ( |e| self . map_internal_error ( e) ) ?;
560+ block_measurements. start_measurement ( Action :: FetchWitnessesFirstPass ) ;
557561 let mut patricia_proofs = self
558562 . forest_storage
559563 . fetch_patricia_witnesses (
@@ -569,16 +573,21 @@ where
569573 height,
570574 message : format ! ( "pre-commit witness paths: {e:?}" ) ,
571575 } ) ?;
576+ block_measurements
577+ . attempt_to_stop_measurement (
578+ Action :: FetchWitnessesFirstPass ,
579+ patricia_proofs. get_nodes_count ( ) ,
580+ )
581+ . ok ( ) ;
572582
573- let mut block_measurements = SingleBlockMeasurements :: default ( ) ;
574- block_measurements. start_measurement ( Action :: EndToEnd ) ;
575583 let CommitStateDiffOutput { filled_forest, global_root, deleted_nodes } =
576584 self . commit_state_diff ( state_diff, & mut block_measurements) . await ?;
577585 let post_roots = filled_forest. state_roots ( ) ;
578586
579587 let forest_updates = ForestDB :: serialize_forest ( & filled_forest)
580588 . map_err ( |e| self . map_internal_error ( e) ) ?;
581589
590+ block_measurements. start_measurement ( Action :: FetchWitnessesSecondPass ) ;
582591 let proof_after = self
583592 . forest_storage
584593 . fetch_patricia_witnesses (
@@ -594,23 +603,24 @@ where
594603 height,
595604 message : format ! ( "post-commit witness paths: {e:?}" ) ,
596605 } ) ?;
606+ block_measurements
607+ . attempt_to_stop_measurement (
608+ Action :: FetchWitnessesSecondPass ,
609+ proof_after. get_nodes_count ( ) ,
610+ )
611+ . ok ( ) ;
597612
598613 patricia_proofs. extend ( proof_after) ;
599614
600615 let ( metadata, next_offset) =
601616 commit_tip_metadata_bundle ( height, global_root, state_diff_commitment) ;
602- let witness_node_count = patricia_proofs. classes_trie_proof . len ( )
603- + patricia_proofs. contracts_trie_proof . nodes . len ( )
604- + patricia_proofs. contracts_trie_proof . leaves . len ( )
605- + patricia_proofs
606- . contracts_trie_storage_proofs
607- . values ( )
608- . map ( |proof| proof. len ( ) )
609- . sum :: < usize > ( ) ;
617+
610618 info ! (
611- "For block number {height}, writing filled forest and {witness_node_count} \
612- witness nodes to storage with metadata: {metadata:?}, delete {} nodes",
613- deleted_nodes. len( )
619+ "For block number {height}, writing filled forest and {witness_count} \
620+ witnesses to storage with metadata: {metadata:?}, delete \
621+ {deleted_nodes_count} nodes",
622+ witness_count = patricia_proofs. get_nodes_count( ) ,
623+ deleted_nodes_count = deleted_nodes. len( ) ,
614624 ) ;
615625 block_measurements. start_measurement ( Action :: Write ) ;
616626 let n_write_entries = self
@@ -669,9 +679,17 @@ impl ComponentStarter for ApolloCommitter {
669679}
670680
671681#[ allow( clippy:: as_conversions) ]
682+ // TODO(Ariel): Consider adding fetch witnesses measurements.
672683fn update_metrics (
673684 height : BlockNumber ,
674- BlockMeasurement { n_reads, n_writes, durations, modifications_counts } : & BlockMeasurement ,
685+ BlockMeasurement {
686+ n_reads,
687+ n_writes,
688+ durations,
689+ modifications_counts,
690+ #[ cfg( feature = "os_input") ]
691+ fetched_witnesses_count,
692+ } : & BlockMeasurement ,
675693) {
676694 BLOCKS_COMMITTED . increment ( 1 ) ;
677695 TOTAL_BLOCK_DURATION . increment ( ( durations. block * 1000.0 ) as u64 ) ;
@@ -736,6 +754,8 @@ fn update_metrics(
736754 write_rate,
737755 modifications_counts,
738756 emptied_leaves_percentage,
757+ #[ cfg( feature = "os_input" ) ]
758+ * fetched_witnesses_count,
739759 ) ;
740760}
741761
@@ -749,12 +769,24 @@ fn log_block_measurements(
749769 write_rate : Option < f64 > ,
750770 modifications_counts : & BlockModificationsCounts ,
751771 emptied_leaves_percentage : Option < f64 > ,
772+ #[ cfg( feature = "os_input" ) ] fetched_witnesses_count : usize ,
752773) {
774+ #[ cfg( feature = "os_input" ) ]
775+ let witness_log = format ! (
776+ "witness fetch ms (pre-commit/post-commit): {:.0}/{:.0}, witness entries: {}" ,
777+ durations. fetch_witnesses_first_pass * 1000.0 ,
778+ durations. fetch_witnesses_second_pass * 1000.0 ,
779+ fetched_witnesses_count,
780+ ) ;
781+ #[ cfg( not( feature = "os_input" ) ) ]
782+ let witness_log = String :: new ( ) ;
783+
753784 debug ! (
754785 "Block {height} stats: durations in ms (total/read/compute/write): \
755786 {:.0}/{:.0}/{:.0}/{:.0}, total block duration per modification in µs: {}, rates in \
756787 entries/sec (read/compute/write): {}/{}/{}, modifications count \
757- (storage_tries/contracts_trie/classes_trie/emptied_storage_leaves): {}/{}/{}/{}{}",
788+ (storage_tries/contracts_trie/classes_trie/emptied_storage_leaves): {}/{}/{}/{}{}, \
789+ {witness_log}",
758790 durations. block * 1000.0 ,
759791 durations. read * 1000.0 ,
760792 durations. compute * 1000.0 ,
@@ -767,6 +799,7 @@ fn log_block_measurements(
767799 modifications_counts. contracts_trie,
768800 modifications_counts. classes_trie,
769801 modifications_counts. emptied_storage_leaves,
770- emptied_leaves_percentage. map_or( String :: new( ) , |p| format!( " ({p:.2}%)" ) )
802+ emptied_leaves_percentage. map_or( String :: new( ) , |p| format!( " ({p:.2}%)" ) ) ,
803+ witness_log = witness_log,
771804 ) ;
772805}
0 commit comments