Skip to content

Commit f4914f4

Browse files
committed
Add trampoline_hops field to Path
To specify Trampoline hops in Path instances, we need to introduce a third field to the struct, which is a vec of TrampolineHops defined in the previous commit.
1 parent e626385 commit f4914f4

File tree

14 files changed

+89
-41
lines changed

14 files changed

+89
-41
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ fn send_payment(
520520
cltv_expiry_delta: 200,
521521
maybe_announced_channel: true,
522522
}],
523+
trampoline_hops: vec![],
523524
blinded_tail: None,
524525
}],
525526
route_params: Some(route_params.clone()),
@@ -604,6 +605,7 @@ fn send_hop_payment(
604605
maybe_announced_channel: true,
605606
},
606607
],
608+
trampoline_hops: vec![],
607609
blinded_tail: None,
608610
}],
609611
route_params: Some(route_params.clone()),

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ mod tests {
25402540
fee_msat: 0,
25412541
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
25422542
maybe_announced_channel: true,
2543-
}], blinded_tail: None };
2543+
}], trampoline_hops: vec![], blinded_tail: None };
25442544

25452545
$nodes[0].scorer.write_lock().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
25462546
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {

lightning/src/events/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
3030
use crate::offers::invoice::Bolt12Invoice;
3131
use crate::onion_message::messenger::Responder;
3232
use crate::routing::gossip::NetworkUpdate;
33-
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
33+
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters, TrampolineHop};
3434
use crate::sign::SpendableOutputDescriptor;
3535
use crate::util::errors::APIError;
3636
use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
@@ -1190,12 +1190,12 @@ pub enum Event {
11901190
/// events generated or serialized by versions prior to 0.0.122.
11911191
next_user_channel_id: Option<u128>,
11921192
/// The node id of the previous node.
1193-
///
1193+
///
11941194
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
11951195
/// versions prior to 0.1
11961196
prev_node_id: Option<PublicKey>,
11971197
/// The node id of the next node.
1198-
///
1198+
///
11991199
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
12001200
/// versions prior to 0.1
12011201
next_node_id: Option<PublicKey>,
@@ -1575,6 +1575,7 @@ impl Writeable for Event {
15751575
(3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
15761576
(4, path.blinded_tail, option),
15771577
(5, path.hops, required_vec),
1578+
(6, path.trampoline_hops, optional_vec),
15781579
(7, short_channel_id, option),
15791580
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
15801581
(11, payment_id, option),
@@ -1665,6 +1666,7 @@ impl Writeable for Event {
16651666
(2, payment_hash, option),
16661667
(4, path.hops, required_vec),
16671668
(6, path.blinded_tail, option),
1669+
(8, path.trampoline_hops, optional_vec),
16681670
})
16691671
},
16701672
&Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
@@ -1729,6 +1731,7 @@ impl Writeable for Event {
17291731
(2, payment_hash, required),
17301732
(4, path.hops, required_vec),
17311733
(6, path.blinded_tail, option),
1734+
(8, path.trampoline_hops, optional_vec),
17321735
})
17331736
},
17341737
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
@@ -1739,6 +1742,7 @@ impl Writeable for Event {
17391742
(4, path.hops, required_vec),
17401743
(6, short_channel_id, option),
17411744
(8, path.blinded_tail, option),
1745+
(10, path.trampoline_hops, optional_vec)
17421746
})
17431747
},
17441748
&Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
@@ -1915,6 +1919,7 @@ impl MaybeReadable for Event {
19151919
let mut network_update = None;
19161920
let mut blinded_tail: Option<BlindedTail> = None;
19171921
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1922+
let mut trampoline_path: Option<Vec<TrampolineHop>> = Some(vec![]);
19181923
let mut short_channel_id = None;
19191924
let mut payment_id = None;
19201925
let mut failure_opt = None;
@@ -1923,6 +1928,7 @@ impl MaybeReadable for Event {
19231928
(1, network_update, upgradable_option),
19241929
(2, payment_failed_permanently, required),
19251930
(4, blinded_tail, option),
1931+
(6, trampoline_path, optional_vec),
19261932
// Added as a part of LDK 0.0.101 and always filled in since.
19271933
// Defaults to an empty Vec, though likely should have been `Option`al.
19281934
(5, path, optional_vec),
@@ -1936,7 +1942,7 @@ impl MaybeReadable for Event {
19361942
payment_hash,
19371943
payment_failed_permanently,
19381944
failure,
1939-
path: Path { hops: path.unwrap(), blinded_tail },
1945+
path: Path { hops: path.unwrap(), trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
19401946
short_channel_id,
19411947
#[cfg(test)]
19421948
error_code,
@@ -2077,11 +2083,12 @@ impl MaybeReadable for Event {
20772083
(2, payment_hash, option),
20782084
(4, path, required_vec),
20792085
(6, blinded_tail, option),
2086+
(8, trampoline_path, optional_vec),
20802087
});
20812088
Ok(Some(Event::PaymentPathSuccessful {
20822089
payment_id: payment_id.0.unwrap(),
20832090
payment_hash,
2084-
path: Path { hops: path, blinded_tail },
2091+
path: Path { hops: path, trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
20852092
}))
20862093
};
20872094
f()
@@ -2157,11 +2164,12 @@ impl MaybeReadable for Event {
21572164
(2, payment_hash, required),
21582165
(4, path, required_vec),
21592166
(6, blinded_tail, option),
2167+
(8, trampoline_path, optional_vec)
21602168
});
21612169
Ok(Some(Event::ProbeSuccessful {
21622170
payment_id: payment_id.0.unwrap(),
21632171
payment_hash: payment_hash.0.unwrap(),
2164-
path: Path { hops: path, blinded_tail },
2172+
path: Path { hops: path, trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
21652173
}))
21662174
};
21672175
f()
@@ -2174,11 +2182,12 @@ impl MaybeReadable for Event {
21742182
(4, path, required_vec),
21752183
(6, short_channel_id, option),
21762184
(8, blinded_tail, option),
2185+
(10, trampoline_path, optional_vec)
21772186
});
21782187
Ok(Some(Event::ProbeFailed {
21792188
payment_id: payment_id.0.unwrap(),
21802189
payment_hash: payment_hash.0.unwrap(),
2181-
path: Path { hops: path, blinded_tail },
2190+
path: Path { hops: path, trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
21822191
short_channel_id,
21832192
}))
21842193
};

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ fn route_blinding_spec_test_vector() {
15041504
cltv_expiry_delta: 42,
15051505
maybe_announced_channel: false,
15061506
}],
1507+
trampoline_hops: vec![],
15071508
blinded_tail: Some(BlindedTail {
15081509
hops: blinded_hops,
15091510
blinding_point: bob_blinding_point,

lightning/src/ln/channel.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10683,7 +10683,7 @@ mod tests {
1068310683
cltv_expiry: 200000000,
1068410684
state: OutboundHTLCState::Committed,
1068510685
source: HTLCSource::OutboundRoute {
10686-
path: Path { hops: Vec::new(), blinded_tail: None },
10686+
path: Path { hops: Vec::new(), trampoline_hops: vec![], blinded_tail: None },
1068710687
session_priv: SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
1068810688
first_hop_htlc_msat: 548,
1068910689
payment_id: PaymentId([42; 32]),
@@ -11059,6 +11059,7 @@ mod tests {
1105911059
node_features: NodeFeatures::empty(), short_channel_id: 0, fee_msat: 0,
1106011060
cltv_expiry_delta: 0, maybe_announced_channel: false,
1106111061
}],
11062+
trampoline_hops: vec![],
1106211063
blinded_tail: None
1106311064
},
1106411065
session_priv: test_utils::privkey(42),

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::ln::channel_state::ChannelDetails;
5555
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5656
#[cfg(any(feature = "_test_utils", test))]
5757
use crate::types::features::Bolt11InvoiceFeatures;
58-
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
58+
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router, TrampolineHop};
5959
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
6060
use crate::ln::msgs;
6161
use crate::ln::onion_utils;
@@ -689,7 +689,7 @@ impl HTLCSource {
689689
pub fn dummy() -> Self {
690690
assert!(cfg!(not(feature = "grind_signatures")));
691691
HTLCSource::OutboundRoute {
692-
path: Path { hops: Vec::new(), blinded_tail: None },
692+
path: Path { hops: Vec::new(), trampoline_hops: Vec::new(), blinded_tail: None },
693693
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
694694
first_hop_htlc_msat: 0,
695695
payment_id: PaymentId([2; 32]),
@@ -12584,20 +12584,22 @@ impl Readable for HTLCSource {
1258412584
let mut payment_id = None;
1258512585
let mut payment_params: Option<PaymentParameters> = None;
1258612586
let mut blinded_tail: Option<BlindedTail> = None;
12587+
let mut trampoline_path: Option<Vec<TrampolineHop>> = Some(vec![]);
1258712588
read_tlv_fields!(reader, {
1258812589
(0, session_priv, required),
1258912590
(1, payment_id, option),
1259012591
(2, first_hop_htlc_msat, required),
1259112592
(4, path_hops, required_vec),
1259212593
(5, payment_params, (option: ReadableArgs, 0)),
1259312594
(6, blinded_tail, option),
12595+
(8, trampoline_path, optional_vec),
1259412596
});
1259512597
if payment_id.is_none() {
1259612598
// For backwards compat, if there was no payment_id written, use the session_priv bytes
1259712599
// instead.
1259812600
payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref()));
1259912601
}
12600-
let path = Path { hops: path_hops, blinded_tail };
12602+
let path = Path { hops: path_hops, trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail };
1260112603
if path.hops.len() == 0 {
1260212604
return Err(DecodeError::InvalidValue);
1260312605
}
@@ -12635,6 +12637,7 @@ impl Writeable for HTLCSource {
1263512637
(4, path.hops, required_vec),
1263612638
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1263712639
(6, path.blinded_tail, option),
12640+
(8, path.trampoline_hops, optional_vec),
1263812641
});
1263912642
}
1264012643
HTLCSource::PreviousHopData(ref field) => {

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ fn fake_network_test() {
10881088
).with_bolt11_features(nodes[1].node.bolt11_invoice_features()).unwrap();
10891089
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 1000000);
10901090
let payment_preimage_1 = send_along_route(&nodes[1],
1091-
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params.clone()) },
1091+
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: Some(route_params.clone()) },
10921092
&vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;
10931093

