Skip to content

Commit 4b35697

Browse files
authored
Merge pull request #2637 from Sharmalm/2348
Improve block connection logging and filtered txids
2 parents 40379aa + f89d42c commit 4b35697

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ 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!(logger, "Adding monitoring for spends of outpoint {} to the filter", output.outpoint);
406+
chain_source.register_output(output);
406407
}
407408
}
408409
}
@@ -741,7 +742,7 @@ where C::Target: chain::Filter,
741742
},
742743
}
743744
if let Some(ref chain_source) = self.chain_source {
744-
monitor.load_outputs_to_watch(chain_source);
745+
monitor.load_outputs_to_watch(chain_source , &self.logger);
745746
}
746747
entry.insert(MonitorHolder {
747748
monitor,

lightning/src/chain/channelmonitor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,15 +1382,22 @@ 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();
1390+
let logger = WithChannelMonitor::from_impl(logger, &*lock);
1391+
log_trace!(&logger, "Registering funding outpoint {}", &lock.get_funding_txo().0);
13871392
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
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 };
1397+
log_trace!(logger, "Registering outpoint {} with the filter for monitoring spends", outpoint);
13911398
filter.register_output(WatchedOutput {
13921399
block_hash: None,
1393-
outpoint: OutPoint { txid: *txid, index: *index as u16 },
1400+
outpoint,
13941401
script_pubkey: script_pubkey.clone(),
13951402
});
13961403
}
@@ -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, "Best block re-orged, replaced with new block {} at height {}", block_hash, height);
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 {} 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)