Skip to content

Commit ac9e1f6

Browse files
Replace Vec<RouteHop> with new Path struct
This lays groundwork for adding blinded path info to Path
1 parent 7b457e0 commit ac9e1f6

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)]
@@ -495,7 +495,7 @@ pub enum Event {
495495
/// The payment path that was successful.
496496
///
497497
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
498-
path: Vec<RouteHop>,
498+
path: Path,
499499
},
500500
/// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
501501
/// handle the HTLC.
@@ -527,7 +527,7 @@ pub enum Event {
527527
/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
528528
failure: PathFailure,
529529
/// The payment path that failed.
530-
path: Vec<RouteHop>,
530+
path: Path,
531531
/// The channel responsible for the failed payment path.
532532
///
533533
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -553,7 +553,7 @@ pub enum Event {
553553
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
554554
payment_hash: PaymentHash,
555555
/// The payment path that was successful.
556-
path: Vec<RouteHop>,
556+
path: Path,
557557
},
558558
/// Indicates that a probe payment we sent failed at an intermediary node on the path.
559559
ProbeFailed {
@@ -566,7 +566,7 @@ pub enum Event {
566566
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
567567
payment_hash: PaymentHash,
568568
/// The payment path that failed.
569-
path: Vec<RouteHop>,
569+
path: Path,
570570
/// The channel responsible for the failed probe.
571571
///
572572
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -872,7 +872,7 @@ impl Writeable for Event {
872872
(1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
873873
(2, payment_failed_permanently, required),
874874
(3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
875-
(5, *path, vec_type),
875+
(5, path.hops, vec_type),
876876
(7, short_channel_id, option),
877877
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
878878
(11, payment_id, option),
@@ -940,7 +940,7 @@ impl Writeable for Event {
940940
write_tlv_fields!(writer, {
941941
(0, payment_id, required),
942942
(2, payment_hash, option),
943-
(4, *path, vec_type)
943+
(4, path.hops, vec_type),
944944
})
945945
},
946946
&Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
@@ -970,15 +970,15 @@ impl Writeable for Event {
970970
write_tlv_fields!(writer, {
971971
(0, payment_id, required),
972972
(2, payment_hash, required),
973-
(4, *path, vec_type)
973+
(4, path.hops, vec_type),
974974
})
975975
},
976976
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
977977
23u8.write(writer)?;
978978
write_tlv_fields!(writer, {
979979
(0, payment_id, required),
980980
(2, payment_hash, required),
981-
(4, *path, vec_type),
981+
(4, path.hops, vec_type),
982982
(6, short_channel_id, option),
983983
})
984984
},
@@ -1126,7 +1126,7 @@ impl MaybeReadable for Event {
11261126
payment_hash,
11271127
payment_failed_permanently,
11281128
failure,
1129-
path: path.unwrap(),
1129+
path: Path { hops: path.unwrap() },
11301130
short_channel_id,
11311131
#[cfg(test)]
11321132
error_code,
@@ -1240,7 +1240,7 @@ impl MaybeReadable for Event {
12401240
Ok(Some(Event::PaymentPathSuccessful {
12411241
payment_id,
12421242
payment_hash,
1243-
path: path.unwrap(),
1243+
path: Path { hops: path.unwrap() },
12441244
}))
12451245
};
12461246
f()
@@ -1301,7 +1301,7 @@ impl MaybeReadable for Event {
13011301
Ok(Some(Event::ProbeSuccessful {
13021302
payment_id,
13031303
payment_hash,
1304-
path: path.unwrap(),
1304+
path: Path { hops: path.unwrap() },
13051305
}))
13061306
};
13071307
f()
@@ -1321,7 +1321,7 @@ impl MaybeReadable for Event {
13211321
Ok(Some(Event::ProbeFailed {
13221322
payment_id,
13231323
payment_hash,
1324-
path: path.unwrap(),
1324+
path: Path { hops: path.unwrap() },
13251325
short_channel_id,
13261326
}))
13271327
};

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
@@ -7013,6 +7013,7 @@ mod tests {
70137013
use crate::chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
70147014
use crate::chain::keysinterface::{ChannelSigner, InMemorySigner, EntropySource, SignerProvider};
70157015
use crate::chain::transaction::OutPoint;
7016+
use crate::routing::router::Path;
70167017
use crate::util::config::UserConfig;
70177018
use crate::util::enforcing_trait_impls::EnforcingSigner;
70187019
use crate::util::errors::APIError;
@@ -7190,7 +7191,7 @@ mod tests {
71907191
cltv_expiry: 200000000,
71917192
state: OutboundHTLCState::Committed,
71927193
source: HTLCSource::OutboundRoute {
7193-
path: Vec::new(),
7194+
path: Path { hops: Vec::new() },
71947195
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
71957196
first_hop_htlc_msat: 548,
71967197
payment_id: PaymentId([42; 32]),

0 commit comments

Comments
 (0)