From 7fd6ac3a86edaefa820f9cee37d7a9a148298a05 Mon Sep 17 00:00:00 2001 From: Lalitmohansharma1 Date: Mon, 2 Oct 2023 15:57:09 +0530 Subject: [PATCH] Improving block conenction logging and filtered txids This commit is logging confirmed txids and also logging when we adds things to the filter solves #2348 --- lightning/src/chain/chainmonitor.rs | 6 ++++-- lightning/src/chain/channelmonitor.rs | 14 ++++++++++++-- lightning/src/chain/transaction.rs | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 261c0471ca4..c01f2e7b3d8 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -402,7 +402,9 @@ where C::Target: chain::Filter, outpoint: OutPoint { txid, index: idx as u16 }, script_pubkey: output.script_pubkey, }; - chain_source.register_output(output) + log_trace!(self.logger, + "Adding monitoring for spends of outpoint {} to the filter", output.outpoint); + chain_source.register_output(output); } } } @@ -739,7 +741,7 @@ where C::Target: chain::Filter, }, } if let Some(ref chain_source) = self.chain_source { - monitor.load_outputs_to_watch(chain_source); + monitor.load_outputs_to_watch(chain_source , &self.logger); } entry.insert(MonitorHolder { monitor, diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index a0ac1657e93..aa2d8ef201b 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1343,17 +1343,24 @@ impl ChannelMonitor { /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs /// have been registered. - pub fn load_outputs_to_watch(&self, filter: &F) where F::Target: chain::Filter { + pub fn load_outputs_to_watch(&self, filter: &F, logger: &L) + where + F::Target: chain::Filter, L::Target: Logger, + { let lock = self.inner.lock().unwrap(); filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1); + log_trace!(logger, + "Registering funding outpoint {}", &lock.get_funding_txo().0); for (txid, outputs) in lock.get_outputs_to_watch().iter() { for (index, script_pubkey) in outputs.iter() { assert!(*index <= u16::max_value() as u32); + let outpoint = OutPoint { txid: *txid, index: *index as u16 }; filter.register_output(WatchedOutput { block_hash: None, - outpoint: OutPoint { txid: *txid, index: *index as u16 }, + outpoint: outpoint, script_pubkey: script_pubkey.clone(), }); + log_trace!(logger, "Adding monitoring for spends of outpoint {} to the filter", outpoint); } } } @@ -3392,9 +3399,11 @@ impl ChannelMonitorImpl { if height > self.best_block.height() { self.best_block = BestBlock::new(block_hash, height); + log_trace!(logger, "Connecting new block {} at height {}", block_hash, height); self.block_confirmed(height, block_hash, vec![], vec![], vec![], &broadcaster, &fee_estimator, &logger) } else if block_hash != self.best_block.block_hash() { self.best_block = BestBlock::new(block_hash, height); + log_trace!(logger, "New block of block hash {} has been found and updated", block_hash); self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height <= height); self.onchain_tx_handler.block_disconnected(height + 1, broadcaster, fee_estimator, logger); Vec::new() @@ -3431,6 +3440,7 @@ impl ChannelMonitorImpl { let mut claimable_outpoints = Vec::new(); 'tx_iter: for tx in &txn_matched { let txid = tx.txid(); + log_trace!(logger, "Transaction id {} confirmed in block {}", txid , block_hash); // If a transaction has already been confirmed, ensure we don't bother processing it duplicatively. if Some(txid) == self.funding_spend_confirmed { log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid); diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index 22e7ec2c2f9..39a0a5449ac 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -75,6 +75,12 @@ impl OutPoint { } } +impl core::fmt::Display for OutPoint { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{}:{}", self.txid, self.index) + } +} + impl_writeable!(OutPoint, { txid, index }); #[cfg(test)]