Skip to content

Commit 0cd899e

Browse files
committed
Parse 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 forward payloads that carry a next node ID rather than an SCID.
1 parent fec26ee commit 0cd899e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lightning/src/ln/msgs.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ mod fuzzy_internal_msgs {
18001800

18011801
#[allow(unused_imports)]
18021802
use crate::prelude::*;
1803-
1803+
use crate::routing::gossip::NodeId;
18041804
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
18051805
// them from untrusted input):
18061806

@@ -1811,6 +1811,14 @@ mod fuzzy_internal_msgs {
18111811
pub outgoing_cltv_value: u32,
18121812
}
18131813

1814+
#[allow(unused)]
1815+
pub struct InboundTrampolineForwardPayload {
1816+
pub outgoing_node_id: NodeId,
1817+
/// The value, in msat, of the payment after this hop's fee is deducted.
1818+
pub amt_to_forward: u64,
1819+
pub outgoing_cltv_value: u32,
1820+
}
1821+
18141822
#[allow(unused)]
18151823
pub struct InboundTrampolineEntrypointPayload {
18161824
pub amt_to_forward: u64,
@@ -1856,6 +1864,10 @@ mod fuzzy_internal_msgs {
18561864
Receive(InboundOnionReceivePayload),
18571865
BlindedForward(InboundOnionBlindedForwardPayload),
18581866
BlindedReceive(InboundOnionBlindedReceivePayload),
1867+
1868+
// These payloads should be seen inside an inner Trampoline onion
1869+
#[allow(unused)]
1870+
TrampolineForward(InboundTrampolineForwardPayload),
18591871
}
18601872

18611873
pub(crate) enum OutboundOnionPayload<'a> {
@@ -2940,6 +2952,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29402952
let mut payment_data: Option<FinalOnionHopData> = None;
29412953
let mut encrypted_tlvs_opt: Option<WithoutLength<Vec<u8>>> = None;
29422954
let mut intro_node_blinding_point = None;
2955+
let mut outgoing_node_id: Option<NodeId> = None;
29432956
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
29442957
let mut total_msat = None;
29452958
let mut keysend_preimage: Option<PaymentPreimage> = None;
@@ -2956,6 +2969,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29562969
(8, payment_data, option),
29572970
(10, encrypted_tlvs_opt, option),
29582971
(12, intro_node_blinding_point, option),
2972+
(14, outgoing_node_id, option),
29592973
(16, payment_metadata, option),
29602974
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
29612975
(20, trampoline_onion_packet, option),
@@ -3048,6 +3062,15 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
30483062
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
30493063
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
30503064
}))
3065+
} else if let Some(outgoing_node_id) = outgoing_node_id {
3066+
if payment_data.is_some() || payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
3067+
total_msat.is_some() || invoice_request.is_some()
3068+
{ return Err(DecodeError::InvalidValue) }
3069+
Ok(Self::TrampolineForward(InboundTrampolineForwardPayload {
3070+
outgoing_node_id,
3071+
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
3072+
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
3073+
}))
30513074
} else {
30523075
if encrypted_tlvs_opt.is_some() || total_msat.is_some() || invoice_request.is_some() {
30533076
return Err(DecodeError::InvalidValue)

0 commit comments

Comments
 (0)