Skip to content

Commit 94cadd5

Browse files
include the bolt12_invoice inside the htlc hash
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 4403787 commit 94cadd5

File tree

8 files changed

+16577
-11
lines changed

8 files changed

+16577
-11
lines changed

lightning/src/events/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ impl<T: EventHandler> EventHandler for Arc<T> {
24572457
}
24582458

24592459
/// The BOLT 12 invoice that was paid, surfaced in [`Event::PaymentSent::bolt12_invoice`].
2460-
#[derive(Clone, Debug, PartialEq, Eq)]
2460+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
24612461
pub enum PaidBolt12Invoice {
24622462
/// The BOLT 12 invoice specified by the BOLT 12 specification,
24632463
/// allowing the user to perform proof of payment.

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,13 @@ impl core::hash::Hash for HTLCSource {
709709
0u8.hash(hasher);
710710
prev_hop_data.hash(hasher);
711711
},
712-
// FIXME(vincenzopalazzo): we can ignore the bolt12_invoice here?
713-
HTLCSource::OutboundRoute { path, session_priv, payment_id, first_hop_htlc_msat, .. } => {
712+
HTLCSource::OutboundRoute { path, session_priv, payment_id, first_hop_htlc_msat, bolt12_invoice } => {
714713
1u8.hash(hasher);
715714
path.hash(hasher);
716715
session_priv[..].hash(hasher);
717716
payment_id.hash(hasher);
718717
first_hop_htlc_msat.hash(hasher);
718+
bolt12_invoice.hash(hasher);
719719
},
720720
}
721721
}

lightning/src/ln/channelmanager.rs.bak

+16,559
Large diffs are not rendered by default.

lightning/src/offers/invoice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ pub(super) type BlindedPayInfoIter<'a> = core::iter::Map<
14951495
>;
14961496

14971497
/// Wire representation for an on-chain fallback address.
1498-
#[derive(Clone, Debug, PartialEq)]
1498+
#[derive(Clone, Debug, PartialEq, Hash)]
14991499
pub(super) struct FallbackAddress {
15001500
pub(super) version: u8,
15011501
pub(super) program: Vec<u8>,

lightning/src/offers/nonce.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::prelude::*;
2626
/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
2727
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
2828
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
29-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
29+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
3030
pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
3131

3232
impl Nonce {

lightning/src/offers/offer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ pub struct Offer {
604604
///
605605
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
606606
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
607-
#[derive(Clone, Debug)]
607+
#[derive(Clone, Debug, Hash)]
608608
#[cfg_attr(test, derive(PartialEq))]
609609
pub(super) struct OfferContents {
610610
chains: Option<Vec<ChainHash>>,
@@ -1059,7 +1059,7 @@ impl Writeable for OfferContents {
10591059

10601060
/// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
10611061
/// another currency.
1062-
#[derive(Clone, Copy, Debug, PartialEq)]
1062+
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
10631063
pub enum Amount {
10641064
/// An amount of bitcoin.
10651065
Bitcoin {
@@ -1079,7 +1079,7 @@ pub enum Amount {
10791079
pub type CurrencyCode = [u8; 3];
10801080

10811081
/// Quantity of items supported by an [`Offer`].
1082-
#[derive(Clone, Copy, Debug, PartialEq)]
1082+
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
10831083
pub enum Quantity {
10841084
/// Up to a specific number of items (inclusive). Use when more than one item can be requested
10851085
/// but is limited (e.g., because of per customer or inventory limits).

lightning/src/offers/signer.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ASYNC_PAYMENTS_HELD_HTLC_HMAC_INPUT: &[u8; 16] = &[9; 16];
5757

5858
/// Message metadata which possibly is derived from [`MetadataMaterial`] such that it can be
5959
/// verified.
60-
#[derive(Clone)]
60+
#[derive(Clone, Hash)]
6161
pub(super) enum Metadata {
6262
/// Metadata as parsed, supplied by the user, or derived from the message contents.
6363
///
@@ -263,6 +263,13 @@ pub(super) struct MetadataMaterial {
263263
encrypted_payment_id: Option<[u8; PaymentId::LENGTH]>,
264264
}
265265

266+
impl std::hash::Hash for MetadataMaterial {
267+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
268+
self.nonce.hash(state);
269+
self.encrypted_payment_id.hash(state);
270+
}
271+
}
272+
266273
impl MetadataMaterial {
267274
pub fn new(nonce: Nonce, expanded_key: &ExpandedKey, payment_id: Option<PaymentId>) -> Self {
268275
// Encrypt payment_id

lightning/src/offers/static_invoice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub const SIGNATURE_TAG: &'static str = concat!("lightning", "static_invoice", "
6565
/// [`Offer`]: crate::offers::offer::Offer
6666
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6767
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
68-
#[derive(Clone, Debug)]
68+
#[derive(Clone, Debug, Hash)]
6969
pub struct StaticInvoice {
7070
bytes: Vec<u8>,
7171
contents: InvoiceContents,
@@ -83,7 +83,7 @@ impl Eq for StaticInvoice {}
8383
/// The contents of a [`StaticInvoice`] for responding to an [`Offer`].
8484
///
8585
/// [`Offer`]: crate::offers::offer::Offer
86-
#[derive(Clone, Debug)]
86+
#[derive(Clone, Debug, Hash)]
8787
struct InvoiceContents {
8888
offer: OfferContents,
8989
payment_paths: Vec<BlindedPaymentPath>,

0 commit comments

Comments
 (0)