Skip to content

Commit 81e9f73

Browse files
Replace Vec<RouteHop> with new Path struct
This lays groundwork for adding blinded path info to Path
1 parent b12f984 commit 81e9f73

18 files changed

+838
-848
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use lightning::util::errors::APIError;
5050
use lightning::util::logger::Logger;
5151
use lightning::util::config::UserConfig;
5252
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
53-
use lightning::routing::router::{InFlightHtlcs, Route, RouteHop, RouteParameters, Router};
53+
use lightning::routing::router::{InFlightHtlcs, Path, Route, RouteHop, RouteParameters, Router};
5454

5555
use crate::utils::test_logger::{self, Output};
5656
use crate::utils::test_persister::TestPersister;
@@ -352,14 +352,14 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
352352
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
353353
*payment_idx += 1;
354354
if let Err(err) = source.send_payment_with_route(&Route {
355-
paths: vec![vec![RouteHop {
355+
paths: vec![Path { hops: vec![RouteHop {
356356
pubkey: dest.get_our_node_id(),
357357
node_features: dest.node_features(),
358358
short_channel_id: dest_chan_id,
359359
channel_features: dest.channel_features(),
360360
fee_msat: amt,
361361
cltv_expiry_delta: 200,
362-
}]],
362+
}]}],
363363
payment_params: None,
364364
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
365365
check_payment_err(err);
@@ -374,7 +374,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
374374
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
375375
*payment_idx += 1;
376376
if let Err(err) = source.send_payment_with_route(&Route {
377-
paths: vec![vec![RouteHop {
377+
paths: vec![Path { hops: vec![RouteHop {
378378
pubkey: middle.get_our_node_id(),
379379
node_features: middle.node_features(),
380380
short_channel_id: middle_chan_id,
@@ -388,7 +388,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
388388
channel_features: dest.channel_features(),
389389
fee_msat: amt,
390390
cltv_expiry_delta: 200,
391-
}]],
391+
}]}],
392392
payment_params: None,
393393
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
394394
check_payment_err(err);

lightning-background-processor/src/lib.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,21 @@ fn update_scorer<'a, S: 'static + Deref<Target = SC> + Send + Sync, SC: 'a + Wri
236236
let mut score = scorer.lock();
237237
match event {
238238
Event::PaymentPathFailed { ref path, short_channel_id: Some(scid), .. } => {
239-
let path = path.iter().collect::<Vec<_>>();
240-
score.payment_path_failed(&path, *scid);
239+
score.payment_path_failed(path, *scid);
241240
},
242241
Event::PaymentPathFailed { ref path, payment_failed_permanently: true, .. } => {
243242
// Reached if the destination explicitly failed it back. We treat this as a successful probe
244243
// because the payment made it all the way to the destination with sufficient liquidity.
245-
let path = path.iter().collect::<Vec<_>>();
246-
score.probe_successful(&path);
244+
score.probe_successful(path);
247245
},
248246
Event::PaymentPathSuccessful { path, .. } => {
249-
let path = path.iter().collect::<Vec<_>>();
250-
score.payment_path_successful(&path);
247+
score.payment_path_successful(path);
251248
},
252249
Event::ProbeSuccessful { path, .. } => {
253-
let path = path.iter().collect::<Vec<_>>();
254-
score.probe_successful(&path);
250+
score.probe_successful(path);
255251
},
256252
Event::ProbeFailed { path, short_channel_id: Some(scid), .. } => {
257-
let path = path.iter().collect::<Vec<_>>();
258-
score.probe_failed(&path, *scid);
253+
score.probe_failed(path, *scid);
259254
},
260255
_ => {},
261256
}
@@ -751,7 +746,7 @@ mod tests {
751746
use lightning::ln::msgs::{ChannelMessageHandler, Init};
752747
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
753748
use lightning::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
754-
use lightning::routing::router::{DefaultRouter, RouteHop};
749+
use lightning::routing::router::{DefaultRouter, Path, RouteHop};
755750
use lightning::routing::scoring::{ChannelUsage, Score};
756751
use lightning::util::config::UserConfig;
757752
use lightning::util::ser::Writeable;
@@ -891,10 +886,10 @@ mod tests {
891886

892887
#[derive(Debug)]
893888
enum TestResult {
894-
PaymentFailure { path: Vec<RouteHop>, short_channel_id: u64 },
895-
PaymentSuccess { path: Vec<RouteHop> },
896-
ProbeFailure { path: Vec<RouteHop> },
897-
ProbeSuccess { path: Vec<RouteHop> },
889+
PaymentFailure { path: Path, short_channel_id: u64 },
890+
PaymentSuccess { path: Path },
891+
ProbeFailure { path: Path },
892+
ProbeSuccess { path: Path },
898893
}
899894

900895
impl TestScorer {
@@ -916,11 +911,11 @@ mod tests {
916911
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage
917912
) -> u64 { unimplemented!(); }
918913

919-
fn payment_path_failed(&mut self, actual_path: &[&RouteHop], actual_short_channel_id: u64) {
914+
fn payment_path_failed(&mut self, actual_path: &Path, actual_short_channel_id: u64) {
920915
if let Some(expectations) = &mut self.event_expectations {
921916
match expectations.pop_front().unwrap() {
922917
TestResult::PaymentFailure { path, short_channel_id } => {
923-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
918+
assert_eq!(actual_path, &path);
924919
assert_eq!(actual_short_channel_id, short_channel_id);
925920
},
926921
TestResult::PaymentSuccess { path } => {
@@ -936,14 +931,14 @@ mod tests {
936931
}
937932
}
938933

939-
fn payment_path_successful(&mut self, actual_path: &[&RouteHop]) {
934+
fn payment_path_successful(&mut self, actual_path: &Path) {
940935
if let Some(expectations) = &mut self.event_expectations {
941936
match expectations.pop_front().unwrap() {
942937
TestResult::PaymentFailure { path, .. } => {
943938
panic!("Unexpected payment path failure: {:?}", path)
944939
},
945940
TestResult::PaymentSuccess { path } => {
946-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
941+
assert_eq!(actual_path, &path);
947942
},
948943
TestResult::ProbeFailure { path } => {
949944
panic!("Unexpected probe failure: {:?}", path)
@@ -955,7 +950,7 @@ mod tests {
955950
}
956951
}
957952

958-
fn probe_failed(&mut self, actual_path: &[&RouteHop], _: u64) {
953+
fn probe_failed(&mut self, actual_path: &Path, _: u64) {
959954
if let Some(expectations) = &mut self.event_expectations {
960955
match expectations.pop_front().unwrap() {
961956
TestResult::PaymentFailure { path, .. } => {
@@ -965,15 +960,15 @@ mod tests {
965960
panic!("Unexpected payment path success: {:?}", path)
966961
},
967962
TestResult::ProbeFailure { path } => {
968-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
963+
assert_eq!(actual_path, &path);
969964
},
970965
TestResult::ProbeSuccess { path } => {
971966
panic!("Unexpected probe success: {:?}", path)
972967
}
973968
}
974969
}
975970
}
976-
fn probe_successful(&mut self, actual_path: &[&RouteHop]) {
971+
fn probe_successful(&mut self, actual_path: &Path) {
977972
if let Some(expectations) = &mut self.event_expectations {
978973
match expectations.pop_front().unwrap() {
979974
TestResult::PaymentFailure { path, .. } => {
@@ -986,7 +981,7 @@ mod tests {
986981
panic!("Unexpected probe failure: {:?}", path)
987982
},
988983
TestResult::ProbeSuccess { path } => {
989-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
984+
assert_eq!(actual_path, &path);
990985
}
991986
}
992987
}
@@ -1510,14 +1505,14 @@ mod tests {
15101505
let node_1_privkey = SecretKey::from_slice(&[42; 32]).unwrap();
15111506
let node_1_id = PublicKey::from_secret_key(&secp_ctx, &node_1_privkey);
15121507

1513-
let path = vec![RouteHop {
1508+
let path = Path { hops: vec![RouteHop {
15141509
pubkey: node_1_id,
15151510
node_features: NodeFeatures::empty(),
15161511
short_channel_id: scored_scid,
15171512
channel_features: ChannelFeatures::empty(),
15181513
fee_msat: 0,
15191514
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
1520-
}];
1515+
}]};
15211516

15221517
$nodes[0].scorer.lock().unwrap().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
15231518
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {

lightning/src/events/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::routing::gossip::NetworkUpdate;
3030
use crate::util::errors::APIError;
3131
use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
3232
use crate::util::string::UntrustedString;
33-
use crate::routing::router::{RouteHop, RouteParameters};
33+
use crate::routing::router::{Path, RouteHop, RouteParameters};
3434

3535
use bitcoin::{PackedLockTime, Transaction, OutPoint};
3636
#[cfg(anchors)]
@@ -503,7 +503,7 @@ pub enum Event {
503503
/// The payment path that was successful.
504504
///
505505
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
506-
path: Vec<RouteHop>,
506+
path: Path,
507507
},
508508
/// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
509509
/// handle the HTLC.
@@ -535,7 +535,7 @@ pub enum Event {
535535
/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
536536
failure: PathFailure,
537537
/// The payment path that failed.
538-
path: Vec<RouteHop>,
538+
path: Path,
539539
/// The channel responsible for the failed payment path.
540540
///
541541
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -561,7 +561,7 @@ pub enum Event {
561561
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
562562
payment_hash: PaymentHash,
563563
/// The payment path that was successful.
564-
path: Vec<RouteHop>,
564+
path: Path,
565565
},
566566
/// Indicates that a probe payment we sent failed at an intermediary node on the path.
567567
ProbeFailed {
@@ -574,7 +574,7 @@ pub enum Event {
574574
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
575575
payment_hash: PaymentHash,
576576
/// The payment path that failed.
577-
path: Vec<RouteHop>,
577+
path: Path,
578578
/// The channel responsible for the failed probe.
579579
///
580580
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -884,7 +884,7 @@ impl Writeable for Event {
884884
(1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
885885
(2, payment_failed_permanently, required),
886886
(3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
887-
(5, *path, vec_type),
887+
(5, path.hops, vec_type),
888888
(7, short_channel_id, option),
889889
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
890890
(11, payment_id, option),
@@ -952,7 +952,7 @@ impl Writeable for Event {
952952
write_tlv_fields!(writer, {
953953
(0, payment_id, required),
954954
(2, payment_hash, option),
955-
(4, *path, vec_type)
955+
(4, path.hops, vec_type),
956956
})
957957
},
958958
&Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
@@ -982,15 +982,15 @@ impl Writeable for Event {
982982
write_tlv_fields!(writer, {
983983
(0, payment_id, required),
984984
(2, payment_hash, required),
985-
(4, *path, vec_type)
985+
(4, path.hops, vec_type),
986986
})
987987
},
988988
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
989989
23u8.write(writer)?;
990990
write_tlv_fields!(writer, {
991991
(0, payment_id, required),
992992
(2, payment_hash, required),
993-
(4, *path, vec_type),
993+
(4, path.hops, vec_type),
994994
(6, short_channel_id, option),
995995
})
996996
},
@@ -1141,7 +1141,7 @@ impl MaybeReadable for Event {
11411141
payment_hash,
11421142
payment_failed_permanently,
11431143
failure,
1144-
path: path.unwrap(),
1144+
path: Path { hops: path.unwrap() },
11451145
short_channel_id,
11461146
#[cfg(test)]
11471147
error_code,
@@ -1255,7 +1255,7 @@ impl MaybeReadable for Event {
12551255
Ok(Some(Event::PaymentPathSuccessful {
12561256
payment_id,
12571257
payment_hash,
1258-
path: path.unwrap(),
1258+
path: Path { hops: path.unwrap() },
12591259
}))
12601260
};
12611261
f()
@@ -1316,7 +1316,7 @@ impl MaybeReadable for Event {
13161316
Ok(Some(Event::ProbeSuccessful {
13171317
payment_id,
13181318
payment_hash,
1319-
path: path.unwrap(),
1319+
path: Path { hops: path.unwrap() },
13201320
}))
13211321
};
13221322
f()
@@ -1336,7 +1336,7 @@ impl MaybeReadable for Event {
13361336
Ok(Some(Event::ProbeFailed {
13371337
payment_id,
13381338
payment_hash,
1339-
path: path.unwrap(),
1339+
path: Path { hops: path.unwrap() },
13401340
short_channel_id,
13411341
}))
13421342
};

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,12 +2000,12 @@ fn test_path_paused_mpp() {
20002000
// Set us up to take multiple routes, one 0 -> 1 -> 3 and one 0 -> 2 -> 3:
20012001
let path = route.paths[0].clone();
20022002
route.paths.push(path);
2003-
route.paths[0][0].pubkey = nodes[1].node.get_our_node_id();
2004-
route.paths[0][0].short_channel_id = chan_1_id;
2005-
route.paths[0][1].short_channel_id = chan_3_id;
2006-
route.paths[1][0].pubkey = nodes[2].node.get_our_node_id();
2007-
route.paths[1][0].short_channel_id = chan_2_ann.contents.short_channel_id;
2008-
route.paths[1][1].short_channel_id = chan_4_id;
2003+
route.paths[0].hops[0].pubkey = nodes[1].node.get_our_node_id();
2004+
route.paths[0].hops[0].short_channel_id = chan_1_id;
2005+
route.paths[0].hops[1].short_channel_id = chan_3_id;
2006+
route.paths[1].hops[0].pubkey = nodes[2].node.get_our_node_id();
2007+
route.paths[1].hops[0].short_channel_id = chan_2_ann.contents.short_channel_id;
2008+
route.paths[1].hops[1].short_channel_id = chan_4_id;
20092009

20102010
// Set it so that the first monitor update (for the path 0 -> 1 -> 3) succeeds, but the second
20112011
// (for the path 0 -> 2 -> 3) fails.

lightning/src/ln/channel.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7024,6 +7024,7 @@ mod tests {
70247024
use crate::chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
70257025
use crate::chain::keysinterface::{ChannelSigner, InMemorySigner, EntropySource, SignerProvider};
70267026
use crate::chain::transaction::OutPoint;
7027+
use crate::routing::router::Path;
70277028
use crate::util::config::UserConfig;
70287029
use crate::util::enforcing_trait_impls::EnforcingSigner;
70297030
use crate::util::errors::APIError;
@@ -7201,7 +7202,7 @@ mod tests {
72017202
cltv_expiry: 200000000,
72027203
state: OutboundHTLCState::Committed,
72037204
source: HTLCSource::OutboundRoute {
7204-
path: Vec::new(),
7205+
path: Path { hops: Vec::new() },
72057206
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
72067207
first_hop_htlc_msat: 548,
72077208
payment_id: PaymentId([42; 32]),

0 commit comments

Comments
 (0)