10941094
let mut hops = Vec::with_capacity(3);
@@ -1122,7 +1122,7 @@ fn fake_network_test() {
11221122
hops[1].fee_msat = chan_2.1.contents.fee_base_msat as u64 + chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
11231123
hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64 + chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
11241124
let payment_hash_2 = send_along_route(&nodes[1],
1125-
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params) },
1125+
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: Some(route_params) },
11261126
&vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;
11271127

11281128
// Claim the rebalances...

lightning/src/ln/onion_payment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ mod tests {
534534
// Ensure the onion will not fit all the payloads by adding a large custom TLV.
535535
recipient_onion.custom_tlvs.push((13377331, vec![0; 1156]));
536536

537-
let path = Path { hops, blinded_tail: None, };
537+
let path = Path { hops, trampoline_hops: vec![], blinded_tail: None, };
538538
let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap();
539539
let (onion_payloads, ..) = super::onion_utils::build_onion_payloads(
540540
&path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage), None
@@ -560,6 +560,7 @@ mod tests {
560560

561561
let path = Path {
562562
hops: hops,
563+
trampoline_hops: vec![],
563564
blinded_tail: None,
564565
};
565566

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ mod tests {
13501350
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
13511351
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
13521352
},
1353-
], blinded_tail: None }],
1353+
], trampoline_hops: vec![], blinded_tail: None }],
13541354
route_params: None,
13551355
};
13561356

lightning/src/ln/outbound_payment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ mod tests {
25822582
fee_msat: 0,
25832583
cltv_expiry_delta: 0,
25842584
maybe_announced_channel: true,
2585-
}], blinded_tail: None }],
2585+
}], trampoline_hops: vec![], blinded_tail: None }],
25862586
route_params: Some(route_params.clone()),
25872587
};
25882588
router.expect_find_route(route_params.clone(), Ok(route.clone()));
@@ -2938,6 +2938,7 @@ mod tests {
29382938
maybe_announced_channel: true,
29392939
}
29402940
],
2941+
trampoline_hops: vec![],
29412942
blinded_tail: None,
29422943
}
29432944
],

0 commit comments

Comments
 (0)