From 7fb16ea20c53613f14378a57e4e552fb4ed78a1f Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 10 Jul 2024 14:58:11 -0400 Subject: [PATCH] Pass full message context into ChanMan blinded path util. Allows us to repurpose this util to create blinded paths in an async payments message context while maintaining support for the offers context. --- lightning/src/ln/channelmanager.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d88bf2c4c..c6cffaf10 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -9131,7 +9131,9 @@ where let invoice_request = builder.build_and_sign()?; let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key); - let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }; + let context = MessageContext::Offers( + OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) } + ); let reply_paths = self.create_blinded_paths(context) .map_err(|_| Bolt12SemanticError::MissingPaths)?; @@ -9251,9 +9253,9 @@ where let nonce = Nonce::from_entropy_source(entropy); let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key); - let context = OffersContext::InboundPayment { + let context = MessageContext::Offers(OffersContext::InboundPayment { payment_hash: invoice.payment_hash(), nonce, hmac - }; + }); let reply_paths = self.create_blinded_paths(context) .map_err(|_| Bolt12SemanticError::MissingPaths)?; @@ -9401,7 +9403,7 @@ where if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry { self.create_compact_blinded_paths(context) } else { - self.create_blinded_paths(context) + self.create_blinded_paths(MessageContext::Offers(context)) } } @@ -9422,7 +9424,7 @@ where /// [`MessageRouter::create_blinded_paths`]. /// /// Errors if the `MessageRouter` errors. - fn create_blinded_paths(&self, context: OffersContext) -> Result, ()> { + fn create_blinded_paths(&self, context: MessageContext) -> Result, ()> { let recipient = self.get_our_node_id(); let secp_ctx = &self.secp_ctx; @@ -9435,7 +9437,7 @@ where .collect::>(); self.router - .create_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx) + .create_blinded_paths(recipient, context, peers, secp_ctx) .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(())) } @@ -10839,11 +10841,11 @@ where { let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request; let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key); - let context = OffersContext::OutboundPayment { + let context = MessageContext::Offers(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) - }; + }); match self.create_blinded_paths(context) { Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) { Ok(_) => {} -- 2.39.5