]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Generate random `PaymentId` for outbound offers
authorElias Rohrer <dev@tnull.de>
Fri, 8 Mar 2024 13:32:39 +0000 (14:32 +0100)
committerElias Rohrer <dev@tnull.de>
Fri, 8 Mar 2024 13:32:39 +0000 (14:32 +0100)
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

index a70d772769e931bed7e7bfd5312b97136ec646b6..b9fbf77bb7314b7e19e2d6b6c0177f31c868b944 100644 (file)
@@ -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,