Skip to content

Commit 6d0af10

Browse files
committed
f: use trampoline cfg-gating
1 parent 3f84ceb commit 6d0af10

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

lightning/src/ln/msgs.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ mod fuzzy_internal_msgs {
18111811
pub outgoing_cltv_value: u32,
18121812
}
18131813

1814-
#[allow(unused)]
1814+
#[cfg(trampoline)]
18151815
pub struct InboundTrampolineEntrypointPayload {
18161816
pub amt_to_forward: u64,
18171817
pub outgoing_cltv_value: u32,
@@ -1851,7 +1851,7 @@ mod fuzzy_internal_msgs {
18511851

18521852
pub enum InboundOnionPayload {
18531853
Forward(InboundOnionForwardPayload),
1854-
#[allow(unused)]
1854+
#[cfg(trampoline)]
18551855
TrampolineEntrypoint(InboundTrampolineEntrypointPayload),
18561856
Receive(InboundOnionReceivePayload),
18571857
BlindedForward(InboundOnionBlindedForwardPayload),
@@ -2943,12 +2943,15 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29432943
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
29442944
let mut total_msat = None;
29452945
let mut keysend_preimage: Option<PaymentPreimage> = None;
2946+
#[cfg(trampoline)]
29462947
let mut trampoline_onion_packet: Option<TrampolineOnionPacket> = None;
29472948
let mut invoice_request: Option<InvoiceRequest> = None;
29482949
let mut custom_tlvs = Vec::new();
29492950

29502951
let tlv_len = BigSize::read(r)?;
29512952
let mut rd = FixedLengthReader::new(r, tlv_len.0);
2953+
2954+
#[cfg(trampoline)]
29522955
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
29532956
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
29542957
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
@@ -2969,24 +2972,47 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
29692972
custom_tlvs.push((msg_type, value));
29702973
Ok(true)
29712974
});
2975+
#[cfg(not(trampoline))]
2976+
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
2977+
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
2978+
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
2979+
(6, short_id, option),
2980+
(8, payment_data, option),
2981+
(10, encrypted_tlvs_opt, option),
2982+
(12, intro_node_blinding_point, option),
2983+
(16, payment_metadata, option),
2984+
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
2985+
(77_777, invoice_request, option),
2986+
// See https://github.com/lightning/blips/blob/master/blip-0003.md
2987+
(5482373484, keysend_preimage, option)
2988+
}, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> {
2989+
if msg_type < 1 << 16 { return Ok(false) }
2990+
let mut value = Vec::new();
2991+
msg_reader.read_to_limit(&mut value, u64::MAX)?;
2992+
custom_tlvs.push((msg_type, value));
2993+
Ok(true)
2994+
});
29722995

29732996
if amt.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) }
29742997
if intro_node_blinding_point.is_some() && update_add_blinding_point.is_some() {
29752998
return Err(DecodeError::InvalidValue)
29762999
}
29773000

3001+
#[cfg(trampoline)]
29783002
if let Some(trampoline_onion_packet) = trampoline_onion_packet {
29793003
if payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
29803004
total_msat.is_some()
29813005
{ return Err(DecodeError::InvalidValue) }
2982-
Ok(Self::TrampolineEntrypoint(InboundTrampolineEntrypointPayload {
3006+
return Ok(Self::TrampolineEntrypoint(InboundTrampolineEntrypointPayload {
29833007
amt_to_forward: amt.ok_or(DecodeError::InvalidValue)?,
29843008
outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?,
29853009
multipath_trampoline_data: payment_data,
29863010
trampoline_packet: trampoline_onion_packet,
2987-
current_path_key: intro_node_blinding_point
3011+
current_path_key: intro_node_blinding_point,
29883012
}))
2989-
} else if let Some(blinding_point) = intro_node_blinding_point.or(update_add_blinding_point) {
3013+
}
3014+
3015+
if let Some(blinding_point) = intro_node_blinding_point.or(update_add_blinding_point) {
29903016
if short_id.is_some() || payment_data.is_some() || payment_metadata.is_some() {
29913017
return Err(DecodeError::InvalidValue)
29923018
}

0 commit comments

Comments
 (0)