Skip to content

Commit bda19d6

Browse files
authored
Merge pull request #4217 from joostjager/chan-logging
Log structured peer, channel and hash fields
2 parents 6d4897c + 053933b commit bda19d6

File tree

17 files changed

+334
-295
lines changed

17 files changed

+334
-295
lines changed

fuzz/src/full_stack.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,14 +1609,7 @@ mod tests {
16091609
.unwrap()
16101610
.entry((record.module_path.to_string(), format!("{}", record.args)))
16111611
.or_insert(0) += 1;
1612-
println!(
1613-
"{:<5} [{} : {}, {}] {}",
1614-
record.level.to_string(),
1615-
record.module_path,
1616-
record.file,
1617-
record.line,
1618-
record.args
1619-
);
1612+
println!("{}", record);
16201613
}
16211614
}
16221615

fuzz/src/onion_message.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ impl MessageRouter for TestMessageRouter {
102102
fn find_path(
103103
&self, _sender: PublicKey, _peers: Vec<PublicKey>, destination: Destination,
104104
) -> Result<OnionMessagePath, ()> {
105-
Ok(OnionMessagePath { intermediate_nodes: vec![], destination, first_node_addresses: vec![] })
105+
Ok(OnionMessagePath {
106+
intermediate_nodes: vec![],
107+
destination,
108+
first_node_addresses: vec![],
109+
})
106110
}
107111

108112
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
@@ -328,14 +332,7 @@ mod tests {
328332
let mut lines_lock = self.lines.lock().unwrap();
329333
let key = (record.module_path.to_string(), format!("{}", record.args));
330334
*lines_lock.entry(key).or_insert(0) += 1;
331-
println!(
332-
"{:<5} [{} : {}, {}] {}",
333-
record.level.to_string(),
334-
record.module_path,
335-
record.file,
336-
record.line,
337-
record.args
338-
);
335+
println!("{}", record);
339336
}
340337
}
341338

