@@ -20,6 +20,9 @@ use bitcoin::{Block, BlockHash, Transaction, Txid};
2020use bitcoincore_rpc:: { bitcoincore_rpc_json, RpcApi } ;
2121use core:: ops:: Deref ;
2222
23+ #[ cfg( feature = "tracing-logs" ) ]
24+ use tracing:: trace;
25+
2326pub mod bip158;
2427
2528pub use bitcoincore_rpc;
@@ -123,6 +126,13 @@ where
123126 pub fn mempool_at ( & mut self , sync_time : u64 ) -> Result < MempoolEvent , bitcoincore_rpc:: Error > {
124127 let client = & * self . client ;
125128
129+ #[ cfg( feature = "tracing-logs" ) ]
130+ trace ! (
131+ start_height = self . start_height,
132+ sync_time = sync_time,
133+ "enter mempool_at"
134+ ) ;
135+
126136 let mut rpc_tip_height;
127137 let mut rpc_tip_hash;
128138 let mut rpc_mempool;
@@ -163,6 +173,14 @@ where
163173 ..Default :: default ( )
164174 } ;
165175
176+ #[ cfg( feature = "tracing-logs" ) ]
177+ trace ! (
178+ rpc_mempool_count = rpc_mempool_txids. len( ) ,
179+ rpc_height = rpc_tip_height,
180+ rpc_block_hash = %rpc_tip_hash,
181+ "fetched raw mempool"
182+ ) ;
183+
166184 let at_tip =
167185 rpc_tip_height == self . last_cp . height ( ) as u64 && rpc_tip_hash == self . last_cp . hash ( ) ;
168186
@@ -199,11 +217,23 @@ where
199217
200218 /// Emit the next block height and block (if any).
201219 pub fn next_block ( & mut self ) -> Result < Option < BlockEvent < Block > > , bitcoincore_rpc:: Error > {
220+ #[ cfg( feature = "tracing-logs" ) ]
221+ trace ! (
222+ last_block_height = self . last_block. as_ref( ) . map( |r| r. height) ,
223+ "enter next_block"
224+ ) ;
225+
202226 if let Some ( ( checkpoint, block) ) = poll ( self , move |hash, client| client. get_block ( hash) ) ? {
203227 // Stop tracking unconfirmed transactions that have been confirmed in this block.
204228 for tx in & block. txdata {
205229 self . mempool_snapshot . remove ( & tx. compute_txid ( ) ) ;
206230 }
231+ #[ cfg( feature = "tracing-logs" ) ]
232+ trace ! (
233+ block_height = checkpoint. height( ) ,
234+ tx_count = block. txdata. len( ) ,
235+ "emit block"
236+ ) ;
207237 return Ok ( Some ( BlockEvent { block, checkpoint } ) ) ;
208238 }
209239 Ok ( None )
@@ -278,6 +308,13 @@ where
278308 C : Deref ,
279309 C :: Target : RpcApi ,
280310{
311+ #[ cfg( feature = "tracing-logs" ) ]
312+ trace ! (
313+ last_block_height = emitter. last_block. as_ref( ) . map( |r| r. height) ,
314+ start_height = emitter. start_height,
315+ "enter poll_once"
316+ ) ;
317+
281318 let client = & * emitter. client ;
282319
283320 if let Some ( last_res) = & emitter. last_block {
@@ -286,21 +323,35 @@ where
286323 let next_hash = client. get_block_hash ( emitter. start_height as _ ) ?;
287324 // make sure last emission is still in best chain
288325 if client. get_block_hash ( last_res. height as _ ) ? != last_res. hash {
326+ #[ cfg( feature = "tracing-logs" ) ]
327+ trace ! ( "block not in best chain" ) ;
289328 return Ok ( PollResponse :: BlockNotInBestChain ) ;
290329 }
291330 next_hash
292331 } else {
293332 match last_res. nextblockhash {
294- None => return Ok ( PollResponse :: NoMoreBlocks ) ,
333+ None => {
334+ #[ cfg( feature = "tracing-logs" ) ]
335+ trace ! ( "no more blocks" ) ;
336+ return Ok ( PollResponse :: NoMoreBlocks ) ;
337+ }
295338 Some ( next_hash) => next_hash,
296339 }
297340 } ;
298341
299342 let res = client. get_block_info ( & next_hash) ?;
300343 if res. confirmations < 0 {
344+ #[ cfg( feature = "tracing-logs" ) ]
345+ trace ! ( "block not in best chain" ) ;
301346 return Ok ( PollResponse :: BlockNotInBestChain ) ;
302347 }
303348
349+ #[ cfg( feature = "tracing-logs" ) ]
350+ trace ! (
351+ height = res. height,
352+ hash = %res. hash,
353+ "agreement found"
354+ ) ;
304355 return Ok ( PollResponse :: Block ( res) ) ;
305356 }
306357
@@ -320,6 +371,12 @@ where
320371 } ;
321372
322373 // agreement point found
374+ #[ cfg( feature = "tracing-logs" ) ]
375+ trace ! (
376+ "poll(): PollResponse::AgreementFound, height={}, hash={}" ,
377+ res. height,
378+ res. hash
379+ ) ;
323380 return Ok ( PollResponse :: AgreementFound ( res, cp) ) ;
324381 }
325382
0 commit comments