Skip to content

Commit 46cdcc5

Browse files
committed
Simplifying logging/formatting by adding Display trait
1 parent ccd48d0 commit 46cdcc5

File tree

9 files changed

+144
-136
lines changed

9 files changed

+144
-136
lines changed

lightning-invoice/src/utils.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ where
627627
log_trace!(logger, "Considering {} channels for invoice route hints", channels.len());
628628
for channel in channels.into_iter().filter(|chan| chan.is_channel_ready) {
629629
if channel.get_inbound_payment_scid().is_none() || channel.counterparty.forwarding_info.is_none() {
630-
log_trace!(logger, "Ignoring channel {} for invoice route hints", log_bytes!(channel.channel_id.bytes()[..]));
630+
log_trace!(logger, "Ignoring channel {} for invoice route hints", &channel.channel_id);
631631
continue;
632632
}
633633

@@ -641,7 +641,7 @@ where
641641
// If any public channel exists, return no hints and let the sender
642642
// look at the public channels instead.
643643
log_trace!(logger, "Not including channels in invoice route hints on account of public channel {}",
644-
log_bytes!(channel.channel_id.bytes()[..]));
644+
&channel.channel_id);
645645
return vec![].into_iter().take(MAX_CHANNEL_HINTS).map(route_hint_from_channel);
646646
}
647647
}
@@ -681,18 +681,18 @@ where
681681
log_trace!(logger,
682682
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
683683
log_pubkey!(channel.counterparty.node_id),
684-
log_bytes!(channel.channel_id.bytes()[..]), channel.short_channel_id,
684+
&channel.channel_id, channel.short_channel_id,
685685
channel.inbound_capacity_msat,
686-
log_bytes!(entry.get().channel_id.bytes()[..]), entry.get().short_channel_id,
686+
&entry.get().channel_id, entry.get().short_channel_id,
687687
current_max_capacity);
688688
entry.insert(channel);
689689
} else {
690690
log_trace!(logger,
691691
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
692692
log_pubkey!(channel.counterparty.node_id),
693-
log_bytes!(entry.get().channel_id.bytes()[..]), entry.get().short_channel_id,
693+
&entry.get().channel_id, entry.get().short_channel_id,
694694
current_max_capacity,
695-
log_bytes!(channel.channel_id.bytes()[..]), channel.short_channel_id,
695+
&channel.channel_id, channel.short_channel_id,
696696
channel.inbound_capacity_msat);
697697
}
698698
}
@@ -731,14 +731,14 @@ where
731731

732732
if include_channel {
733733
log_trace!(logger, "Including channel {} in invoice route hints",
734-
log_bytes!(channel.channel_id.bytes()[..]));
734+
&channel.channel_id);
735735
} else if !has_enough_capacity {
736736
log_trace!(logger, "Ignoring channel {} without enough capacity for invoice route hints",
737-
log_bytes!(channel.channel_id.bytes()[..]));
737+
&channel.channel_id);
738738
} else {
739739
debug_assert!(!channel.is_usable || (has_pub_unconf_chan && !channel.is_public));
740740
log_trace!(logger, "Ignoring channel {} with disconnected peer",
741-
log_bytes!(channel.channel_id.bytes()[..]));
741+
&channel.channel_id);
742742
}
743743

744744
include_channel

