From 89101531aa65169c3459cfd38094b9c6f4af7b22 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 13 Feb 2024 23:43:19 +0000 Subject: [PATCH] Opportunistically skip log in `update_claims_view_from_matched_txn` On each block, for each `ChannelMonitor`, we log two status statements in `OnChainTx::update_claims_view_from_matched_txn`. This can add up to quite a bit, and is generally not very interesting when we don't actually do anything if there's no claims to bump. Here we drop both logs if we have no claims to work with, but retain it if we process any claims. --- lightning/src/chain/onchaintx.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index a95cf774..94d6aa35 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -861,8 +861,15 @@ impl OnchainTxHandler B::Target: BroadcasterInterface, F::Target: FeeEstimator, { - log_debug!(logger, "Updating claims view at height {} with {} matched transactions in block {}", cur_height, txn_matched.len(), conf_height); + let mut have_logged_intro = false; + let mut maybe_log_intro = || { + if !have_logged_intro { + log_debug!(logger, "Updating claims view at height {} with {} matched transactions in block {}", cur_height, txn_matched.len(), conf_height); + have_logged_intro = true; + } + }; let mut bump_candidates = new_hash_map(); + if !txn_matched.is_empty() { maybe_log_intro(); } for tx in txn_matched { // Scan all input to verify is one of the outpoint spent is of interest for us let mut claimed_outputs_material = Vec::new(); @@ -955,6 +962,7 @@ impl OnchainTxHandler self.onchain_events_awaiting_threshold_conf.drain(..).collect::>(); for entry in onchain_events_awaiting_threshold_conf { if entry.has_reached_confirmation_threshold(cur_height) { + maybe_log_intro(); match entry.event { OnchainEvent::Claim { claim_id } => { // We may remove a whole set of claim outpoints here, as these one may have @@ -992,7 +1000,11 @@ impl OnchainTxHandler } // Build, bump and rebroadcast tx accordingly - log_trace!(logger, "Bumping {} candidates", bump_candidates.len()); + if !bump_candidates.is_empty() { + maybe_log_intro(); + log_trace!(logger, "Bumping {} candidates", bump_candidates.len()); + } + for (claim_id, request) in bump_candidates.iter() { if let Some((new_timer, new_feerate, bump_claim)) = self.generate_claim( cur_height, &request, &FeerateStrategy::ForceBump, &*fee_estimator, &*logger, -- 2.30.2