Skip to content

Commit 908c6bf

Browse files
committed
Remove Trampoline config flag
In this PR, we add end-to-end tests for Trampoline receive and forwarding behavior, ensuring sanity and obviating the cfg-gating.
1 parent 030a784 commit 908c6bf

File tree

8 files changed

+6
-97
lines changed

8 files changed

+6
-97
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 36 deletions
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),
@@ -4527,7 +4524,6 @@ where
45274524
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
45284525
}
45294526
},
4530-
#[cfg(trampoline)]
45314527
onion_utils::Hop::TrampolineReceive { .. } | onion_utils::Hop::TrampolineBlindedReceive { .. } => {
45324528
// OUR PAYMENT!
45334529
let current_height: u32 = self.best_block.read().unwrap().height;
@@ -4551,7 +4547,6 @@ where
45514547
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
45524548
}
45534549
},
4554-
#[cfg(trampoline)]
45554550
onion_utils::Hop::TrampolineForward { .. } | onion_utils::Hop::TrampolineBlindedForward { .. } => {
45564551
match create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt) {
45574552
Ok(info) => PendingHTLCStatus::Forward(info),
@@ -9067,7 +9062,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
90679062
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
90689063
let scid = match forward_info.routing {
90699064
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
9070-
#[cfg(trampoline)]
90719065
PendingHTLCRouting::TrampolineForward { .. } => 0,
90729066
PendingHTLCRouting::Receive { .. } => 0,
90739067
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
@@ -12888,36 +12882,6 @@ impl_writeable_tlv_based!(BlindedForward, {
1288812882
(3, next_blinding_override, option),
1288912883
});
1289012884

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)]
1292112885
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
1292212886
(0, Forward) => {
1292312887
(0, onion_packet, required),

lightning/src/ln/msgs.rs

Lines changed: 1 addition & 32 deletions
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

Lines changed: 0 additions & 10 deletions
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());

lightning/src/ln/onion_utils.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,6 @@ pub(crate) enum Hop {
15641564
},
15651565
/// This onion was received via Trampoline, and needs to be forwarded to a subsequent Trampoline
15661566
/// node.
1567-
#[cfg(trampoline)]
15681567
TrampolineForward {
15691568
#[allow(unused)]
15701569
outer_hop_data: msgs::InboundTrampolineEntrypointPayload,
@@ -1577,11 +1576,10 @@ pub(crate) enum Hop {
15771576
},
15781577
/// This onion was received via Trampoline, and needs to be forwarded to a subsequent Trampoline
15791578
/// node.
1580-
#[allow(unused)]
1581-
#[cfg(trampoline)]
15821579
TrampolineBlindedForward {
15831580
outer_hop_data: msgs::InboundTrampolineEntrypointPayload,
15841581
outer_shared_secret: SharedSecret,
1582+
#[allow(unused)]
15851583
incoming_trampoline_public_key: PublicKey,
15861584
trampoline_shared_secret: SharedSecret,
15871585
next_trampoline_hop_data: msgs::InboundTrampolineBlindedForwardPayload,
@@ -1617,22 +1615,22 @@ pub(crate) enum Hop {
16171615
},
16181616
/// This onion payload was for us, not for forwarding to a next-hop, and it was sent to us via
16191617
/// Trampoline. Contains information for verifying the incoming payment.
1620-
#[allow(unused)]
1621-
#[cfg(trampoline)]
16221618
TrampolineReceive {
1619+
#[allow(unused)]
16231620
outer_hop_data: msgs::InboundTrampolineEntrypointPayload,
16241621
outer_shared_secret: SharedSecret,
16251622
trampoline_hop_data: msgs::InboundOnionReceivePayload,
1623+
#[allow(unused)]
16261624
trampoline_shared_secret: SharedSecret,
16271625
},
16281626
/// This onion payload was for us, not for forwarding to a next-hop, and it was sent to us via
16291627
/// Trampoline. Contains information for verifying the incoming payment.
1630-
#[allow(unused)]
1631-
#[cfg(trampoline)]
16321628
TrampolineBlindedReceive {
1629+
#[allow(unused)]
16331630
outer_hop_data: msgs::InboundTrampolineEntrypointPayload,
16341631
outer_shared_secret: SharedSecret,
16351632
trampoline_hop_data: msgs::InboundOnionBlindedReceivePayload,
1633+
#[allow(unused)]
16361634
trampoline_shared_secret: SharedSecret,
16371635
},
16381636
}
@@ -1655,15 +1653,11 @@ impl Hop {
16551653
match self {
16561654
Hop::Forward { shared_secret, .. } => shared_secret,
16571655
Hop::BlindedForward { shared_secret, .. } => shared_secret,
1658-
#[cfg(trampoline)]
16591656
Hop::TrampolineForward { outer_shared_secret, .. } => outer_shared_secret,
1660-
#[cfg(trampoline)]
16611657
Hop::TrampolineBlindedForward { outer_shared_secret, .. } => outer_shared_secret,
16621658
Hop::Receive { shared_secret, .. } => shared_secret,
16631659
Hop::BlindedReceive { shared_secret, .. } => shared_secret,
1664-
#[cfg(trampoline)]
16651660
Hop::TrampolineReceive { outer_shared_secret, .. } => outer_shared_secret,
1666-
#[cfg(trampoline)]
16671661
Hop::TrampolineBlindedReceive { outer_shared_secret, .. } => outer_shared_secret,
16681662
}
16691663
}
@@ -1750,7 +1744,6 @@ where
17501744
msgs::InboundOnionPayload::BlindedReceive(hop_data) => {
17511745
Ok(Hop::BlindedReceive { shared_secret, hop_data })
17521746
},
1753-
#[cfg(trampoline)]
17541747
msgs::InboundOnionPayload::TrampolineEntrypoint(hop_data) => {
17551748
let incoming_trampoline_public_key = hop_data.trampoline_packet.public_key;
17561749
let trampoline_blinded_node_id_tweak = hop_data.current_path_key.map(|bp| {

0 commit comments

Comments
 (0)