lightning/src/chain/channelmonitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25252525
}
25262526
} else if !self.holder_tx_signed {
25272527
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
2528-
log_error!(logger, " in channel monitor for channel {}!", log_bytes!(self.funding_info.0.to_channel_id().bytes()[..]));
2528+
log_error!(logger, " in channel monitor for channel {}!", &self.funding_info.0.to_channel_id());
25292529
log_error!(logger, " Read the docs for ChannelMonitor::get_latest_holder_commitment_txn and take manual action!");
25302530
} else {
25312531
// If we generated a MonitorEvent::CommitmentTxConfirmed, the ChannelManager
@@ -3183,7 +3183,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31833183
if prevout.txid == self.funding_info.0.txid && prevout.vout == self.funding_info.0.index as u32 {
31843184
let mut balance_spendable_csv = None;
31853185
log_info!(logger, "Channel {} closed by funding output spend in txid {}.",
3186-
log_bytes!(self.funding_info.0.to_channel_id().bytes()[..]), txid);
3186+
&self.funding_info.0.to_channel_id(), txid);
31873187
self.funding_spend_seen = true;
31883188
let mut commitment_tx_to_counterparty_output = None;
31893189
if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.0 >> 8*3) as u8 == 0x20 {

lightning/src/ln/channel.rs

+59-47
Large diffs are not rendered by default.

lightning/src/ln/channelmanager.rs

+46-46
Large diffs are not rendered by default.

lightning/src/ln/functional_test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ macro_rules! get_monitor {
860860
for index in 0..2 {
861861
if let Ok(mon) = $node.chain_monitor.chain_monitor.get_monitor(
862862
$crate::chain::transaction::OutPoint {
863-
txid: bitcoin::Txid::from_slice(&$channel_id.bytes()[..][..]).unwrap(), index
863+
txid: bitcoin::Txid::from_slice(&$channel_id.bytes()[..]).unwrap(), index
864864
})
865865
{
866866
monitor = Some(mon);

lightning/src/ln/functional_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ fn test_fee_spike_violation_fails_htlc() {
15061506
_ => panic!("Unexpected event"),
15071507
};
15081508
nodes[1].logger.assert_log("lightning::ln::channel".to_string(),
1509-
format!("Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", ::hex::encode(raa_msg.channel_id.bytes())), 1);
1509+
format!("Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", raa_msg.channel_id), 1);
15101510

15111511
check_added_monitors!(nodes[1], 2);
15121512
}
@@ -8003,7 +8003,7 @@ fn test_can_not_accept_unknown_inbound_channel() {
80038003
let api_res = nodes[0].node.accept_inbound_channel(&unknown_channel_id, &nodes[1].node.get_our_node_id(), 0);
80048004
match api_res {
80058005
Err(APIError::ChannelUnavailable { err }) => {
8006-
assert_eq!(err, format!("Channel with id {} not found for the passed counterparty node_id {}", log_bytes!(unknown_channel_id.bytes()[..]), nodes[1].node.get_our_node_id()));
8006+
assert_eq!(err, format!("Channel with id {} not found for the passed counterparty node_id {}", &unknown_channel_id, nodes[1].node.get_our_node_id()));
80078007
},
80088008
Ok(_) => panic!("It shouldn't be possible to accept an unkown channel"),
80098009
Err(_) => panic!("Unexpected Error"),

lightning/src/ln/payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
17321732
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
17331733
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable {
17341734
err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.",
1735-
log_bytes!(temp_chan_id.bytes()[..]), nodes[2].node.get_our_node_id()) });
1735+
&temp_chan_id, nodes[2].node.get_our_node_id()) });
17361736
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
17371737

17381738
// Open the just-in-time channel so the payment can then be forwarded.

