From 4a1a645819fa18609ccaf9f6a9c4ddfd55519dd5 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Fri, 8 Mar 2024 14:32:39 +0100 Subject: [PATCH 1/2] Generate random `PaymentId` for outbound offers Previously, we'd deterministically derive the `offer_hash` as a `PaymentId` for outbound BOLT 12 payments. However, as offers may be paid multiple times, this could result in collisions in our `outbound_payments` store. Here, we therefore use random `PaymentId`s to avoid collisions, even if offers are paid multiple times. --- src/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a70d772..b9fbf77 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -175,8 +175,8 @@ pub(crate) fn poll_for_user_input( } if let Ok(offer) = Offer::from_str(invoice_str.unwrap()) { - let offer_hash = Sha256::hash(invoice_str.unwrap().as_bytes()); - let payment_id = PaymentId(*offer_hash.as_ref()); + let random_bytes = keys_manager.get_secure_random_bytes(); + let payment_id = PaymentId(random_bytes); let amt_msat = match (offer.amount(), user_provided_amt) { (Some(offer::Amount::Bitcoin { amount_msats }), _) => *amount_msats, From f58bb8471fcd2be32afbf95ccefee6d4538ae6e5 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Fri, 8 Mar 2024 14:35:19 +0100 Subject: [PATCH 2/2] Fix warning by including error in error prompt --- src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index b9fbf77..04c5898 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -818,7 +818,7 @@ fn send_payment( let (payment_hash, recipient_onion, route_params) = match pay_params_opt { Ok(res) => res, Err(e) => { - println!("Failed to parse invoice"); + println!("Failed to parse invoice: {:?}", e); print!("> "); return; }