@@ -23,7 +23,7 @@ use crate::{
2323 bootstrap:: { export_bootstrap_stream, import_bootstrap_stream} ,
2424 calculate_median_time_past,
2525 tx_verification_strategy:: TransactionVerificationStrategy ,
26- BlockSource , OrphanBlocksRef ,
26+ BlockSource , OrphanBlocksRef , CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS ,
2727 } ,
2828 ChainInfo , ChainstateConfig , ChainstateError , ChainstateEvent , ChainstateInterface , Locator ,
2929 NonZeroPoolBalances ,
7171 self . chainstate . subscribe_to_event_broadcast ( )
7272 }
7373
74- #[ tracing:: instrument( skip_all, fields( block_id = %block. get_id( ) ) ) ]
74+ // Note: in this and some other functions below (in particular, in those that are called from
75+ // p2p when processing blocks coming from peers) we add an additional DEBUG span that prints
76+ // the block via `format!("{:x}")`. This is because the other span prints the id via Display
77+ // (due to the '%' sigil), in which case it is shortened, e.g. "778b…b100".
78+ // Always printing the full id would clutter the log, so we don't want to do that.
79+ // So we add an additional span for the cases when the full id is needed.
80+ // Also note that we add the extra span first, but in the output it will be printed after
81+ // the normal one.
82+ #[ tracing:: instrument(
83+ skip_all, level = tracing:: Level :: DEBUG , name = "" ,
84+ fields( id = format!( "{:x}" , block. get_id( ) ) ) ,
85+ target = CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS
86+ ) ]
87+ #[ tracing:: instrument( skip_all, fields( id = %block. get_id( ) ) ) ]
7588 fn process_block (
7689 & mut self ,
7790 block : Block ,
@@ -82,23 +95,34 @@ where
8295 . map_err ( ChainstateError :: ProcessBlockError )
8396 }
8497
85- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
98+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
8699 fn invalidate_block ( & mut self , block_id : & Id < Block > ) -> Result < ( ) , ChainstateError > {
87100 self . chainstate
88101 . invalidate_block ( block_id)
89102 . map_err ( ChainstateError :: BlockInvalidatorError )
90103 }
91104
92- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
105+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
93106 fn reset_block_failure_flags ( & mut self , block_id : & Id < Block > ) -> Result < ( ) , ChainstateError > {
94107 BlockInvalidator :: new ( & mut self . chainstate )
95108 . reset_block_failure_flags ( block_id)
96109 . map_err ( ChainstateError :: BlockInvalidatorError )
97110 }
98111
112+ #[ tracing:: instrument(
113+ skip_all, level = tracing:: Level :: DEBUG , name = "" ,
114+ fields( first_id =
115+ if let Some ( first_header) = headers. first( ) {
116+ format!( "{:x}" , first_header. get_id( ) )
117+ } else {
118+ "None" . to_owned( )
119+ }
120+ ) ,
121+ target = CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS
122+ ) ]
99123 #[ tracing:: instrument(
100124 skip_all,
101- fields( first_block_id = %headers. first( ) . map( |header| header. get_id( ) ) . as_displayable( ) )
125+ fields( first_id = %headers. first( ) . map( |header| header. get_id( ) ) . as_displayable( ) )
102126 ) ]
103127 fn preliminary_headers_check (
104128 & self ,
@@ -109,7 +133,12 @@ where
109133 . map_err ( ChainstateError :: ProcessBlockError )
110134 }
111135
112- #[ tracing:: instrument( skip_all, fields( block_id = %block. get_id( ) ) ) ]
136+ #[ tracing:: instrument(
137+ skip_all, level = tracing:: Level :: DEBUG , name = "" ,
138+ fields( id = format!( "{:x}" , block. get_id( ) ) ) ,
139+ target = CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS
140+ ) ]
141+ #[ tracing:: instrument( skip_all, fields( id = %block. get_id( ) ) ) ]
113142 fn preliminary_block_check ( & self , block : Block ) -> Result < Block , ChainstateError > {
114143 let block = BlockChecker :: new ( & self . chainstate )
115144 . preliminary_block_check ( block. into ( ) )
@@ -126,7 +155,7 @@ where
126155 . map_err ( ChainstateError :: FailedToReadProperty )
127156 }
128157
129- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
158+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
130159 fn is_block_in_main_chain ( & self , block_id : & Id < GenBlock > ) -> Result < bool , ChainstateError > {
131160 self . chainstate
132161 . query ( )
@@ -144,7 +173,7 @@ where
144173 . map_err ( ChainstateError :: FailedToReadProperty )
145174 }
146175
147- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
176+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
148177 fn get_block_height_in_main_chain (
149178 & self ,
150179 block_id : & Id < GenBlock > ,
@@ -168,7 +197,7 @@ where
168197 . map_err ( ChainstateError :: FailedToReadProperty )
169198 }
170199
171- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
200+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
172201 fn get_block ( & self , block_id : Id < Block > ) -> Result < Option < Block > , ChainstateError > {
173202 self . chainstate
174203 . query ( )
@@ -190,7 +219,7 @@ where
190219 . map_err ( ChainstateError :: FailedToReadProperty )
191220 }
192221
193- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
222+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
194223 fn get_block_header (
195224 & self ,
196225 block_id : Id < Block > ,
@@ -311,7 +340,7 @@ where
311340 . map_err ( ChainstateError :: FailedToReadProperty )
312341 }
313342
314- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
343+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
315344 fn get_block_index_for_persisted_block (
316345 & self ,
317346 block_id : & Id < Block > ,
@@ -323,7 +352,7 @@ where
323352 . map_err ( ChainstateError :: FailedToReadProperty )
324353 }
325354
326- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
355+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
327356 fn get_block_index_for_any_block (
328357 & self ,
329358 block_id : & Id < Block > ,
@@ -389,7 +418,7 @@ where
389418 Ok ( calculate_median_time_past ( & dbtx, starting_block) )
390419 }
391420
392- #[ tracing:: instrument( skip_all, fields( block_id = %block_id) ) ]
421+ #[ tracing:: instrument( skip_all, fields( id = %block_id) ) ]
393422 fn is_already_an_orphan ( & self , block_id : & Id < Block > ) -> bool {
394423 self . chainstate . orphan_blocks_pool ( ) . is_already_an_orphan ( block_id)
395424 }
@@ -401,7 +430,7 @@ where
401430
402431 #[ tracing:: instrument(
403432 skip_all,
404- fields( block_id = %block_index. block_id( ) , ancestor_height = %ancestor_height)
433+ fields( id = %block_index. block_id( ) , ancestor_height = %ancestor_height)
405434 ) ]
406435 fn get_ancestor (
407436 & self ,
@@ -420,8 +449,8 @@ where
420449 #[ tracing:: instrument(
421450 skip_all,
422451 fields(
423- first_block_id = %first_block_index. block_id( ) ,
424- second_block_id = %second_block_index. block_id( )
452+ first_id = %first_block_index. block_id( ) ,
453+ second_id = %second_block_index. block_id( )
425454 )
426455 ) ]
427456 fn last_common_ancestor (
@@ -461,7 +490,7 @@ where
461490 }
462491 }
463492
464- #[ tracing:: instrument( skip_all, fields( block_id = %block_index. block_id( ) ) ) ]
493+ #[ tracing:: instrument( skip_all, fields( id = %block_index. block_id( ) ) ) ]
465494 fn get_block_reward (
466495 & self ,
467496 block_index : & BlockIndex ,
0 commit comments