Skip to content

Commit 7bc5d46

Browse files
committed
f - logging for phantom invoice creation
1 parent d0e9fd6 commit 7bc5d46

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

lightning-invoice/src/utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ where
135135
CreationError::MissingRouteHints,
136136
));
137137
}
138+
138139
let invoice = match description {
139140
InvoiceDescription::Direct(description) => {
140141
InvoiceBuilder::new(network).description(description.0.clone())
@@ -171,6 +172,9 @@ where
171172
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
172173
};
173174

175+
log_debug!(logger, "Creating phantom invoice from {} participating nodes with payment hash {}",
176+
phantom_route_hints.len(), log_bytes!(payment_hash.0));
177+
174178
let mut invoice = invoice
175179
.current_timestamp()
176180
.payment_hash(Hash::from_slice(&payment_hash.0).unwrap())
@@ -182,6 +186,8 @@ where
182186
}
183187

184188
for PhantomRouteHints { channels, phantom_scid, real_node_pubkey } in phantom_route_hints {
189+
log_debug!(logger, "Generating phantom route hints for node {}",
190+
log_pubkey!(real_node_pubkey));
185191
let mut route_hints = filter_channels(channels, amt_msat, &logger);
186192

187193
// If we have any public channel, the route hints from `filter_channels` will be empty.
@@ -418,7 +424,7 @@ fn filter_channels<L: Deref>(
418424
if channel.is_public {
419425
// If any public channel exists, return no hints and let the sender
420426
// look at the public channels instead.
421-
log_debug!(logger, "Not including invoice route hints on account of public channel {}",
427+
log_debug!(logger, "Not including channels in invoice route hints on account of public channel {}",
422428
log_bytes!(channel.channel_id));
423429
return vec![]
424430
}

lightning/src/util/logger.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//! The second one, client-side by implementing check against Record Level field.
1515
//! Each module may have its own Logger or share one.
1616
17+
use bitcoin::secp256k1::PublicKey;
18+
1719
use core::cmp;
1820
use core::fmt;
1921

@@ -138,6 +140,19 @@ pub trait Logger {
138140
fn log(&self, record: &Record);
139141
}
140142

143+
/// Wrapper for logging a [`PublicKey`] in hex format.
144+
/// (C-not exported) as fmt can't be used in C
145+
#[doc(hidden)]
146+
pub struct DebugPubKey<'a>(pub &'a PublicKey);
147+
impl<'a> core::fmt::Display for DebugPubKey<'a> {
148+
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
149+
for i in self.0.serialize().iter() {
150+
write!(f, "{:02x}", i)?;
151+
}
152+
Ok(())
153+
}
154+
}
155+
141156
/// Wrapper for logging byte slices in hex format.
142157
/// (C-not exported) as fmt can't be used in C
143158
#[doc(hidden)]

lightning/src/util/macro_logger.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,16 @@ use chain::keysinterface::SpendableOutputDescriptor;
1212

1313
use bitcoin::hash_types::Txid;
1414
use bitcoin::blockdata::transaction::Transaction;
15-
use bitcoin::secp256k1::PublicKey;
1615

1716
use routing::router::Route;
1817
use ln::chan_utils::HTLCClaim;
1918
use util::logger::DebugBytes;
2019

21-
pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey);
22-
impl<'a> core::fmt::Display for DebugPubKey<'a> {
23-
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
24-
for i in self.0.serialize().iter() {
25-
write!(f, "{:02x}", i)?;
26-
}
27-
Ok(())
28-
}
29-
}
20+
/// Logs a pubkey in hex format.
21+
#[macro_export]
3022
macro_rules! log_pubkey {
3123
($obj: expr) => {
32-
::util::macro_logger::DebugPubKey(&$obj)
24+
$crate::util::logger::DebugPubKey(&$obj)
3325
}
3426
}
3527

0 commit comments

Comments
 (0)