Skip to content

Commit e07a436

Browse files
committed
Parse inbound TrampolineEntrypoint payload
Check inbound onion payloads for the presence of an inner onion, which we will later also need to decrypt to handle Trampoline payments.
1 parent 9921daf commit e07a436

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lightning/src/ln/msgs.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,14 @@ mod fuzzy_internal_msgs {
18111811
pub outgoing_cltv_value: u32,
18121812
}
18131813

1814+
#[allow(unused)]
1815+
pub struct InboundTrampolineEntrypointPayload {
1816+
pub amt_to_forward: u64,
1817+
pub outgoing_cltv_value: u32,
1818+
pub multipath_trampoline_data: Option<FinalOnionHopData>,
1819+
pub trampoline_packet: TrampolineOnionPacket,
1820+
}
1821+
18141822
pub struct InboundOnionReceivePayload {
18151823
pub payment_data: Option<FinalOnionHopData>,
18161824
pub payment_metadata: Option<Vec<u8>>,
@@ -1842,6 +1850,8 @@ mod fuzzy_internal_msgs {
18421850

18431851
pub enum InboundOnionPayload {
18441852
Forward(InboundOnionForwardPayload),
1853+
#[allow(unused)]
1854+
TrampolineEntrypoint(InboundTrampolineEntrypointPayload),
18451855
Receive(InboundOnionReceivePayload),
18461856
BlindedForward(InboundOnionBlindedForwardPayload),
18471857
BlindedReceive(InboundOnionBlindedReceivePayload),
@@ -2932,6 +2942,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29322942
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
29332943
let mut total_msat = None;
29342944
let mut keysend_preimage: Option<PaymentPreimage> = None;
2945+
let mut trampoline_onion_packet: Option<TrampolineOnionPacket> = None;
29352946
let mut invoice_request: Option<InvoiceRequest> = None;
29362947
let mut custom_tlvs = Vec::new();
29372948

@@ -2946,6 +2957,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29462957
(12, intro_node_blinding_point, option),
29472958
(16, payment_metadata, option),
29482959
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
2960+
(20, trampoline_onion_packet, option),
29492961
(77_777, invoice_request, option),
29502962
// See https://github.com/lightning/blips/blob/master/blip-0003.md
29512963
(5482373484, keysend_preimage, option)
@@ -3024,6 +3036,16 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
30243036
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
30253037
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
30263038
}))
3039+
} else if let Some(trampoline_onion_packet) = trampoline_onion_packet {
3040+
if payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
3041+
total_msat.is_some()
3042+
{ return Err(DecodeError::InvalidValue) }
3043+
Ok(Self::TrampolineEntrypoint(InboundTrampolineEntrypointPayload {
3044+
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
3045+
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
3046+
multipath_trampoline_data: payment_data,
3047+
trampoline_packet: trampoline_onion_packet,
3048+
}))
30273049
} else {
30283050
if encrypted_tlvs_opt.is_some() || total_msat.is_some() || invoice_request.is_some() {
30293051
return Err(DecodeError::InvalidValue)

0 commit comments

Comments
 (0)