Skip to content

Commit

Permalink
Merge pull request #3140 from valentinewallace/2024-06-pay-static-inv…
Browse files Browse the repository at this point in the history
…oice

Support paying static invoices
  • Loading branch information
TheBlueMatt authored Sep 15, 2024
2 parents f7cc40e + 6e27aec commit 22146a9
Show file tree
Hide file tree
Showing 13 changed files with 687 additions and 141 deletions.
11 changes: 5 additions & 6 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};

use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, OffersContext};
use lightning::blinded_path::message::{
AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext,
};
use lightning::blinded_path::EmptyNodeIdLookUp;
use lightning::ln::features::InitFeatures;
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
Expand Down Expand Up @@ -124,12 +126,9 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
Some(resp) => resp,
None => return None,
};
Some((
ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret },
responder.respond(),
))
Some((ReleaseHeldHtlc {}, responder.respond()))
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}

#[derive(Debug)]
Expand Down
44 changes: 44 additions & 0 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ pub enum MessageContext {
///
/// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
Offers(OffersContext),
/// Context specific to an [`AsyncPaymentsMessage`].
///
/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
AsyncPayments(AsyncPaymentsContext),
/// Context specific to a [`CustomOnionMessageHandler::CustomMessage`].
///
/// [`CustomOnionMessageHandler::CustomMessage`]: crate::onion_message::messenger::CustomOnionMessageHandler::CustomMessage
Expand Down Expand Up @@ -363,9 +367,41 @@ pub enum OffersContext {
},
}

/// Contains data specific to an [`AsyncPaymentsMessage`].
///
/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
#[derive(Clone, Debug)]
pub enum AsyncPaymentsContext {
/// Context contained within the reply [`BlindedMessagePath`] we put in outbound
/// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`]
/// messages.
///
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
OutboundPayment {
/// ID used when payment to the originating [`Offer`] was initiated. Useful for us to identify
/// which of our pending outbound payments should be released to its often-offline payee.
///
/// [`Offer`]: crate::offers::offer::Offer
payment_id: PaymentId,
/// A nonce used for authenticating that a [`ReleaseHeldHtlc`] message is valid for a preceding
/// [`HeldHtlcAvailable`] message.
///
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
nonce: Nonce,
/// Authentication code for the [`PaymentId`].
///
/// Prevents the recipient from being able to deanonymize us by creating a blinded path to us
/// containing the expected [`PaymentId`].
hmac: Hmac<Sha256>,
},
}

impl_writeable_tlv_based_enum!(MessageContext,
{0, Offers} => (),
{1, Custom} => (),
{2, AsyncPayments} => (),
);

impl_writeable_tlv_based_enum!(OffersContext,
Expand All @@ -384,6 +420,14 @@ impl_writeable_tlv_based_enum!(OffersContext,
},
);

impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
(0, OutboundPayment) => {
(0, payment_id, required),
(2, nonce, required),
(4, hmac, required),
},
);

/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[MessageForwardNode],
Expand Down
Loading

0 comments on commit 22146a9

Please sign in to comment.