Skip to content

Commit a8ef833

Browse files
committed
Parse blinded Trampoline forward payloads
We will be using the same logic for decoding onion payloads for outer and for Trampoline onions. To accommodate some Trampoline-only payloads, we add the ability to parse blinded forward payloads that carry a next node ID rather than an SCID.
1 parent 0cd899e commit a8ef833

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lightning/src/blinded_path/payment.rs

+22
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,25 @@ pub struct ForwardTlvs {
297297
pub next_blinding_override: Option<PublicKey>,
298298
}
299299

300+
/// Data to construct a [`BlindedHop`] for forwarding a Trampoline payment.
301+
#[derive(Clone, Debug)]
302+
pub struct TrampolineForwardTlvs {
303+
/// The node id to which the trampoline node must find a route.
304+
pub outgoing_node_id: NodeId,
305+
/// Payment parameters for relaying over [`Self::outgoing_node_id`].
306+
pub payment_relay: PaymentRelay,
307+
/// Payment constraints for relaying over [`Self::outgoing_node_id`].
308+
pub payment_constraints: PaymentConstraints,
309+
/// Supported and required features when relaying a payment onion containing this object's
310+
/// corresponding [`BlindedHop::encrypted_payload`].
311+
///
312+
/// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
313+
pub features: BlindedHopFeatures,
314+
/// Set if this [`BlindedPaymentPath`] is concatenated to another, to indicate the
315+
/// [`BlindedPaymentPath::blinding_point`] of the appended blinded path.
316+
pub next_blinding_override: Option<PublicKey>,
317+
}
318+
300319
/// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
301320
/// may not be valid if received by another lightning implementation.
302321
///
@@ -344,6 +363,9 @@ impl UnauthenticatedReceiveTlvs {
344363
pub(crate) enum BlindedPaymentTlvs {
345364
/// This blinded payment data is for a forwarding node.
346365
Forward(ForwardTlvs),
366+
/// This blinded payment data is for a forwarding Trampoline node.
367+
#[allow(unused)]
368+
TrampolineForward(TrampolineForwardTlvs),
347369
/// This blinded payment data is for the receiving node.
348370
Receive(ReceiveTlvs),
349371
}

lightning/src/ln/msgs.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use bitcoin::{secp256k1, Witness};
3131
use bitcoin::script::ScriptBuf;
3232
use bitcoin::hash_types::Txid;
3333

34-
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs, UnauthenticatedReceiveTlvs};
34+
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs, TrampolineForwardTlvs, UnauthenticatedReceiveTlvs};
3535
use crate::ln::channelmanager::Verification;
3636
use crate::ln::types::ChannelId;
3737
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -1844,6 +1844,17 @@ mod fuzzy_internal_msgs {
18441844
pub intro_node_blinding_point: Option<PublicKey>,
18451845
pub next_blinding_override: Option<PublicKey>,
18461846
}
1847+
1848+
#[allow(unused)]
1849+
pub struct InboundTrampolineBlindedForwardPayload {
1850+
pub outgoing_node_id: NodeId,
1851+
pub payment_relay: PaymentRelay,
1852+
pub payment_constraints: PaymentConstraints,
1853+
pub features: BlindedHopFeatures,
1854+
pub intro_node_blinding_point: Option<PublicKey>,
1855+
pub next_blinding_override: Option<PublicKey>,
1856+
}
1857+
18471858
pub struct InboundOnionBlindedReceivePayload {
18481859
pub sender_intended_htlc_amt_msat: u64,
18491860
pub total_msat: u64,
@@ -1868,6 +1879,8 @@ mod fuzzy_internal_msgs {
18681879
// These payloads should be seen inside an inner Trampoline onion
18691880
#[allow(unused)]
18701881
TrampolineForward(InboundTrampolineForwardPayload),
1882+
#[allow(unused)]
1883+
TrampolineBlindedForward(InboundTrampolineBlindedForwardPayload),
18711884
}
18721885

18731886
pub(crate) enum OutboundOnionPayload<'a> {
@@ -3028,6 +3041,23 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
30283041
next_blinding_override,
30293042
}))
30303043
},
3044+
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::TrampolineForward(TrampolineForwardTlvs {
3045+
outgoing_node_id, payment_relay, payment_constraints, features, next_blinding_override
3046+
})} => {
3047+
if amt.is_some() || cltv_value.is_some() || total_msat.is_some() ||
3048+
keysend_preimage.is_some() || invoice_request.is_some()
3049+
{
3050+
return Err(DecodeError::InvalidValue)
3051+
}
3052+
Ok(Self::TrampolineBlindedForward(InboundTrampolineBlindedForwardPayload {
3053+
outgoing_node_id,
3054+
payment_relay,
3055+
payment_constraints,
3056+
features,
3057+
intro_node_blinding_point,
3058+
next_blinding_override,
3059+
}))
3060+
},
30313061
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(receive_tlvs) } => {
30323062
let ReceiveTlvs { tlvs, authentication: (hmac, nonce) } = receive_tlvs;
30333063
let expanded_key = node_signer.get_inbound_payment_key();

0 commit comments

Comments
 (0)