Skip to content

Commit 7f9be58

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 lightningdevkit#2348
1 parent fcf47a4 commit 7f9be58

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
}
@@ -741,7 +743,7 @@ where C::Target: chain::Filter,
741743
},
742744
}
743745
if let Some(ref chain_source) = self.chain_source {
744-
monitor.load_outputs_to_watch(chain_source);
746+
monitor.load_outputs_to_watch(chain_source , &self.logger);
745747
}
746748
entry.insert(MonitorHolder {
747749
monitor,

lightning/src/chain/channelmonitor.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1382,17 +1382,24 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13821382
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
13831383
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
13841384
/// have been registered.
1385-
pub fn load_outputs_to_watch<F: Deref>(&self, filter: &F) where F::Target: chain::Filter {
1385+
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
1386+
where
1387+
F::Target: chain::Filter, L::Target: Logger,
1388+
{
13861389
let lock = self.inner.lock().unwrap();
13871390
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
1391+
log_trace!(logger,
1392+
"Registering funding outpoint {}", &lock.get_funding_txo().0);
13881393
for (txid, outputs) in lock.get_outputs_to_watch().iter() {
13891394
for (index, script_pubkey) in outputs.iter() {
13901395
assert!(*index <= u16::max_value() as u32);
1396+
let outpoint = OutPoint { txid: *txid, index: *index as u16 };
13911397
filter.register_output(WatchedOutput {
13921398
block_hash: None,
1393-
outpoint: OutPoint { txid: *txid, index: *index as u16 },
1399+
outpoint: outpoint,
13941400
script_pubkey: script_pubkey.clone(),
13951401
});
1402+
log_trace!(logger, "Adding monitoring for spends of outpoint {} to the filter", outpoint);
13961403
}
13971404
}
13981405
}
@@ -3458,9 +3465,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34583465

34593466
if height > self.best_block.height() {
34603467
self.best_block = BestBlock::new(block_hash, height);
3468+
log_trace!(logger, "Connecting new block {} at height {}", block_hash, height);
34613469
self.block_confirmed(height, block_hash, vec![], vec![], vec![], &broadcaster, &fee_estimator, logger)
34623470
} else if block_hash != self.best_block.block_hash() {
34633471
self.best_block = BestBlock::new(block_hash, height);
3472+
log_trace!(logger, "New block of block hash {} has been found and updated", block_hash);
34643473
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height <= height);
34653474
self.onchain_tx_handler.block_disconnected(height + 1, broadcaster, fee_estimator, logger);
34663475
Vec::new()
@@ -3497,6 +3506,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34973506
let mut claimable_outpoints = Vec::new();
34983507
'tx_iter: for tx in &txn_matched {
34993508
let txid = tx.txid();
3509+
log_trace!(logger, "Transaction id {} confirmed in block {}", txid , block_hash);
35003510
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
35013511
if Some(txid) == self.funding_spend_confirmed {
35023512
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);

0 commit comments

Comments
 (0)