Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offers: wait for offers invoice #84

Closed
wants to merge 8 commits into from
12 changes: 11 additions & 1 deletion src/lndk_offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn request_invoice<OMH: OnionMessageHandler + SendOnion>(
custom_msg_client: impl SendCustomMessage,
offer: Offer,
introduction_node: PublicKey,
reply_path: BlindedPath,
blinded_path: BlindedPath,
) -> Result<(), OfferError<Secp256k1Error>> {
// Double check that the introduction node we need to connect to actually supports onion messaging.
Expand All @@ -80,12 +81,14 @@ pub async fn request_invoice<OMH: OnionMessageHandler + SendOnion>(
create_invoice_request(client.clone(), offer, vec![], Network::Regtest, 20000)
.await
.expect("should build invoice request");

send_invoice_request(
Network::Regtest,
invoice_request,
onion_messenger,
vec![introduction_node],
blinded_path,
reply_path,
custom_msg_client,
)
.await
Expand Down Expand Up @@ -152,6 +155,7 @@ pub async fn send_invoice_request<OMH: OnionMessageHandler + SendOnion>(
onion_messenger: &OMH,
intermediate_nodes: Vec<PublicKey>,
blinded_path: BlindedPath,
reply_path: BlindedPath,
mut custom_msg_client: impl SendCustomMessage,
) -> Result<(), OfferError<bitcoin::secp256k1::Error>> {
// We need to make sure our local onion messenger is connected to the needed local peers in
Expand Down Expand Up @@ -181,7 +185,7 @@ pub async fn send_invoice_request<OMH: OnionMessageHandler + SendOnion>(
let contents = OffersMessage::InvoiceRequest(invoice_request);

onion_messenger
.send_onion(path, contents, None)
.send_onion(path, contents, Some(reply_path))
.map_err(OfferError::<Secp256k1Error>::SendError)?;

let onion_message = onion_messenger
Expand Down Expand Up @@ -471,6 +475,7 @@ mod tests {

let invoice_request = get_invoice_request();
let blinded_path = get_blinded_path();
let reply_path = get_blinded_path();
let pubkey = PublicKey::from_str(&get_pubkey()).unwrap();

assert!(send_invoice_request(
Expand All @@ -479,6 +484,7 @@ mod tests {
onion_mock,
vec![pubkey],
blinded_path,
reply_path,
sender_mock
)
.await
Expand Down Expand Up @@ -506,6 +512,7 @@ mod tests {

let invoice_request = get_invoice_request();
let blinded_path = get_blinded_path();
let reply_path = get_blinded_path();
let pubkey = PublicKey::from_str(&get_pubkey()).unwrap();

assert!(send_invoice_request(
Expand All @@ -514,6 +521,7 @@ mod tests {
onion_mock,
vec![pubkey],
blinded_path,
reply_path,
sender_mock
)
.await
Expand Down Expand Up @@ -543,6 +551,7 @@ mod tests {

let invoice_request = get_invoice_request();
let blinded_path = get_blinded_path();
let reply_path = get_blinded_path();
let pubkey = PublicKey::from_str(&get_pubkey()).unwrap();

assert!(send_invoice_request(
Expand All @@ -551,6 +560,7 @@ mod tests {
onion_mock,
vec![pubkey],
blinded_path,
reply_path,
sender_mock
)
.await
Expand Down
8 changes: 6 additions & 2 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod common;
use lndk;

use bitcoin::secp256k1::PublicKey;
use bitcoin::secp256k1::{PublicKey, Secp256k1};
use bitcoin::Network;
use ldk_sample::node_api::Node as LdkNode;
use lightning::blinded_path::BlindedPath;
use lightning::ln::peer_handler::IgnoringMessageHandler;
use lightning::offers::offer::Quantity;
use lightning::onion_message::{DefaultMessageRouter, OnionMessenger};
Expand Down Expand Up @@ -168,12 +169,15 @@ async fn test_lndk_send_invoice_request() {
client: client_clone.lightning().to_owned(),
};
let blinded_path = offer.paths()[0].clone();
let secp_ctx = Secp256k1::new();
let reply_path =
BlindedPath::new_for_message(&[pubkey_2, lnd_pubkey], &messenger_utils, &secp_ctx).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be included in #81?

select! {
val = lndk::run(lndk_cfg) => {
panic!("lndk should not have completed first {:?}", val);
},
// Make sure lndk successfully sends the invoice_request.
res = request_invoice(client, &onion_messenger, custom_msg_client, offer, pubkey_2, blinded_path) => {
res = request_invoice(client, &onion_messenger, custom_msg_client, offer, pubkey_2, reply_path, blinded_path) => {
assert!(res.is_ok());

ldk1.stop().await;
Expand Down