Skip to content

Commit 8e4987e

Browse files
committed
Improving block conenction logging and filtered txids
Implement the Display trait for Outpoint and utilize it in the codebase for monitoring outpoints. Additionally, add log tracing for best_block_update and confirmed transactions. solves #2348
1 parent 242e6ae commit 8e4987e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lightning/src/chain/chainmonitor.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ where C::Target: chain::Filter,
402402
outpoint: OutPoint { txid, index: idx as u16 },
403403
script_pubkey: output.script_pubkey,
404404
};
405-
chain_source.register_output(output)
405+
log_trace!(self.logger,
406+
"Adding monitoring for spends of outpoint {} to the filter", output.outpoint);
407+
chain_source.register_output(output);
406408
}
407409
}
408410
}
@@ -746,7 +748,7 @@ where C::Target: chain::Filter,
746748
},
747749
}
748750
if let Some(ref chain_source) = self.chain_source {
749-
monitor.load_outputs_to_watch(chain_source);
751+
monitor.load_outputs_to_watch(chain_source , &self.logger);
750752
}
751753
entry.insert(MonitorHolder {
752754
monitor,

lightning/src/chain/channelmonitor.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1370,17 +1370,24 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13701370
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
13711371
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
13721372
/// have been registered.
1373-
pub fn load_outputs_to_watch<F: Deref>(&self, filter: &F) where F::Target: chain::Filter {
1373+
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
1374+
where
1375+
F::Target: chain::Filter, L::Target: Logger,
1376+
{
13741377
let lock = self.inner.lock().unwrap();
13751378
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
1379+
log_trace!(logger,
1380+
"Registering funding outpoint {}", &lock.get_funding_txo().0);
13761381
for (txid, outputs) in lock.get_outputs_to_watch().iter() {
13771382
for (index, script_pubkey) in outputs.iter() {
13781383
assert!(*index <= u16::max_value() as u32);
1384+
let outpoint = OutPoint { txid: *txid, index: *index as u16 };
13791385
filter.register_output(WatchedOutput {
13801386
block_hash: None,
1381-
outpoint: OutPoint { txid: *txid, index: *index as u16 },
1387+
outpoint: outpoint,
13821388
script_pubkey: script_pubkey.clone(),
13831389
});
1390+
log_trace!(logger, "Adding monitoring for spends of outpoint {} to the filter", outpoint);
13841391
}
13851392
}
13861393
}
@@ -3418,9 +3425,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34183425

34193426
if height > self.best_block.height() {
34203427
self.best_block = BestBlock::new(block_hash, height);
3428+
log_trace!(logger, "Connecting new block {} at height {}", block_hash, height);
34213429
self.block_confirmed(height, block_hash, vec![], vec![], vec![], &broadcaster, &fee_estimator, &logger)
34223430
} else if block_hash != self.best_block.block_hash() {
34233431
self.best_block = BestBlock::new(block_hash, height);
3432+
log_trace!(logger, "New block of block hash {} has been found and updated", block_hash);
34243433
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height <= height);
34253434
self.onchain_tx_handler.block_disconnected(height + 1, broadcaster, fee_estimator, logger);
34263435
Vec::new()
@@ -3457,6 +3466,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34573466
let mut claimable_outpoints = Vec::new();
34583467
'tx_iter: for tx in &txn_matched {
34593468
let txid = tx.txid();
3469+
log_trace!(logger, "Transaction id {} confirmed in block {}", txid , block_hash);
34603470
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
34613471
if Some(txid) == self.funding_spend_confirmed {
34623472
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);

0 commit comments

Comments
 (0)