Skip to content

Commit 7fd6ac3

Browse files
committed
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
1 parent 20f287f commit 7fd6ac3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-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
}
@@ -739,7 +741,7 @@ where C::Target: chain::Filter,
739741
},
740742
}
741743
if let Some(ref chain_source) = self.chain_source {
742-
monitor.load_outputs_to_watch(chain_source);
744+
monitor.load_outputs_to_watch(chain_source , &self.logger);
743745
}
744746
entry.insert(MonitorHolder {
745747
monitor,

lightning/src/chain/channelmonitor.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1343,17 +1343,24 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13431343
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
13441344
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
13451345
/// have been registered.
1346-
pub fn load_outputs_to_watch<F: Deref>(&self, filter: &F) where F::Target: chain::Filter {
1346+
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
1347+
where
1348+
F::Target: chain::Filter, L::Target: Logger,
1349+
{
13471350
let lock = self.inner.lock().unwrap();
13481351
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
1352+
log_trace!(logger,
1353+
"Registering funding outpoint {}", &lock.get_funding_txo().0);
13491354
for (txid, outputs) in lock.get_outputs_to_watch().iter() {
13501355
for (index, script_pubkey) in outputs.iter() {
13511356
assert!(*index <= u16::max_value() as u32);
1357+
let outpoint = OutPoint { txid: *txid, index: *index as u16 };
13521358
filter.register_output(WatchedOutput {
13531359
block_hash: None,
1354-
outpoint: OutPoint { txid: *txid, index: *index as u16 },
1360+
outpoint: outpoint,
13551361
script_pubkey: script_pubkey.clone(),
13561362
});
1363+
log_trace!(logger, "Adding monitoring for spends of outpoint {} to the filter", outpoint);
13571364
}
13581365
}
13591366
}
@@ -3392,9 +3399,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33923399

33933400
if height > self.best_block.height() {
33943401
self.best_block = BestBlock::new(block_hash, height);
3402+
log_trace!(logger, "Connecting new block {} at height {}", block_hash, height);
33953403
self.block_confirmed(height, block_hash, vec![], vec![], vec![], &broadcaster, &fee_estimator, &logger)
33963404
} else if block_hash != self.best_block.block_hash() {
33973405
self.best_block = BestBlock::new(block_hash, height);
3406+
log_trace!(logger, "New block of block hash {} has been found and updated", block_hash);
33983407
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height <= height);
33993408
self.onchain_tx_handler.block_disconnected(height + 1, broadcaster, fee_estimator, logger);
34003409
Vec::new()
@@ -3431,6 +3440,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34313440
let mut claimable_outpoints = Vec::new();
34323441
'tx_iter: for tx in &txn_matched {
34333442
let txid = tx.txid();
3443+
log_trace!(logger, "Transaction id {} confirmed in block {}", txid , block_hash);
34343444
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
34353445
if Some(txid) == self.funding_spend_confirmed {
34363446
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);

lightning/src/chain/transaction.rs

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ impl OutPoint {
7575
}
7676
}
7777

78+
impl core::fmt::Display for OutPoint {
79+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80+
write!(f, "{}:{}", self.txid, self.index)
81+
}
82+
}
83+
7884
impl_writeable!(OutPoint, { txid, index });
7985

8086
#[cfg(test)]

0 commit comments

Comments
 (0)