Skip to content

Commit 4146264

Browse files
committed
Use Display of PaymentId&PaymentPreimage; avoid log_bytes macro
1 parent b35b8cf commit 4146264

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

lightning/src/ln/channelmanager.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -6331,10 +6331,10 @@ where
63316331
match monitor_event {
63326332
MonitorEvent::HTLCEvent(htlc_update) => {
63336333
if let Some(preimage) = htlc_update.payment_preimage {
6334-
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
6334+
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", &preimage);
63356335
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
63366336
} else {
6337-
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
6337+
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", &htlc_update.payment_hash);
63386338
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
63396339
let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
63406340
self.fail_htlc_backwards_internal(&htlc_update.source, &htlc_update.payment_hash, &reason, receiver);
@@ -10551,8 +10551,12 @@ mod tests {
1055110551

1055210552
#[test]
1055310553
fn test_payment_display() {
10554+
let payment_id = PaymentId([42; 32]);
10555+
assert_eq!(format!("{}", &payment_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
1055410556
let payment_hash = PaymentHash([42; 32]);
1055510557
assert_eq!(format!("{}", &payment_hash), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
10558+
let payment_preimage = PaymentPreimage([42; 32]);
10559+
assert_eq!(format!("{}", &payment_preimage), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
1055610560
}
1055710561
}
1055810562

lightning/src/ln/outbound_payment.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl OutboundPayments {
739739

740740
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
741741
onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
742-
log_info!(logger, "Result sending payment with id {}: {:?}", log_bytes!(payment_id.0), res);
742+
log_info!(logger, "Result sending payment with id {}: {:?}", &payment_id, res);
743743
if let Err(e) = res {
744744
self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path);
745745
}
@@ -762,7 +762,7 @@ impl OutboundPayments {
762762
{
763763
#[cfg(feature = "std")] {
764764
if has_expired(&route_params) {
765-
log_error!(logger, "Payment params expired on retry, abandoning payment {}", log_bytes!(payment_id.0));
765+
log_error!(logger, "Payment params expired on retry, abandoning payment {}", &payment_id);
766766
self.abandon_payment(payment_id, PaymentFailureReason::PaymentExpired, pending_events);
767767
return
768768
}
@@ -775,7 +775,7 @@ impl OutboundPayments {
775775
) {
776776
Ok(route) => route,
777777
Err(e) => {
778-
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", log_bytes!(payment_id.0), e);
778+
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", &payment_id, e);
779779
self.abandon_payment(payment_id, PaymentFailureReason::RouteNotFound, pending_events);
780780
return
781781
}
@@ -844,7 +844,7 @@ impl OutboundPayments {
844844
},
845845
};
846846
if !payment.get().is_retryable_now() {
847-
log_error!(logger, "Retries exhausted for payment id {}", log_bytes!(payment_id.0));
847+
log_error!(logger, "Retries exhausted for payment id {}", &payment_id);
848848
abandon_with_entry!(payment, PaymentFailureReason::RetriesExhausted);
849849
return
850850
}
@@ -855,15 +855,15 @@ impl OutboundPayments {
855855
res
856856
},
857857
hash_map::Entry::Vacant(_) => {
858-
log_error!(logger, "Payment with ID {} not found", log_bytes!(payment_id.0));
858+
log_error!(logger, "Payment with ID {} not found", &payment_id);
859859
return
860860
}
861861
}
862862
};
863863
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
864864
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
865865
&send_payment_along_path);
866-
log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), res);
866+
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
867867
if let Err(e) = res {
868868
self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
869869
}
@@ -1215,7 +1215,7 @@ impl OutboundPayments {
12151215
}
12161216
}
12171217
} else {
1218-
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
1218+
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", &payment_preimage);
12191219
}
12201220
}
12211221

lightning/src/routing/gossip.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ impl NodeId {
8888

8989
impl fmt::Debug for NodeId {
9090
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91-
write!(f, "NodeId({})", log_bytes!(self.0))
91+
write!(f, "NodeId({})", crate::util::logger::DebugBytes(&self.0))
9292
}
9393
}
9494
impl fmt::Display for NodeId {
9595
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96-
write!(f, "{}", log_bytes!(self.0))
96+
crate::util::logger::DebugBytes(&self.0).fmt(f)
9797
}
9898
}
9999

@@ -899,7 +899,7 @@ impl ChannelInfo {
899899
impl fmt::Display for ChannelInfo {
900900
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
901901
write!(f, "features: {}, node_one: {}, one_to_two: {:?}, node_two: {}, two_to_one: {:?}",
902-
log_bytes!(self.features.encode()), log_bytes!(self.node_one.as_slice()), self.one_to_two, log_bytes!(self.node_two.as_slice()), self.two_to_one)?;
902+
log_bytes!(self.features.encode()), &self.node_one, self.one_to_two, &self.node_two, self.two_to_one)?;
903903
Ok(())
904904
}
905905
}
@@ -1350,7 +1350,7 @@ impl<L: Deref> fmt::Display for NetworkGraph<L> where L::Target: Logger {
13501350
}
13511351
writeln!(f, "[Nodes]")?;
13521352
for (&node_id, val) in self.nodes.read().unwrap().unordered_iter() {
1353-
writeln!(f, " {}: {}", log_bytes!(node_id.as_slice()), val)?;
1353+
writeln!(f, " {}: {}", &node_id, val)?;
13541354
}
13551355
Ok(())
13561356
}
@@ -3429,6 +3429,12 @@ pub(crate) mod tests {
34293429
// This serialized info has an address field but no announcement_message, therefore the addresses returned by our function will still be empty
34303430
assert!(ann_info_with_addresses.addresses().is_empty());
34313431
}
3432+
3433+
#[test]
3434+
fn test_node_id_display() {
3435+
let node_id = NodeId([42; 33]);
3436+
assert_eq!(format!("{}", &node_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
3437+
}
34323438
}
34333439

34343440
#[cfg(ldk_bench)]

0 commit comments

Comments
 (0)