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