@@ -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. len ( ) ,
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. len ( ) ,
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. len( ) ,
623+ deleted_nodes_count = deleted_nodes. len( ) ,
614624 ) ;
615625 block_measurements. start_measurement ( Action :: Write ) ;
616626 let n_write_entries = self
@@ -669,9 +679,16 @@ impl ComponentStarter for ApolloCommitter {
669679}
670680
671681#[ allow( clippy:: as_conversions) ]
682+ // TODO: 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+ fetched_witnesses_count,
691+ } : & BlockMeasurement ,
675692) {
676693 BLOCKS_COMMITTED . increment ( 1 ) ;
677694 TOTAL_BLOCK_DURATION . increment ( ( durations. block * 1000.0 ) as u64 ) ;
@@ -736,6 +753,7 @@ fn update_metrics(
736753 write_rate,
737754 modifications_counts,
738755 emptied_leaves_percentage,
756+ * fetched_witnesses_count,
739757 ) ;
740758}
741759
@@ -749,12 +767,24 @@ fn log_block_measurements(
749767 write_rate : Option < f64 > ,
750768 modifications_counts : & BlockModificationsCounts ,
751769 emptied_leaves_percentage : Option < f64 > ,
770+ fetched_witnesses_count : usize ,
752771) {
772+ #[ cfg( feature = "os_input" ) ]
773+ let witness_log = format ! (
774+ "witness fetch ms (pre-commit/post-commit): {:.0}/{:.0}, witness entries: {}" ,
775+ durations. fetch_witnesses_first_pass * 1000.0 ,
776+ durations. fetch_witnesses_second_pass * 1000.0 ,
777+ fetched_witnesses_count,
778+ ) ;
779+ #[ cfg( not( feature = "os_input" ) ) ]
780+ let witness_log = String :: new ( ) ;
781+
753782 debug ! (
754783 "Block {height} stats: durations in ms (total/read/compute/write): \
755784 {:.0}/{:.0}/{:.0}/{:.0}, total block duration per modification in µs: {}, rates in \
756785 entries/sec (read/compute/write): {}/{}/{}, modifications count \
757- (storage_tries/contracts_trie/classes_trie/emptied_storage_leaves): {}/{}/{}/{}{}",
786+ (storage_tries/contracts_trie/classes_trie/emptied_storage_leaves): {}/{}/{}/{}{}, \
787+ {witness_log}",
758788 durations. block * 1000.0 ,
759789 durations. read * 1000.0 ,
760790 durations. compute * 1000.0 ,
@@ -767,6 +797,7 @@ fn log_block_measurements(
767797 modifications_counts. contracts_trie,
768798 modifications_counts. classes_trie,
769799 modifications_counts. emptied_storage_leaves,
770- emptied_leaves_percentage. map_or( String :: new( ) , |p| format!( " ({p:.2}%)" ) )
800+ emptied_leaves_percentage. map_or( String :: new( ) , |p| format!( " ({p:.2}%)" ) ) ,
801+ witness_log = witness_log,
771802 ) ;
772803}
0 commit comments