@@ -21,6 +21,9 @@ use bitcoin::{Block, BlockHash, Transaction, Txid};
2121use bitcoincore_rpc:: { bitcoincore_rpc_json, RpcApi } ;
2222use core:: ops:: Deref ;
2323
24+ #[ cfg( feature = "tracing-logs" ) ]
25+ use tracing:: trace;
26+
2427pub mod bip158;
2528
2629pub use bitcoincore_rpc;
@@ -124,6 +127,13 @@ where
124127 pub fn mempool_at ( & mut self , sync_time : u64 ) -> Result < MempoolEvent , bitcoincore_rpc:: Error > {
125128 let client = & * self . client ;
126129
130+ #[ cfg( feature = "tracing-logs" ) ]
131+ trace ! (
132+ start_height = self . start_height,
133+ sync_time = sync_time,
134+ "enter mempool_at"
135+ ) ;
136+
127137 let mut rpc_tip_height;
128138 let mut rpc_tip_hash;
129139 let mut rpc_mempool;
@@ -164,6 +174,14 @@ where
164174 ..Default :: default ( )
165175 } ;
166176
177+ #[ cfg( feature = "tracing-logs" ) ]
178+ trace ! (
179+ rpc_mempool_count = rpc_mempool_txids. len( ) ,
180+ rpc_height = rpc_tip_height,
181+ rpc_block_hash = %rpc_tip_hash,
182+ "fetched raw mempool"
183+ ) ;
184+
167185 let at_tip =
168186 rpc_tip_height == self . last_cp . height ( ) as u64 && rpc_tip_hash == self . last_cp . hash ( ) ;
169187
@@ -200,11 +218,23 @@ where
200218
201219 /// Emit the next block height and block (if any).
202220 pub fn next_block ( & mut self ) -> Result < Option < BlockEvent < Block > > , bitcoincore_rpc:: Error > {
221+ #[ cfg( feature = "tracing-logs" ) ]
222+ trace ! (
223+ last_block_height = self . last_block. as_ref( ) . map( |r| r. height) ,
224+ "enter next_block"
225+ ) ;
226+
203227 if let Some ( ( checkpoint, block) ) = poll ( self , move |hash, client| client. get_block ( hash) ) ? {
204228 // Stop tracking unconfirmed transactions that have been confirmed in this block.
205229 for tx in & block. txdata {
206230 self . mempool_snapshot . remove ( & tx. compute_txid ( ) ) ;
207231 }
232+ #[ cfg( feature = "tracing-logs" ) ]
233+ trace ! (
234+ block_height = checkpoint. height( ) ,
235+ tx_count = block. txdata. len( ) ,
236+ "emit block"
237+ ) ;
208238 return Ok ( Some ( BlockEvent { block, checkpoint } ) ) ;
209239 }
210240 Ok ( None )
@@ -279,6 +309,13 @@ where
279309 C : Deref ,
280310 C :: Target : RpcApi ,
281311{
312+ #[ cfg( feature = "tracing-logs" ) ]
313+ trace ! (
314+ last_block_height = emitter. last_block. as_ref( ) . map( |r| r. height) ,
315+ start_height = emitter. start_height,
316+ "enter poll_once"
317+ ) ;
318+
282319 let client = & * emitter. client ;
283320
284321 if let Some ( last_res) = & emitter. last_block {
@@ -287,21 +324,35 @@ where
287324 let next_hash = client. get_block_hash ( emitter. start_height as _ ) ?;
288325 // make sure last emission is still in best chain
289326 if client. get_block_hash ( last_res. height as _ ) ? != last_res. hash {
327+ #[ cfg( feature = "tracing-logs" ) ]
328+ trace ! ( "block not in best chain" ) ;
290329 return Ok ( PollResponse :: BlockNotInBestChain ) ;
291330 }
292331 next_hash
293332 } else {
294333 match last_res. nextblockhash {
295- None => return Ok ( PollResponse :: NoMoreBlocks ) ,
334+ None => {
335+ #[ cfg( feature = "tracing-logs" ) ]
336+ trace ! ( "no more blocks" ) ;
337+ return Ok ( PollResponse :: NoMoreBlocks ) ;
338+ }
296339 Some ( next_hash) => next_hash,
297340 }
298341 } ;
299342
300343 let res = client. get_block_info ( & next_hash) ?;
301344 if res. confirmations < 0 {
345+ #[ cfg( feature = "tracing-logs" ) ]
346+ trace ! ( "block not in best chain" ) ;
302347 return Ok ( PollResponse :: BlockNotInBestChain ) ;
303348 }
304349
350+ #[ cfg( feature = "tracing-logs" ) ]
351+ trace ! (
352+ height = res. height,
353+ hash = %res. hash,
354+ "agreement found"
355+ ) ;
305356 return Ok ( PollResponse :: Block ( res) ) ;
306357 }
307358
@@ -321,6 +372,12 @@ where
321372 } ;
322373
323374 // agreement point found
375+ #[ cfg( feature = "tracing-logs" ) ]
376+ trace ! (
377+ "poll(): PollResponse::AgreementFound, height={}, hash={}" ,
378+ res. height,
379+ res. hash
380+ ) ;
324381 return Ok ( PollResponse :: AgreementFound ( res, cp) ) ;
325382 }
326383
0 commit comments