Skip to content

Commit cf84655

Browse files
committed
Log chain calls in ChainMonitor, reducing logs in ChannelMonitor
For users with many ChannelMonitors, we log a large volume per block simply because each ChannelMonitor lots several times per block. Instead, we move to log only once at the TRACE level per block call in ChannelMonitors, relying instead on a DEBUG level log in ChainMonitor before we call any ChannelMonitor functions. For most users, this will reduce redundant logging and also log at the DEBUG level for block events, which is appropriate. Fixes #980.
1 parent 33e1652 commit cf84655

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ where
162162
fn block_connected(&self, block: &Block, height: u32) {
163163
let header = &block.header;
164164
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
165+
log_debug!(self.logger, "New best block {} at height {} provided via block_connected", header.block_hash(), height);
165166
self.process_chain_data(header, &txdata, |monitor, txdata| {
166167
monitor.block_connected(
167168
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
@@ -170,6 +171,7 @@ where
170171

171172
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
172173
let monitors = self.monitors.read().unwrap();
174+
log_debug!(self.logger, "Latest block disconnected, new best block {} at height {} provided via block_disconnected", header.block_hash(), height);
173175
for monitor in monitors.values() {
174176
monitor.block_disconnected(
175177
header, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
@@ -187,20 +189,23 @@ where
187189
P::Target: channelmonitor::Persist<ChannelSigner>,
188190
{
189191
fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
192+
log_debug!(self.logger, "{} transactions confirmed at height {} in block {}", txdata.len(), height, header.block_hash());
190193
self.process_chain_data(header, txdata, |monitor, txdata| {
191194
monitor.transactions_confirmed(
192195
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
193196
});
194197
}
195198

196199
fn transaction_unconfirmed(&self, txid: &Txid) {
200+
log_debug!(self.logger, "{} reorganized out of chain", txid);
197201
let monitors = self.monitors.read().unwrap();
198202
for monitor in monitors.values() {
199203
monitor.transaction_unconfirmed(txid, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
200204
}
201205
}
202206

203207
fn best_block_updated(&self, header: &BlockHeader, height: u32) {
208+
log_debug!(self.logger, "New best block {} at height {} provided via best_block_updated", header.block_hash(), height);
204209
self.process_chain_data(header, &[], |monitor, txdata| {
205210
// While in practice there shouldn't be any recursive calls when given empty txdata,
206211
// it's still possible if a chain::Filter implementation returns a transaction.

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19131913
L::Target: Logger,
19141914
{
19151915
let block_hash = header.block_hash();
1916-
log_trace!(logger, "New best block {} at height {}", block_hash, height);
19171916
self.best_block = BestBlock::new(block_hash, height);
19181917

19191918
self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
@@ -1933,7 +1932,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19331932
L::Target: Logger,
19341933
{
19351934
let block_hash = header.block_hash();
1936-
log_trace!(logger, "New best block {} at height {}", block_hash, height);
19371935

19381936
if height > self.best_block.height() {
19391937
self.best_block = BestBlock::new(block_hash, height);
@@ -1971,7 +1969,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19711969
}
19721970

19731971
let block_hash = header.block_hash();
1974-
log_trace!(logger, "Block {} at height {} connected with {} txn matched", block_hash, height, txn_matched.len());
19751972

19761973
let mut watch_outputs = Vec::new();
19771974
let mut claimable_outpoints = Vec::new();
@@ -2044,6 +2041,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20442041
F::Target: FeeEstimator,
20452042
L::Target: Logger,
20462043
{
2044+
log_trace!(logger, "Processing {} transactions for block at height {}.", txn_matched.len(), conf_height);
20472045
debug_assert!(self.best_block.height() >= conf_height);
20482046

20492047
let should_broadcast = self.should_broadcast_holder_commitment_txn(logger);

0 commit comments

Comments
 (0)