Skip to content

Commit 4741892

Browse files
committed
Remove Trampoline config flag
In this PR, we add end-to-end tests for Trampoline receive and forwarding behavior (specifically rejection of payments for the latter), ensuring sanity, no unexpected errors, and obviating the cfg-gating.
1 parent 030a784 commit 4741892

8 files changed

+7
-114
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ check-cfg = [
6363
"cfg(ldk_bench)",
6464
"cfg(ldk_test_vectors)",
6565
"cfg(taproot)",
66-
"cfg(trampoline)",
6766
"cfg(require_route_graph_test)",
6867
"cfg(splicing)",
6968
"cfg(async_payments)",

ci/ci-tests.sh

-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
134134
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
135135
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
136136
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
137-
RUSTFLAGS="--cfg=trampoline" cargo test --verbose --color always -p lightning
138-
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
139137
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
140138
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
141139
RUSTFLAGS="--cfg=lsps1_service" cargo test --verbose --color always -p lightning-liquidity

lightning/src/blinded_path/payment.rs

-3
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ pub struct ForwardTlvs {
298298
}
299299

300300
/// Data to construct a [`BlindedHop`] for forwarding a Trampoline payment.
301-
#[cfg(trampoline)]
302301
#[derive(Clone, Debug)]
303302
pub struct TrampolineForwardTlvs {
304303
/// The node id to which the trampoline node must find a route.
@@ -371,7 +370,6 @@ pub(crate) enum BlindedPaymentTlvs {
371370
/// Data to construct a [`BlindedHop`] for sending a Trampoline payment over.
372371
///
373372
/// [`BlindedHop`]: crate::blinded_path::BlindedHop
374-
#[cfg(trampoline)]
375373
pub(crate) enum BlindedTrampolineTlvs {
376374
/// This blinded payment data is for a forwarding node.
377375
Forward(TrampolineForwardTlvs),
@@ -591,7 +589,6 @@ impl Readable for BlindedPaymentTlvs {
591589
}
592590
}
593591

594-
#[cfg(trampoline)]
595592
impl Readable for BlindedTrampolineTlvs {
596593
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
597594
_init_and_read_tlv_stream!(r, {

lightning/src/ln/blinded_payment_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,6 @@ fn test_combined_trampoline_onion_creation_vectors() {
18161816
}
18171817

18181818
#[test]
1819-
#[cfg(trampoline)]
18201819
fn test_trampoline_inbound_payment_decoding() {
18211820
let secp_ctx = Secp256k1::new();
18221821
let session_priv = secret_from_hex("0303030303030303030303030303030303030303030303030303030303030303");

lightning/src/ln/channelmanager.rs

+1-53
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ pub enum PendingHTLCRouting {
170170
incoming_cltv_expiry: Option<u32>,
171171
},
172172
/// An HTLC which should be forwarded on to another Trampoline node.
173-
#[cfg(trampoline)]
174173
TrampolineForward {
175174
/// The onion shared secret we build with the sender (or the preceding Trampoline node) used
176175
/// to decrypt the onion.
@@ -288,7 +287,6 @@ impl PendingHTLCRouting {
288287
fn blinded_failure(&self) -> Option<BlindedFailure> {
289288
match self {
290289
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
291-
#[cfg(trampoline)]
292290
Self::TrampolineForward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
293291
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
294292
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
@@ -299,7 +297,6 @@ impl PendingHTLCRouting {
299297
fn incoming_cltv_expiry(&self) -> Option<u32> {
300298
match self {
301299
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
302-
#[cfg(trampoline)]
303300
Self::TrampolineForward { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
304301
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
305302
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
@@ -4510,24 +4507,7 @@ where
45104507
}
45114508
}
45124509
match decoded_hop {
4513-
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } => {
4514-
// OUR PAYMENT!
4515-
let current_height: u32 = self.best_block.read().unwrap().height;
4516-
match create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
4517-
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4518-
current_height)
4519-
{
4520-
Ok(info) => {
4521-
// Note that we could obviously respond immediately with an update_fulfill_htlc
4522-
// message, however that would leak that we are the recipient of this payment, so
4523-
// instead we stay symmetric with the forwarding case, only responding (after a
4524-
// delay) once they've sent us a commitment_signed!
4525-
PendingHTLCStatus::Forward(info)
4526-
},
4527-
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4528-
}
4529-
},
4530-
#[cfg(trampoline)]
4510+
onion_utils::Hop::Receive { .. } | onion_utils::Hop::BlindedReceive { .. } |
45314511
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => {
45324512
// OUR PAYMENT!
45334513
let current_height: u32 = self.best_block.read().unwrap().height;
@@ -4551,7 +4531,6 @@ where
45514531
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
45524532
}
45534533
},
4554-
#[cfg(trampoline)]
45554534
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
45564535
match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
45574536
Ok(info) => PendingHTLCStatus::Forward(info),
@@ -9067,7 +9046,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
90679046
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
90689047
let scid = match forward_info.routing {
90699048
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
9070-
#[cfg(trampoline)]
90719049
PendingHTLCRouting::TrampolineForward { .. } => 0,
90729050
PendingHTLCRouting::Receive { .. } => 0,
90739051
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
@@ -12888,36 +12866,6 @@ impl_writeable_tlv_based!(BlindedForward, {
1288812866
(3, next_blinding_override, option),
1288912867
});
1289012868

12891-
#[cfg(not(trampoline))]
12892-
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
12893-
(0, Forward) => {
12894-
(0, onion_packet, required),
12895-
(1, blinded, option),
12896-
(2, short_channel_id, required),
12897-
(3, incoming_cltv_expiry, option),
12898-
},
12899-
(1, Receive) => {
12900-
(0, payment_data, required),
12901-
(1, phantom_shared_secret, option),
12902-
(2, incoming_cltv_expiry, required),
12903-
(3, payment_metadata, option),
12904-
(5, custom_tlvs, optional_vec),
12905-
(7, requires_blinded_error, (default_value, false)),
12906-
(9, payment_context, option),
12907-
},
12908-
(2, ReceiveKeysend) => {
12909-
(0, payment_preimage, required),
12910-
(1, requires_blinded_error, (default_value, false)),
12911-
(2, incoming_cltv_expiry, required),
12912-
(3, payment_metadata, option),
12913-
(4, payment_data, option), // Added in 0.0.116
12914-
(5, custom_tlvs, optional_vec),
12915-
(7, has_recipient_created_payment_secret, (default_value, false)),
12916-
(9, payment_context, option),
12917-
(11, invoice_request, option),
12918-
},
12919-
);
12920-
#[cfg(trampoline)]
1292112869
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1292212870
(0, Forward) => {
1292312871
(0, onion_packet, required),

lightning/src/ln/msgs.rs

+1-32
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use bitcoin::script::ScriptBuf;
3232
use bitcoin::hash_types::Txid;
3333

3434
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs, UnauthenticatedReceiveTlvs};
35-
#[cfg(trampoline)]
3635
use crate::blinded_path::payment::{BlindedTrampolineTlvs, TrampolineForwardTlvs};
3736
use crate::ln::channelmanager::Verification;
3837
use crate::ln::types::ChannelId;
@@ -2075,8 +2074,7 @@ mod fuzzy_internal_msgs {
20752074
pub outgoing_cltv_value: u32,
20762075
}
20772076

2078-
#[cfg(trampoline)]
2079-
#[cfg_attr(trampoline, allow(unused))]
2077+
#[allow(unused)]
20802078
pub struct InboundTrampolineEntrypointPayload {
20812079
pub amt_to_forward: u64,
20822080
pub outgoing_cltv_value: u32,
@@ -2118,23 +2116,19 @@ mod fuzzy_internal_msgs {
21182116

21192117
pub enum InboundOnionPayload {
21202118
Forward(InboundOnionForwardPayload),
2121-
#[cfg(trampoline)]
2122-
#[cfg_attr(trampoline, allow(unused))]
21232119
TrampolineEntrypoint(InboundTrampolineEntrypointPayload),
21242120
Receive(InboundOnionReceivePayload),
21252121
BlindedForward(InboundOnionBlindedForwardPayload),
21262122
BlindedReceive(InboundOnionBlindedReceivePayload),
21272123
}
21282124

2129-
#[cfg(trampoline)]
21302125
pub struct InboundTrampolineForwardPayload {
21312126
pub next_trampoline: PublicKey,
21322127
/// The value, in msat, of the payment after this hop's fee is deducted.
21332128
pub amt_to_forward: u64,
21342129
pub outgoing_cltv_value: u32,
21352130
}
21362131

2137-
#[cfg(trampoline)]
21382132
pub struct InboundTrampolineBlindedForwardPayload {
21392133
pub next_trampoline: PublicKey,
21402134
pub payment_relay: PaymentRelay,
@@ -2144,7 +2138,6 @@ mod fuzzy_internal_msgs {
21442138
pub next_blinding_override: Option<PublicKey>,
21452139
}
21462140

2147-
#[cfg(trampoline)]
21482141
pub enum InboundTrampolinePayload {
21492142
Forward(InboundTrampolineForwardPayload),
21502143
BlindedForward(InboundTrampolineBlindedForwardPayload),
@@ -3239,15 +3232,13 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
32393232
let mut payment_metadata: Option<WithoutLength<Vec<u8>>> = None;
32403233
let mut total_msat = None;
32413234
let mut keysend_preimage: Option<PaymentPreimage> = None;
3242-
#[cfg(trampoline)]
32433235
let mut trampoline_onion_packet: Option<TrampolineOnionPacket> = None;
32443236
let mut invoice_request: Option<InvoiceRequest> = None;
32453237
let mut custom_tlvs = Vec::new();
32463238

32473239
let tlv_len = BigSize::read(r)?;
32483240
let mut rd = FixedLengthReader::new(r, tlv_len.0);
32493241

3250-
#[cfg(trampoline)]
32513242
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
32523243
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
32533244
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
@@ -3268,33 +3259,12 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
32683259
custom_tlvs.push((msg_type, value));
32693260
Ok(true)
32703261
});
3271-
#[cfg(not(trampoline))]
3272-
decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
3273-
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
3274-
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
3275-
(6, short_id, option),
3276-
(8, payment_data, option),
3277-
(10, encrypted_tlvs_opt, option),
3278-
(12, intro_node_blinding_point, option),
3279-
(16, payment_metadata, option),
3280-
(18, total_msat, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
3281-
(77_777, invoice_request, option),
3282-
// See https://github.com/lightning/blips/blob/master/blip-0003.md
3283-
(5482373484, keysend_preimage, option)
3284-
}, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> {
3285-
if msg_type < 1 << 16 { return Ok(false) }
3286-
let mut value = Vec::new();
3287-
msg_reader.read_to_limit(&mut value, u64::MAX)?;
3288-
custom_tlvs.push((msg_type, value));
3289-
Ok(true)
3290-
});
32913262

32923263
if amt.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) }
32933264
if intro_node_blinding_point.is_some() && update_add_blinding_point.is_some() {
32943265
return Err(DecodeError::InvalidValue)
32953266
}
32963267

3297-
#[cfg(trampoline)]
32983268
if let Some(trampoline_onion_packet) = trampoline_onion_packet {
32993269
if payment_metadata.is_some() || encrypted_tlvs_opt.is_some() ||
33003270
total_msat.is_some()
@@ -3391,7 +3361,6 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
33913361
}
33923362
}
33933363

3394-
#[cfg(trampoline)]
33953364
impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundTrampolinePayload where NS::Target: NodeSigner {
33963365
fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, NS)) -> Result<Self, DecodeError> {
33973366
let (update_add_blinding_point, node_signer) = args;

lightning/src/ln/onion_payment.rs

-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use bitcoin::hashes::Hash;
77
use bitcoin::hashes::sha256::Hash as Sha256;
88
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
9-
10-
#[cfg(trampoline)]
119
use bitcoin::secp256k1::ecdh::SharedSecret;
1210

1311
use crate::blinded_path;
@@ -69,7 +67,6 @@ enum RoutingInfo {
6967
new_packet_bytes: [u8; ONION_DATA_LEN],
7068
next_hop_hmac: [u8; 32]
7169
},
72-
#[cfg(trampoline)]
7370
Trampoline {
7471
next_trampoline: PublicKey,
7572
// Trampoline onions are currently variable length
@@ -118,14 +115,12 @@ pub(super) fn create_fwd_pending_htlc_info(
118115
err_code: 0x4000 | 22,
119116
err_data: Vec::new(),
120117
}),
121-
#[cfg(trampoline)]
122118
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } =>
123119
return Err(InboundHTLCErr {
124120
msg: "Final Node OnionHopData provided for us as an intermediary node",
125121
err_code: 0x4000 | 22,
126122
err_data: Vec::new(),
127123
}),
128-
#[cfg(trampoline)]
129124
onion_utils::Hop::TrampolineForward { next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
130125
(
131126
RoutingInfo::Trampoline {
@@ -141,7 +136,6 @@ pub(super) fn create_fwd_pending_htlc_info(
141136
None
142137
)
143138
},
144-
#[cfg(trampoline)]
145139
onion_utils::Hop::TrampolineBlindedForward { outer_hop_data, next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
146140
let (amt_to_forward, outgoing_cltv_value) = check_blinded_forward(
147141
msg.amount_msat, msg.cltv_expiry, &next_trampoline_hop_data.payment_relay, &next_trampoline_hop_data.payment_constraints, &next_trampoline_hop_data.features
@@ -192,7 +186,6 @@ pub(super) fn create_fwd_pending_htlc_info(
192186
}),
193187
}
194188
}
195-
#[cfg(trampoline)]
196189
RoutingInfo::Trampoline { next_trampoline, new_packet_bytes, next_hop_hmac, shared_secret, current_path_key } => {
197190
let next_trampoline_packet_pubkey = match next_packet_pubkey_opt {
198191
Some(Ok(pubkey)) => pubkey,
@@ -272,7 +265,6 @@ pub(super) fn create_recv_pending_htlc_info(
272265
sender_intended_htlc_amt_msat, cltv_expiry_height, None, Some(payment_context),
273266
intro_node_blinding_point.is_none(), true, invoice_request)
274267
}
275-
#[cfg(trampoline)]
276268
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => todo!(),
277269
onion_utils::Hop::Forward { .. } => {
278270
return Err(InboundHTLCErr {
@@ -288,7 +280,6 @@ pub(super) fn create_recv_pending_htlc_info(
288280
msg: "Got blinded non final data with an HMAC of 0",
289281
})
290282
},
291-
#[cfg(trampoline)]
292283
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
293284
return Err(InboundHTLCErr {
294285
err_code: 0x4000|22,
@@ -560,7 +551,6 @@ where
560551
outgoing_cltv_value
561552
})
562553
}
563-
#[cfg(trampoline)]
564554
onion_utils::Hop::TrampolineForward { next_trampoline_hop_data: msgs::InboundTrampolineForwardPayload { amt_to_forward, outgoing_cltv_value, next_trampoline }, trampoline_shared_secret, incoming_trampoline_public_key, .. } => {
565555
let next_trampoline_packet_pubkey = onion_utils::next_hop_pubkey(secp_ctx,
566556
incoming_trampoline_public_key, &trampoline_shared_secret.secret_bytes());

0 commit comments

Comments
 (0)