Skip to content

Commit 6ab6894

Browse files
committed
Add logging to offers flow
1 parent 83f64a0 commit 6ab6894

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,9 +2527,9 @@ pub struct ChannelManager<
25272527
router: R,
25282528

25292529
#[cfg(test)]
2530-
pub(super) flow: OffersMessageFlow<MR>,
2530+
pub(super) flow: OffersMessageFlow<MR, L>,
25312531
#[cfg(not(test))]
2532-
flow: OffersMessageFlow<MR>,
2532+
flow: OffersMessageFlow<MR, L>,
25332533

25342534
/// See `ChannelManager` struct-level documentation for lock order requirements.
25352535
#[cfg(any(test, feature = "_test_utils"))]
@@ -3741,7 +3741,7 @@ where
37413741
let flow = OffersMessageFlow::new(
37423742
ChainHash::using_genesis_block(params.network), params.best_block,
37433743
our_network_pubkey, current_timestamp, expanded_inbound_key,
3744-
node_signer.get_receive_auth_key(), secp_ctx.clone(), message_router
3744+
node_signer.get_receive_auth_key(), secp_ctx.clone(), message_router, logger.clone(),
37453745
);
37463746

37473747
ChannelManager {
@@ -17068,6 +17068,7 @@ where
1706817068
args.node_signer.get_receive_auth_key(),
1706917069
secp_ctx.clone(),
1707017070
args.message_router,
17071+
args.logger.clone(),
1707117072
)
1707217073
.with_async_payments_offers_cache(async_receive_offer_cache);
1707317074

lightning/src/offers/flow.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use crate::sign::{EntropySource, NodeSigner, ReceiveAuthKey};
6262
use crate::offers::static_invoice::{StaticInvoice, StaticInvoiceBuilder};
6363
use crate::sync::{Mutex, RwLock};
6464
use crate::types::payment::{PaymentHash, PaymentSecret};
65+
use crate::util::logger::Logger;
6566
use crate::util::ser::Writeable;
6667

