@@ -35,6 +35,7 @@ use linera_views::{
3535 views:: { ClonableView , CryptoHashView , RootView , View } ,
3636} ;
3737use serde:: { Deserialize , Serialize } ;
38+ use tracing:: instrument;
3839
3940use crate :: {
4041 block:: { Block , ConfirmedBlock } ,
@@ -309,6 +310,12 @@ pub struct ChainTipState {
309310impl ChainTipState {
310311 /// Checks that the proposed block is suitable, i.e. at the expected height and with the
311312 /// expected parent.
313+ #[ instrument( target = "telemetry_only" , skip_all, fields(
314+ next_block_height = %self . next_block_height,
315+ block_hash = ?self . block_hash,
316+ proposed_height = %new_block. height,
317+ proposed_previous_hash = ?new_block. previous_block_hash
318+ ) ) ]
312319 pub fn verify_block_chaining ( & self , new_block : & ProposedBlock ) -> Result < ( ) , ChainError > {
313320 ensure ! (
314321 new_block. height == self . next_block_height,
@@ -326,6 +333,10 @@ impl ChainTipState {
326333
327334 /// Returns `true` if the validated block's height is below the tip height. Returns an error if
328335 /// it is higher than the tip.
336+ #[ instrument( target = "telemetry_only" , skip_all, fields(
337+ next_block_height = %self . next_block_height,
338+ height = %height
339+ ) ) ]
329340 pub fn already_validated_block ( & self , height : BlockHeight ) -> Result < bool , ChainError > {
330341 ensure ! (
331342 self . next_block_height >= height,
@@ -337,6 +348,10 @@ impl ChainTipState {
337348 }
338349
339350 /// Checks if the measurement counters would be valid.
351+ #[ instrument( target = "telemetry_only" , skip_all, fields(
352+ next_block_height = %self . next_block_height,
353+ num_transactions = %transactions. len( )
354+ ) ) ]
340355 pub fn update_counters (
341356 & mut self ,
342357 transactions : & [ Transaction ] ,
@@ -391,6 +406,10 @@ where
391406 self . context ( ) . extra ( ) . chain_id ( )
392407 }
393408
409+ #[ instrument( target = "telemetry_only" , skip_all, fields(
410+ chain_id = %self . chain_id( ) ,
411+ next_block_height = %self . tip_state. get( ) . next_block_height
412+ ) ) ]
394413 pub async fn query_application (
395414 & mut self ,
396415 local_time : Timestamp ,
@@ -408,6 +427,10 @@ where
408427 . with_execution_context ( ChainExecutionContext :: Query )
409428 }
410429
430+ #[ instrument( target = "telemetry_only" , skip_all, fields(
431+ chain_id = %self . chain_id( ) ,
432+ application_id = %application_id
433+ ) ) ]
411434 pub async fn describe_application (
412435 & mut self ,
413436 application_id : ApplicationId ,
@@ -419,6 +442,11 @@ where
419442 . with_execution_context ( ChainExecutionContext :: DescribeApplication )
420443 }
421444
445+ #[ instrument( target = "telemetry_only" , skip_all, fields(
446+ chain_id = %self . chain_id( ) ,
447+ target = %target,
448+ height = %height
449+ ) ) ]
422450 pub async fn mark_messages_as_received (
423451 & mut self ,
424452 target : & ChainId ,
@@ -459,6 +487,10 @@ where
459487
460488 /// Returns true if there are no more outgoing messages in flight up to the given
461489 /// block height.
490+ #[ instrument( target = "telemetry_only" , skip_all, fields(
491+ chain_id = %self . chain_id( ) ,
492+ height = %height
493+ ) ) ]
462494 pub fn all_messages_delivered_up_to ( & self , height : BlockHeight ) -> bool {
463495 tracing:: debug!(
464496 "Messages left in {:.8}'s outbox: {:?}" ,
@@ -478,6 +510,10 @@ where
478510 }
479511
480512 /// Invariant for the states of active chains.
513+ #[ instrument( target = "telemetry_only" , skip_all, fields(
514+ chain_id = %self . chain_id( ) ,
515+ local_time = %local_time
516+ ) ) ]
481517 pub async fn ensure_is_active ( & mut self , local_time : Timestamp ) -> Result < ( ) , ChainError > {
482518 // Initialize ourselves.
483519 if self
@@ -506,6 +542,9 @@ where
506542
507543 /// Verifies that this chain is up-to-date and all the messages executed ahead of time
508544 /// have been properly received by now.
545+ #[ instrument( target = "telemetry_only" , skip_all, fields(
546+ chain_id = %self . chain_id( )
547+ ) ) ]
509548 pub async fn validate_incoming_bundles ( & self ) -> Result < ( ) , ChainError > {
510549 let chain_id = self . chain_id ( ) ;
511550 let pairs = self . inboxes . try_load_all_entries ( ) . await ?;
@@ -526,6 +565,10 @@ where
526565 Ok ( ( ) )
527566 }
528567
568+ #[ instrument( target = "telemetry_only" , skip_all, fields(
569+ chain_id = %self . chain_id( ) ,
570+ origin = %origin
571+ ) ) ]
529572 pub async fn next_block_height_to_receive (
530573 & self ,
531574 origin : & ChainId ,
@@ -540,13 +583,21 @@ where
540583 /// Returns the height of the highest block we have, plus one. Includes preprocessed blocks.
541584 ///
542585 /// The "+ 1" is so that it can be used in the same places as `next_block_height`.
586+ #[ instrument( target = "telemetry_only" , skip_all, fields(
587+ chain_id = %self . chain_id( ) ,
588+ next_block_height = %self . tip_state. get( ) . next_block_height
589+ ) ) ]
543590 pub async fn next_height_to_preprocess ( & self ) -> Result < BlockHeight , ChainError > {
544591 if let Some ( height) = self . preprocessed_blocks . indices ( ) . await ?. last ( ) {
545592 return Ok ( height. saturating_add ( BlockHeight ( 1 ) ) ) ;
546593 }
547594 Ok ( self . tip_state . get ( ) . next_block_height )
548595 }
549596
597+ #[ instrument( target = "telemetry_only" , skip_all, fields(
598+ chain_id = %self . chain_id( ) ,
599+ origin = %origin
600+ ) ) ]
550601 pub async fn last_anticipated_block_height (
551602 & self ,
552603 origin : & ChainId ,
@@ -567,6 +618,11 @@ where
567618 /// round timeouts.
568619 ///
569620 /// Returns `true` if incoming `Subscribe` messages created new outbox entries.
621+ #[ instrument( target = "telemetry_only" , skip_all, fields(
622+ chain_id = %self . chain_id( ) ,
623+ origin = %origin,
624+ bundle_height = %bundle. height
625+ ) ) ]
570626 pub async fn receive_message_bundle (
571627 & mut self ,
572628 origin : & ChainId ,
@@ -630,6 +686,10 @@ where
630686 }
631687
632688 /// Updates the `received_log` trackers.
689+ #[ instrument( target = "telemetry_only" , skip_all, fields(
690+ chain_id = %self . chain_id( ) ,
691+ num_trackers = %new_trackers. len( )
692+ ) ) ]
633693 pub fn update_received_certificate_trackers (
634694 & mut self ,
635695 new_trackers : BTreeMap < ValidatorPublicKey , u64 > ,
@@ -649,6 +709,9 @@ where
649709 }
650710 }
651711
712+ #[ instrument( target = "telemetry_only" , skip_all, fields(
713+ chain_id = %self . chain_id( )
714+ ) ) ]
652715 pub fn current_committee ( & self ) -> Result < ( Epoch , & Committee ) , ChainError > {
653716 self . execution_state
654717 . system
@@ -661,6 +724,10 @@ where
661724 }
662725
663726 /// Removes the incoming message bundles in the block from the inboxes.
727+ #[ instrument( target = "telemetry_only" , skip_all, fields(
728+ chain_id = %self . chain_id( ) ,
729+ timestamp = %timestamp
730+ ) ) ]
664731 pub async fn remove_bundles_from_inboxes (
665732 & mut self ,
666733 timestamp : Timestamp ,
@@ -739,6 +806,10 @@ where
739806 }
740807
741808 /// Returns the outboxes for the given targets, or an error if any of them are missing.
809+ #[ instrument( target = "telemetry_only" , skip_all, fields(
810+ chain_id = %self . chain_id( ) ,
811+ num_targets = %targets. len( )
812+ ) ) ]
742813 pub async fn load_outboxes (
743814 & self ,
744815 targets : & [ ChainId ] ,
@@ -750,6 +821,10 @@ where
750821
751822 /// Executes a block: first the incoming messages, then the main operation.
752823 /// Does not update chain state other than the execution state.
824+ #[ instrument( target = "telemetry_only" , skip_all, fields(
825+ chain_id = %block. chain_id,
826+ block_height = %block. height
827+ ) ) ]
753828 #[ expect( clippy:: too_many_arguments) ]
754829 async fn execute_block_inner (
755830 chain : & mut ExecutionStateView < C > ,
@@ -859,6 +934,10 @@ where
859934
860935 /// Executes a block: first the incoming messages, then the main operation.
861936 /// Does not update chain state other than the execution state.
937+ #[ instrument( target = "telemetry_only" , skip_all, fields(
938+ chain_id = %self . chain_id( ) ,
939+ block_height = %block. height
940+ ) ) ]
862941 pub async fn execute_block (
863942 & mut self ,
864943 block : & ProposedBlock ,
@@ -919,6 +998,10 @@ where
919998 /// Applies an execution outcome to the chain, updating the outboxes, state hash and chain
920999 /// manager. This does not touch the execution state itself, which must be updated separately.
9211000 /// Returns the set of event streams that were updated as a result of applying the block.
1001+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1002+ chain_id = %self . chain_id( ) ,
1003+ block_height = %block. inner( ) . inner( ) . header. height
1004+ ) ) ]
9221005 pub async fn apply_confirmed_block (
9231006 & mut self ,
9241007 block : & ConfirmedBlock ,
@@ -953,6 +1036,10 @@ where
9531036
9541037 /// Adds a block to `preprocessed_blocks`, and updates the outboxes where possible.
9551038 /// Returns the set of streams that were updated as a result of preprocessing the block.
1039+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1040+ chain_id = %self . chain_id( ) ,
1041+ block_height = %block. inner( ) . inner( ) . header. height
1042+ ) ) ]
9561043 pub async fn preprocess_block (
9571044 & mut self ,
9581045 block : & ConfirmedBlock ,
@@ -979,6 +1066,10 @@ where
9791066 }
9801067
9811068 /// Verifies that the block is valid according to the chain's application permission settings.
1069+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1070+ block_height = %block. height,
1071+ num_transactions = %block. transactions. len( )
1072+ ) ) ]
9821073 fn check_app_permissions (
9831074 app_permissions : & ApplicationPermissions ,
9841075 block : & ProposedBlock ,
@@ -1021,6 +1112,10 @@ where
10211112 }
10221113
10231114 /// Returns the hashes of all blocks we have in the given range.
1115+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1116+ chain_id = %self . chain_id( ) ,
1117+ next_block_height = %self . tip_state. get( ) . next_block_height
1118+ ) ) ]
10241119 pub async fn block_hashes (
10251120 & self ,
10261121 range : impl RangeBounds < BlockHeight > ,
@@ -1066,6 +1161,10 @@ where
10661161 /// Updates the outboxes with the messages sent in the block.
10671162 ///
10681163 /// Returns the set of all recipients.
1164+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1165+ chain_id = %self . chain_id( ) ,
1166+ block_height = %block. header. height
1167+ ) ) ]
10691168 async fn process_outgoing_messages (
10701169 & mut self ,
10711170 block : & Block ,
@@ -1157,6 +1256,10 @@ where
11571256 /// Updates the event streams with events emitted by the block if they form a contiguous
11581257 /// sequence (might not be the case when preprocessing a block).
11591258 /// Returns the set of updated event streams.
1259+ #[ instrument( target = "telemetry_only" , skip_all, fields(
1260+ chain_id = %self . chain_id( ) ,
1261+ block_height = %block. header. height
1262+ ) ) ]
11601263 async fn process_emitted_events (
11611264 & mut self ,
11621265 block : & Block ,
0 commit comments