lightning/src/ln/peer_handler.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1914,31 +1914,31 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
19141914
MessageSendEvent::SendAcceptChannel { ref node_id, ref msg } => {
19151915
log_debug!(self.logger, "Handling SendAcceptChannel event in peer_handler for node {} for channel {}",
19161916
log_pubkey!(node_id),
1917-
log_bytes!(msg.temporary_channel_id.bytes()[..]));
1917+
&msg.temporary_channel_id);
19181918
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19191919
},
19201920
MessageSendEvent::SendAcceptChannelV2 { ref node_id, ref msg } => {
19211921
log_debug!(self.logger, "Handling SendAcceptChannelV2 event in peer_handler for node {} for channel {}",
19221922
log_pubkey!(node_id),
1923-
log_bytes!(msg.temporary_channel_id.bytes()[..]));
1923+
&msg.temporary_channel_id);
19241924
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19251925
},
19261926
MessageSendEvent::SendOpenChannel { ref node_id, ref msg } => {
19271927
log_debug!(self.logger, "Handling SendOpenChannel event in peer_handler for node {} for channel {}",
19281928
log_pubkey!(node_id),
1929-
log_bytes!(msg.temporary_channel_id.bytes()[..]));
1929+
&msg.temporary_channel_id);
19301930
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19311931
},
19321932
MessageSendEvent::SendOpenChannelV2 { ref node_id, ref msg } => {
19331933
log_debug!(self.logger, "Handling SendOpenChannelV2 event in peer_handler for node {} for channel {}",
19341934
log_pubkey!(node_id),
1935-
log_bytes!(msg.temporary_channel_id.bytes()[..]));
1935+
&msg.temporary_channel_id);
19361936
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19371937
},
19381938
MessageSendEvent::SendFundingCreated { ref node_id, ref msg } => {
19391939
log_debug!(self.logger, "Handling SendFundingCreated event in peer_handler for node {} for channel {} (which becomes {})",
19401940
log_pubkey!(node_id),
1941-
log_bytes!(msg.temporary_channel_id.bytes()[..]),
1941+
&msg.temporary_channel_id,
19421942
log_funding_channel_id!(msg.funding_txid, msg.funding_output_index));
19431943
// TODO: If the peer is gone we should generate a DiscardFunding event
19441944
// indicating to the wallet that they should just throw away this funding transaction
@@ -1947,73 +1947,73 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
19471947
MessageSendEvent::SendFundingSigned { ref node_id, ref msg } => {
19481948
log_debug!(self.logger, "Handling SendFundingSigned event in peer_handler for node {} for channel {}",
19491949
log_pubkey!(node_id),
1950-
log_bytes!(msg.channel_id.bytes()[..]));
1950+
&msg.channel_id);
19511951
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19521952
},
19531953
MessageSendEvent::SendChannelReady { ref node_id, ref msg } => {
19541954
log_debug!(self.logger, "Handling SendChannelReady event in peer_handler for node {} for channel {}",
19551955
log_pubkey!(node_id),
1956-
log_bytes!(msg.channel_id.bytes()[..]));
1956+
&msg.channel_id);
19571957
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19581958
},
19591959
MessageSendEvent::SendTxAddInput { ref node_id, ref msg } => {
19601960
log_debug!(self.logger, "Handling SendTxAddInput event in peer_handler for node {} for channel {}",
19611961
log_pubkey!(node_id),
1962-
log_bytes!(msg.channel_id.bytes()[..]));
1962+
&msg.channel_id);
19631963
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19641964
},
19651965
MessageSendEvent::SendTxAddOutput { ref node_id, ref msg } => {
19661966
log_debug!(self.logger, "Handling SendTxAddOutput event in peer_handler for node {} for channel {}",
19671967
log_pubkey!(node_id),
1968-
log_bytes!(msg.channel_id.bytes()[..]));
1968+
&msg.channel_id);
19691969
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19701970
},
19711971
MessageSendEvent::SendTxRemoveInput { ref node_id, ref msg } => {
19721972
log_debug!(self.logger, "Handling SendTxRemoveInput event in peer_handler for node {} for channel {}",
19731973
log_pubkey!(node_id),
1974-
log_bytes!(msg.channel_id.bytes()[..]));
1974+
&msg.channel_id);
19751975
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19761976
},
19771977
MessageSendEvent::SendTxRemoveOutput { ref node_id, ref msg } => {
19781978
log_debug!(self.logger, "Handling SendTxRemoveOutput event in peer_handler for node {} for channel {}",
19791979
log_pubkey!(node_id),
1980-
log_bytes!(msg.channel_id.bytes()[..]));
1980+
&msg.channel_id);
19811981
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19821982
},
19831983
MessageSendEvent::SendTxComplete { ref node_id, ref msg } => {
19841984
log_debug!(self.logger, "Handling SendTxComplete event in peer_handler for node {} for channel {}",
19851985
log_pubkey!(node_id),
1986-
log_bytes!(msg.channel_id.bytes()[..]));
1986+
&msg.channel_id);
19871987
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19881988
},
19891989
MessageSendEvent::SendTxSignatures { ref node_id, ref msg } => {
19901990
log_debug!(self.logger, "Handling SendTxSignatures event in peer_handler for node {} for channel {}",
19911991
log_pubkey!(node_id),
1992-
log_bytes!(msg.channel_id.bytes()[..]));
1992+
&msg.channel_id);
19931993
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
19941994
},
19951995
MessageSendEvent::SendTxInitRbf { ref node_id, ref msg } => {
19961996
log_debug!(self.logger, "Handling SendTxInitRbf event in peer_handler for node {} for channel {}",
19971997
log_pubkey!(node_id),
1998-
log_bytes!(msg.channel_id.bytes()[..]));
1998+
&msg.channel_id);
19991999
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20002000
},
20012001
MessageSendEvent::SendTxAckRbf { ref node_id, ref msg } => {
20022002
log_debug!(self.logger, "Handling SendTxAckRbf event in peer_handler for node {} for channel {}",
20032003
log_pubkey!(node_id),
2004-
log_bytes!(msg.channel_id.bytes()[..]));
2004+
&msg.channel_id);
20052005
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20062006
},
20072007
MessageSendEvent::SendTxAbort { ref node_id, ref msg } => {
20082008
log_debug!(self.logger, "Handling SendTxAbort event in peer_handler for node {} for channel {}",
20092009
log_pubkey!(node_id),
2010-
log_bytes!(msg.channel_id.bytes()[..]));
2010+
&msg.channel_id);
20112011
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20122012
},
20132013
MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } => {
20142014
log_debug!(self.logger, "Handling SendAnnouncementSignatures event in peer_handler for node {} for channel {})",
20152015
log_pubkey!(node_id),
2016-
log_bytes!(msg.channel_id.bytes()[..]));
2016+
&msg.channel_id);
20172017
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20182018
},
20192019
MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
@@ -2022,7 +2022,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
20222022
update_add_htlcs.len(),
20232023
update_fulfill_htlcs.len(),
20242024
update_fail_htlcs.len(),
2025-
log_bytes!(commitment_signed.channel_id.bytes()[..]));
2025+
&commitment_signed.channel_id);
20262026
let mut peer = get_peer_for_forwarding!(node_id);
20272027
for msg in update_add_htlcs {
20282028
self.enqueue_message(&mut *peer, msg);
@@ -2044,25 +2044,25 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
20442044
MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
20452045
log_debug!(self.logger, "Handling SendRevokeAndACK event in peer_handler for node {} for channel {}",
20462046
log_pubkey!(node_id),
2047-
log_bytes!(msg.channel_id.bytes()[..]));
2047+
&msg.channel_id);
20482048
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20492049
},
20502050
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
20512051
log_debug!(self.logger, "Handling SendClosingSigned event in peer_handler for node {} for channel {}",
20522052
log_pubkey!(node_id),
2053-
log_bytes!(msg.channel_id.bytes()[..]));
2053+
&msg.channel_id);
20542054
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20552055
},
20562056
MessageSendEvent::SendShutdown { ref node_id, ref msg } => {
20572057
log_debug!(self.logger, "Handling Shutdown event in peer_handler for node {} for channel {}",
20582058
log_pubkey!(node_id),
2059-
log_bytes!(msg.channel_id.bytes()[..]));
2059+
&msg.channel_id);
20602060
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20612061
},
20622062
MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
20632063
log_debug!(self.logger, "Handling SendChannelReestablish event in peer_handler for node {} for channel {}",
20642064
log_pubkey!(node_id),
2065-
log_bytes!(msg.channel_id.bytes()[..]));
2065+
&msg.channel_id);
20662066
self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
20672067
},
20682068
MessageSendEvent::SendChannelAnnouncement { ref node_id, ref msg, ref update_msg } => {

lightning/src/util/macro_logger.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use bitcoin::blockdata::transaction::Transaction;
1515

1616
use crate::routing::router::Route;
1717
use crate::ln::chan_utils::HTLCClaim;
18-
use crate::util::logger::DebugBytes;
1918

2019
macro_rules! log_iter {
2120
($obj: expr) => {
@@ -42,10 +41,7 @@ macro_rules! log_bytes {
4241
pub(crate) struct DebugFundingChannelId<'a>(pub &'a Txid, pub u16);
4342
impl<'a> core::fmt::Display for DebugFundingChannelId<'a> {
4443
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
45-
for i in (OutPoint { txid: self.0.clone(), index: self.1 }).to_channel_id().bytes().iter() {
46-
write!(f, "{:02x}", i)?;
47-
}
48-
Ok(())
44+
(OutPoint { txid: self.0.clone(), index: self.1 }).to_channel_id().fmt(f)
4945
}
5046
}
5147
macro_rules! log_funding_channel_id {
@@ -57,7 +53,7 @@ macro_rules! log_funding_channel_id {
5753
pub(crate) struct DebugFundingInfo<'a, T: 'a>(pub &'a (OutPoint, T));
5854
impl<'a, T> core::fmt::Display for DebugFundingInfo<'a, T> {
5955
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
60-
DebugBytes(&(self.0).0.to_channel_id().bytes()[..][..]).fmt(f)
56+
(self.0).0.to_channel_id().fmt(f)
6157
}
6258
}
6359
macro_rules! log_funding_info {

0 commit comments

Comments
 (0)