@@ -20,6 +20,9 @@ use bitcoin::{Block, BlockHash, Transaction, Txid};
20
20
use bitcoincore_rpc:: { bitcoincore_rpc_json, RpcApi } ;
21
21
use core:: ops:: Deref ;
22
22
23
+ #[ cfg( feature = "tracing-logs" ) ]
24
+ use tracing:: trace;
25
+
23
26
pub mod bip158;
24
27
25
28
pub use bitcoincore_rpc;
@@ -123,6 +126,13 @@ where
123
126
pub fn mempool_at ( & mut self , sync_time : u64 ) -> Result < MempoolEvent , bitcoincore_rpc:: Error > {
124
127
let client = & * self . client ;
125
128
129
+ #[ cfg( feature = "tracing-logs" ) ]
130
+ trace ! (
131
+ start_height = self . start_height,
132
+ sync_time = sync_time,
133
+ "enter mempool_at"
134
+ ) ;
135
+
126
136
let mut rpc_tip_height;
127
137
let mut rpc_tip_hash;
128
138
let mut rpc_mempool;
@@ -163,6 +173,14 @@ where
163
173
..Default :: default ( )
164
174
} ;
165
175
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
+
166
184
let at_tip =
167
185
rpc_tip_height == self . last_cp . height ( ) as u64 && rpc_tip_hash == self . last_cp . hash ( ) ;
168
186
@@ -199,11 +217,23 @@ where
199
217
200
218
/// Emit the next block height and block (if any).
201
219
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
+
202
226
if let Some ( ( checkpoint, block) ) = poll ( self , move |hash, client| client. get_block ( hash) ) ? {
203
227
// Stop tracking unconfirmed transactions that have been confirmed in this block.
204
228
for tx in & block. txdata {
205
229
self . mempool_snapshot . remove ( & tx. compute_txid ( ) ) ;
206
230
}
231
+ #[ cfg( feature = "tracing-logs" ) ]
232
+ trace ! (
233
+ block_height = checkpoint. height( ) ,
234
+ tx_count = block. txdata. len( ) ,
235
+ "emit block"
236
+ ) ;
207
237
return Ok ( Some ( BlockEvent { block, checkpoint } ) ) ;
208
238
}
209
239
Ok ( None )
@@ -278,6 +308,13 @@ where
278
308
C : Deref ,
279
309
C :: Target : RpcApi ,
280
310
{
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
+
281
318
let client = & * emitter. client ;
282
319
283
320
if let Some ( last_res) = & emitter. last_block {
@@ -286,21 +323,35 @@ where
286
323
let next_hash = client. get_block_hash ( emitter. start_height as _ ) ?;
287
324
// make sure last emission is still in best chain
288
325
if client. get_block_hash ( last_res. height as _ ) ? != last_res. hash {
326
+ #[ cfg( feature = "tracing-logs" ) ]
327
+ trace ! ( "block not in best chain" ) ;
289
328
return Ok ( PollResponse :: BlockNotInBestChain ) ;
290
329
}
291
330
next_hash
292
331
} else {
293
332
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
+ }
295
338
Some ( next_hash) => next_hash,
296
339
}
297
340
} ;
298
341
299
342
let res = client. get_block_info ( & next_hash) ?;
300
343
if res. confirmations < 0 {
344
+ #[ cfg( feature = "tracing-logs" ) ]
345
+ trace ! ( "block not in best chain" ) ;
301
346
return Ok ( PollResponse :: BlockNotInBestChain ) ;
302
347
}
303
348
349
+ #[ cfg( feature = "tracing-logs" ) ]
350
+ trace ! (
351
+ height = res. height,
352
+ hash = %res. hash,
353
+ "agreement found"
354
+ ) ;
304
355
return Ok ( PollResponse :: Block ( res) ) ;
305
356
}
306
357
@@ -320,6 +371,12 @@ where
320
371
} ;
321
372
322
373
// agreement point found
374
+ #[ cfg( feature = "tracing-logs" ) ]
375
+ trace ! (
376
+ "poll(): PollResponse::AgreementFound, height={}, hash={}" ,
377
+ res. height,
378
+ res. hash
379
+ ) ;
323
380
return Ok ( PollResponse :: AgreementFound ( res, cp) ) ;
324
381
}
325
382
0 commit comments