6768
#[cfg(feature = "dnssec")]
@@ -75,9 +76,10 @@ use {
7576
///
7677
/// [`OffersMessageFlow`] is parameterized by a [`MessageRouter`], which is responsible
7778
/// for finding message paths when initiating and retrying onion messages.
78-
pub struct OffersMessageFlow<MR: Deref>
79+
pub struct OffersMessageFlow<MR: Deref, L: Deref>
7980
where
8081
MR::Target: MessageRouter,
82+
L::Target: Logger,
8183
{
8284
chain_hash: ChainHash,
8385
best_block: RwLock<BestBlock>,
@@ -103,17 +105,21 @@ where
103105
pub(crate) hrn_resolver: OMNameResolver,
104106
#[cfg(feature = "dnssec")]
105107
pending_dns_onion_messages: Mutex<Vec<(DNSResolverMessage, MessageSendInstructions)>>,
108+
109+
logger: L,
106110
}
107111

108-
impl<MR: Deref> OffersMessageFlow<MR>
112+
impl<MR: Deref, L: Deref> OffersMessageFlow<MR, L>
109113
where
110114
MR::Target: MessageRouter,
115+
L::Target: Logger,
111116
{
112117
/// Creates a new [`OffersMessageFlow`]
113118
pub fn new(
114119
chain_hash: ChainHash, best_block: BestBlock, our_network_pubkey: PublicKey,
115120
current_timestamp: u32, inbound_payment_key: inbound_payment::ExpandedKey,
116121
receive_auth_key: ReceiveAuthKey, secp_ctx: Secp256k1<secp256k1::All>, message_router: MR,
122+
logger: L,
117123
) -> Self {
118124
Self {
119125
chain_hash,
@@ -137,6 +143,8 @@ where
137143
pending_dns_onion_messages: Mutex::new(Vec::new()),
138144

139145
async_receive_offer_cache: Mutex::new(AsyncReceiveOfferCache::new()),
146+
147+
logger,
140148
}
141149
}
142150

@@ -260,9 +268,10 @@ const DEFAULT_ASYNC_RECEIVE_OFFER_EXPIRY: Duration = Duration::from_secs(365 * 2
260268
pub(crate) const TEST_DEFAULT_ASYNC_RECEIVE_OFFER_EXPIRY: Duration =
261269
DEFAULT_ASYNC_RECEIVE_OFFER_EXPIRY;
262270

263-
impl<MR: Deref> OffersMessageFlow<MR>
271+
impl<MR: Deref, L: Deref> OffersMessageFlow<MR, L>
264272
where
265273
MR::Target: MessageRouter,
274+
L::Target: Logger,
266275
{
267276
/// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
268277
/// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
@@ -278,6 +287,7 @@ where
278287
peers: Vec<MessageForwardNode>,
279288
) -> Result<Vec<BlindedMessagePath>, ()> {
280289
if recipient_id.len() > 1024 {
290+
log_trace!(self.logger, "Async recipient ID exceeds 1024 bytes");
281291
return Err(());
282292
}
283293

@@ -409,9 +419,10 @@ pub enum InvreqResponseInstructions {
409419
},
410420
}
411421

412-
impl<MR: Deref> OffersMessageFlow<MR>
422+
impl<MR: Deref, L: Deref> OffersMessageFlow<MR, L>
413423
where
414424
MR::Target: MessageRouter,
425+
L::Target: Logger,
415426
{
416427
/// Verifies an [`InvoiceRequest`] using the provided [`OffersContext`] or the [`InvoiceRequest::metadata`].
417428
///
@@ -439,6 +450,7 @@ where
439450
path_absolute_expiry,
440451
}) => {
441452
if path_absolute_expiry < self.duration_since_epoch() {
453+
log_trace!(self.logger, "Static invoice request has expired");
442454
return Err(());
443455
}
444456

@@ -1281,6 +1293,10 @@ where
12811293
let reply_paths = match self.create_blinded_paths(peers, context) {
12821294
Ok(paths) => paths,
12831295
Err(()) => {
1296+
log_error!(
1297+
self.logger,
1298+
"Failed to create blinded paths for OfferPathsRequest message"
1299+
);
12841300
return Err(());
12851301
},
12861302
};
@@ -1399,7 +1415,13 @@ where
13991415

14001416
match self.create_blinded_paths(peers, context) {
14011417
Ok(paths) => (paths, path_absolute_expiry),
1402-
Err(()) => return None,
1418+
Err(()) => {
1419+
log_error!(
1420+
self.logger,
1421+
"Failed to create blinded paths for OfferPaths message"
1422+
);
1423+
return None;
1424+
},
14031425
}
14041426
};
14051427

@@ -1473,6 +1495,7 @@ where
14731495
let (offer_id, offer) = match offer_builder.build() {
14741496
Ok(offer) => (offer.id(), offer),
14751497
Err(_) => {
1498+
log_error!(self.logger, "Failed to build async receive offer");
14761499
debug_assert!(false);
14771500
return None;
14781501
},
@@ -1487,7 +1510,10 @@ where
14871510
router,
14881511
) {
14891512
Ok(res) => res,
1490-
Err(()) => return None,
1513+
Err(()) => {
1514+
log_error!(self.logger, "Failed to create static invoice for server");
1515+
return None;
1516+
},
14911517
};
14921518

14931519
if let Err(()) = self.async_receive_offer_cache.lock().unwrap().cache_pending_offer(
@@ -1498,6 +1524,7 @@ where
14981524
duration_since_epoch,
14991525
invoice_slot,
15001526
) {
1527+
log_error!(self.logger, "Failed to cache pending offer");
15011528
return None;
15021529
}
15031530

@@ -1581,6 +1608,7 @@ where
15811608
&self, message: &ServeStaticInvoice, context: AsyncPaymentsContext,
15821609
) -> Result<(Vec<u8>, u16), ()> {
15831610
if message.invoice.is_expired_no_std(self.duration_since_epoch()) {
1611+
log_trace!(self.logger, "Received expired StaticInvoice");
15841612
return Err(());
15851613
}
15861614
if message.invoice.serialized_length() > MAX_STATIC_INVOICE_SIZE_BYTES {
@@ -1593,6 +1621,7 @@ where
15931621
path_absolute_expiry,
15941622
} => {
15951623
if self.duration_since_epoch() > path_absolute_expiry {
1624+
log_trace!(self.logger, "Received expired StaticInvoice path");
15961625
return Err(());
15971626
}
15981627

0 commit comments

Comments
 (0)