fuzz/src/utils/test_logger.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {
5959

6060
impl<Out: Output> Logger for TestLogger<Out> {
6161
fn log(&self, record: Record) {
62-
write!(
63-
LockedWriteAdapter(&self.out),
64-
"{:<5} {} [{} : {}] {}\n",
65-
record.level.to_string(),
66-
self.id,
67-
record.module_path,
68-
record.line,
69-
record.args
70-
)
71-
.unwrap();
62+
write!(LockedWriteAdapter(&self.out), "{:<6} {}", self.id, record).unwrap();
7263
}
7364
}

lightning-dns-resolver/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ mod test {
192192
}
193193
impl Logger for TestLogger {
194194
fn log(&self, record: lightning::util::logger::Record) {
195-
eprintln!("{}: {}", self.node, record.args);
195+
eprintln!("{:<8} {}", self.node, record);
196196
}
197197
}
198198
impl Deref for TestLogger {

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,7 @@ mod tests {
629629
pub struct TestLogger();
630630
impl lightning::util::logger::Logger for TestLogger {
631631
fn log(&self, record: lightning::util::logger::Record) {
632-
println!(
633-
"{:<5} [{} : {}, {}] {}",
634-
record.level.to_string(),
635-
record.module_path,
636-
record.file,
637-
record.line,
638-
record.args
639-
);
632+
println!("{}", record);
640633
}
641634
}
642635

lightning/src/chain/chainmonitor.rs

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -580,23 +580,17 @@ where
580580

581581
let has_pending_claims = monitor_state.monitor.has_pending_claims();
582582
if has_pending_claims || get_partition_key(channel_id) % partition_factor == 0 {
583-
log_trace!(
584-
logger,
585-
"Syncing Channel Monitor for channel {}",
586-
log_funding_info!(monitor)
587-
);
583+
log_trace!(logger, "Syncing Channel Monitor");
588584
// Even though we don't track monitor updates from chain-sync as pending, we still want
589585
// updates per-channel to be well-ordered so that users don't see a
590586
// `ChannelMonitorUpdate` after a channel persist for a channel with the same
591587
// `latest_update_id`.
592588
let _pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
593589
match self.persister.update_persisted_channel(monitor.persistence_key(), None, monitor)
594590
{
595-
ChannelMonitorUpdateStatus::Completed => log_trace!(
596-
logger,
597-
"Finished syncing Channel Monitor for channel {} for block-data",
598-
log_funding_info!(monitor)
599-
),
591+
ChannelMonitorUpdateStatus::Completed => {
592+
log_trace!(logger, "Finished syncing Channel Monitor for block-data")
593+
},
600594
ChannelMonitorUpdateStatus::InProgress => {
601595
log_trace!(
602596
logger,
@@ -961,16 +955,12 @@ where
961955
}
962956
if have_monitors_to_prune {
963957
let mut monitors = self.monitors.write().unwrap();
964-
monitors.retain(|channel_id, monitor_holder| {
958+
monitors.retain(|_channel_id, monitor_holder| {
965959
let logger = WithChannelMonitor::from(&self.logger, &monitor_holder.monitor, None);
966960
let (is_fully_resolved, _) =
967961
monitor_holder.monitor.check_and_update_full_resolution_status(&logger);
968962
if is_fully_resolved {
969-
log_info!(
970-
logger,
971-
"Archiving fully resolved ChannelMonitor for channel ID {}",
972-
channel_id
973-
);
963+
log_info!(logger, "Archiving fully resolved ChannelMonitor");
974964
self.persister
975965
.archive_persisted_channel(monitor_holder.monitor.persistence_key());
976966
false
@@ -1106,11 +1096,7 @@ where
11061096
},
11071097
hash_map::Entry::Vacant(e) => e,
11081098
};
1109-
log_trace!(
1110-
logger,
1111-
"Loaded existing ChannelMonitor for channel {}",
1112-
log_funding_info!(monitor)
1113-
);
1099+
log_trace!(logger, "Loaded existing ChannelMonitor");
11141100
if let Some(ref chain_source) = self.chain_source {
11151101
monitor.load_outputs_to_watch(chain_source, &self.logger);
11161102
}
@@ -1366,25 +1352,17 @@ where
13661352
},
13671353
hash_map::Entry::Vacant(e) => e,
13681354
};
1369-
log_trace!(logger, "Got new ChannelMonitor for channel {}", log_funding_info!(monitor));
1355+
log_trace!(logger, "Got new ChannelMonitor");
13701356
let update_id = monitor.get_latest_update_id();
13711357
let mut pending_monitor_updates = Vec::new();
13721358
let persist_res = self.persister.persist_new_channel(monitor.persistence_key(), &monitor);
13731359
match persist_res {
13741360
ChannelMonitorUpdateStatus::InProgress => {
1375-
log_info!(
1376-
logger,
1377-
"Persistence of new ChannelMonitor for channel {} in progress",
1378-
log_funding_info!(monitor)
1379-
);
1361+
log_info!(logger, "Persistence of new ChannelMonitor in progress",);
13801362
pending_monitor_updates.push(update_id);
13811363
},
13821364
ChannelMonitorUpdateStatus::Completed => {
1383-
log_info!(
1384-
logger,
1385-
"Persistence of new ChannelMonitor for channel {} completed",
1386-
log_funding_info!(monitor)
1387-
);
1365+
log_info!(logger, "Persistence of new ChannelMonitor completed",);
13881366
},
13891367
ChannelMonitorUpdateStatus::UnrecoverableError => {
13901368
let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";
@@ -1426,12 +1404,7 @@ where
14261404
Some(monitor_state) => {
14271405
let monitor = &monitor_state.monitor;
14281406
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
1429-
log_trace!(
1430-
logger,
1431-
"Updating ChannelMonitor to id {} for channel {}",
1432-
update.update_id,
1433-
log_funding_info!(monitor)
1434-
);
1407+
log_trace!(logger, "Updating ChannelMonitor to id {}", update.update_id,);
14351408

14361409
// We hold a `pending_monitor_updates` lock through `update_monitor` to ensure we
14371410
// have well-ordered updates from the users' point of view. See the
@@ -1452,7 +1425,7 @@ where
14521425
// We don't want to persist a `monitor_update` which results in a failure to apply later
14531426
// while reading `channel_monitor` with updates from storage. Instead, we should persist
14541427
// the entire `channel_monitor` here.
1455-
log_warn!(logger, "Failed to update ChannelMonitor for channel {}. Going ahead and persisting the entire ChannelMonitor", log_funding_info!(monitor));
1428+
log_warn!(logger, "Failed to update ChannelMonitor. Going ahead and persisting the entire ChannelMonitor");
14561429
self.persister.update_persisted_channel(
14571430
monitor.persistence_key(),
14581431
None,
@@ -1468,18 +1441,17 @@ where
14681441
match persist_res {
14691442
ChannelMonitorUpdateStatus::InProgress => {
14701443
pending_monitor_updates.push(update_id);
1471-
log_debug!(logger,
1472-
"Persistence of ChannelMonitorUpdate id {:?} for channel {} in progress",
1444+
log_debug!(
1445+
logger,
1446+
"Persistence of ChannelMonitorUpdate id {:?} in progress",
14731447
update_id,
1474-
log_funding_info!(monitor)
14751448
);
14761449
},
14771450
ChannelMonitorUpdateStatus::Completed => {
14781451
log_debug!(
14791452
logger,
1480-
"Persistence of ChannelMonitorUpdate id {:?} for channel {} completed",
1453+
"Persistence of ChannelMonitorUpdate id {:?} completed",
14811454
update_id,
1482-
log_funding_info!(monitor)
14831455
);
14841456
},
14851457
ChannelMonitorUpdateStatus::UnrecoverableError => {

lightning/src/chain/channelmonitor.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,8 +4223,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42234223
log_info!(logger, "Applying pre-0.1 force close update to monitor {} with {} change(s).",
42244224
log_funding_info!(self), updates.updates.len());
42254225
} else {
4226-
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} change(s).",
4227-
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
4226+
log_info!(logger, "Applying update, bringing update_id from {} to {} with {} change(s).",
4227+
self.latest_update_id, updates.update_id, updates.updates.len());
42284228
}
42294229

42304230
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
@@ -4351,7 +4351,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
43514351
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger, true);
43524352
} else if !self.holder_tx_signed {
43534353
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
4354-
log_error!(logger, " in channel monitor for channel {}!", &self.channel_id());
4354+
log_error!(logger, " in channel monitor!");
43554355
log_error!(logger, " Read the docs for ChannelMonitor::broadcast_latest_holder_commitment_txn to take manual action!");
43564356
} else {
43574357
// If we generated a MonitorEvent::HolderForceClosed, the ChannelManager
@@ -5479,7 +5479,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
54795479
} else {
54805480
"".to_string()
54815481
};
5482-
log_info!(logger, "{desc} for channel {} confirmed with txid {txid}{action}", self.channel_id());
5482+
log_info!(logger, "{desc} confirmed with txid {txid}{action}");
54835483

54845484
self.alternative_funding_confirmed = Some((txid, height));
54855485

@@ -5531,8 +5531,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55315531
.map(|(txid, _)| txid)
55325532
.unwrap_or_else(|| self.funding.funding_txid())
55335533
);
5534-
log_info!(logger, "Channel {} closed by funding output spend in txid {txid}",
5535-
self.channel_id());
5534+
log_info!(logger, "Channel closed by funding output spend in txid {txid}");
55365535
if !self.funding_spend_seen {
55375536
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(()));
55385537
}

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ fn test_monitor_and_persister_update_fail() {
150150
}
151151
logger.assert_log_regex(
152152
"lightning::chain::chainmonitor",
153-
regex::Regex::new("Failed to update ChannelMonitor for channel [0-9a-f]*.")
154-
.unwrap(),
153+
regex::Regex::new("Failed to update ChannelMonitor").unwrap(),
155154
1,
156155
);
157156

0 commit comments

Comments
 (0)