Skip to content

Commit a3f7fb2

Browse files
Provide the full Path in payment and probe fail/success events
1 parent 1e9cd51 commit a3f7fb2

File tree

5 files changed

+55
-56
lines changed

5 files changed

+55
-56
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,25 @@ 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<_>>();
239+
let path = path.hops.iter().collect::<Vec<_>>();
240240
score.payment_path_failed(&path, *scid);
241241
},
242242
Event::PaymentPathFailed { ref path, payment_failed_permanently: true, .. } => {
243243
// Reached if the destination explicitly failed it back. We treat this as a successful probe
244244
// because the payment made it all the way to the destination with sufficient liquidity.
245-
let path = path.iter().collect::<Vec<_>>();
245+
let path = path.hops.iter().collect::<Vec<_>>();
246246
score.probe_successful(&path);
247247
},
248248
Event::PaymentPathSuccessful { path, .. } => {
249-
let path = path.iter().collect::<Vec<_>>();
249+
let path = path.hops.iter().collect::<Vec<_>>();
250250
score.payment_path_successful(&path);
251251
},
252252
Event::ProbeSuccessful { path, .. } => {
253-
let path = path.iter().collect::<Vec<_>>();
253+
let path = path.hops.iter().collect::<Vec<_>>();
254254
score.probe_successful(&path);
255255
},
256256
Event::ProbeFailed { path, short_channel_id: Some(scid), .. } => {
257-
let path = path.iter().collect::<Vec<_>>();
257+
let path = path.hops.iter().collect::<Vec<_>>();
258258
score.probe_failed(&path, *scid);
259259
},
260260
_ => {},
@@ -751,7 +751,7 @@ mod tests {
751751
use lightning::ln::msgs::{ChannelMessageHandler, Init};
752752
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
753753
use lightning::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
754-
use lightning::routing::router::{DefaultRouter, RouteHop};
754+
use lightning::routing::router::{DefaultRouter, Path, RouteHop};
755755
use lightning::routing::scoring::{ChannelUsage, Score};
756756
use lightning::util::config::UserConfig;
757757
use lightning::util::ser::Writeable;
@@ -891,10 +891,10 @@ mod tests {
891891

892892
#[derive(Debug)]
893893
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> },
894+
PaymentFailure { path: Path, short_channel_id: u64 },
895+
PaymentSuccess { path: Path },
896+
ProbeFailure { path: Path },
897+
ProbeSuccess { path: Path },
898898
}
899899

900900
impl TestScorer {
@@ -920,7 +920,7 @@ mod tests {
920920
if let Some(expectations) = &mut self.event_expectations {
921921
match expectations.pop_front().unwrap() {
922922
TestResult::PaymentFailure { path, short_channel_id } => {
923-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
923+
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
924924
assert_eq!(actual_short_channel_id, short_channel_id);
925925
},
926926
TestResult::PaymentSuccess { path } => {
@@ -943,7 +943,7 @@ mod tests {
943943
panic!("Unexpected payment path failure: {:?}", path)
944944
},
945945
TestResult::PaymentSuccess { path } => {
946-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
946+
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
947947
},
948948
TestResult::ProbeFailure { path } => {
949949
panic!("Unexpected probe failure: {:?}", path)
@@ -965,7 +965,7 @@ mod tests {
965965
panic!("Unexpected payment path success: {:?}", path)
966966
},
967967
TestResult::ProbeFailure { path } => {
968-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
968+
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
969969
},
970970
TestResult::ProbeSuccess { path } => {
971971
panic!("Unexpected probe success: {:?}", path)
@@ -986,7 +986,7 @@ mod tests {
986986
panic!("Unexpected probe failure: {:?}", path)
987987
},
988988
TestResult::ProbeSuccess { path } => {
989-
assert_eq!(actual_path, &path.iter().collect::<Vec<_>>()[..]);
989+
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
990990
}
991991
}
992992
}
@@ -1510,14 +1510,14 @@ mod tests {
15101510
let node_1_privkey = SecretKey::from_slice(&[42; 32]).unwrap();
15111511
let node_1_id = PublicKey::from_secret_key(&secp_ctx, &node_1_privkey);
15121512

1513-
let path = vec![RouteHop {
1513+
let path = Path { hops: vec![RouteHop {
15141514
pubkey: node_1_id,
15151515
node_features: NodeFeatures::empty(),
15161516
short_channel_id: scored_scid,
15171517
channel_features: ChannelFeatures::empty(),
15181518
fee_msat: 0,
15191519
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
1520-
}];
1520+
}], blinded_tail: None };
15211521

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

lightning/src/events/mod.rs

Lines changed: 30 additions & 31 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::{BlindedTail, Path, RouteHop, RouteParameters};
3434

3535
use bitcoin::{PackedLockTime, Transaction, OutPoint};
3636
#[cfg(anchors)]
@@ -447,7 +447,7 @@ pub enum Event {
447447
/// The payment path that was successful.
448448
///
449449
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
450-
path: Vec<RouteHop>,
450+
path: Path,
451451
},
452452
/// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
453453
/// handle the HTLC.
@@ -480,7 +480,7 @@ pub enum Event {
480480
/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
481481
failure: PathFailure,
482482
/// The payment path that failed.
483-
path: Vec<RouteHop>,
483+
path: Path,
484484
/// The channel responsible for the failed payment path.
485485
///
486486
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -506,7 +506,7 @@ pub enum Event {
506506
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
507507
payment_hash: PaymentHash,
508508
/// The payment path that was successful.
509-
path: Vec<RouteHop>,
509+
path: Path,
510510
},
511511
/// Indicates that a probe payment we sent failed at an intermediary node on the path.
512512
ProbeFailed {
@@ -519,7 +519,7 @@ pub enum Event {
519519
/// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
520520
payment_hash: PaymentHash,
521521
/// The payment path that failed.
522-
path: Vec<RouteHop>,
522+
path: Path,
523523
/// The channel responsible for the failed probe.
524524
///
525525
/// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -824,7 +824,8 @@ impl Writeable for Event {
824824
(1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
825825
(2, payment_failed_permanently, required),
826826
(3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
827-
(5, *path, vec_type),
827+
(4, path.blinded_tail, option),
828+
(5, path.hops, vec_type),
828829
(7, short_channel_id, option),
829830
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
830831
(11, payment_id, option),
@@ -892,7 +893,8 @@ impl Writeable for Event {
892893
write_tlv_fields!(writer, {
893894
(0, payment_id, required),
894895
(2, payment_hash, option),
895-
(4, *path, vec_type)
896+
(4, path.hops, vec_type),
897+
(6, path.blinded_tail, option),
896898
})
897899
},
898900
&Event::PaymentFailed { ref payment_id, ref payment_hash } => {
@@ -921,16 +923,18 @@ impl Writeable for Event {
921923
write_tlv_fields!(writer, {
922924
(0, payment_id, required),
923925
(2, payment_hash, required),
924-
(4, *path, vec_type)
926+
(4, path.hops, vec_type),
927+
(6, path.blinded_tail, option),
925928
})
926929
},
927930
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
928931
23u8.write(writer)?;
929932
write_tlv_fields!(writer, {
930933
(0, payment_id, required),
931934
(2, payment_hash, required),
932-
(4, *path, vec_type),
935+
(4, path.hops, vec_type),
933936
(6, short_channel_id, option),
937+
(8, path.blinded_tail, option),
934938
})
935939
},
936940
&Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
@@ -1055,6 +1059,7 @@ impl MaybeReadable for Event {
10551059
let mut payment_hash = PaymentHash([0; 32]);
10561060
let mut payment_failed_permanently = false;
10571061
let mut network_update = None;
1062+
let mut blinded_tail: Option<BlindedTail> = None;
10581063
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
10591064
let mut short_channel_id = None;
10601065
let mut payment_id = None;
@@ -1063,6 +1068,7 @@ impl MaybeReadable for Event {
10631068
(0, payment_hash, required),
10641069
(1, network_update, upgradable_option),
10651070
(2, payment_failed_permanently, required),
1071+
(4, blinded_tail, option),
10661072
(5, path, vec_type),
10671073
(7, short_channel_id, option),
10681074
(11, payment_id, option),
@@ -1074,7 +1080,7 @@ impl MaybeReadable for Event {
10741080
payment_hash,
10751081
payment_failed_permanently,
10761082
failure,
1077-
path: path.unwrap(),
1083+
path: Path { hops: path.unwrap(), blinded_tail },
10781084
short_channel_id,
10791085
#[cfg(test)]
10801086
error_code,
@@ -1177,18 +1183,16 @@ impl MaybeReadable for Event {
11771183
},
11781184
13u8 => {
11791185
let f = || {
1180-
let mut payment_id = PaymentId([0; 32]);
1181-
let mut payment_hash = None;
1182-
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1183-
read_tlv_fields!(reader, {
1186+
_init_and_read_tlv_fields!(reader, {
11841187
(0, payment_id, required),
11851188
(2, payment_hash, option),
11861189
(4, path, vec_type),
1190+
(6, blinded_tail, option),
11871191
});
11881192
Ok(Some(Event::PaymentPathSuccessful {
1189-
payment_id,
1193+
payment_id: payment_id.0.unwrap(),
11901194
payment_hash,
1191-
path: path.unwrap(),
1195+
path: Path { hops: path.unwrap(), blinded_tail },
11921196
}))
11931197
};
11941198
f()
@@ -1235,38 +1239,33 @@ impl MaybeReadable for Event {
12351239
},
12361240
21u8 => {
12371241
let f = || {
1238-
let mut payment_id = PaymentId([0; 32]);
1239-
let mut payment_hash = PaymentHash([0; 32]);
1240-
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1241-
read_tlv_fields!(reader, {
1242+
_init_and_read_tlv_fields!(reader, {
12421243
(0, payment_id, required),
12431244
(2, payment_hash, required),
12441245
(4, path, vec_type),
1246+
(6, blinded_tail, option),
12451247
});
12461248
Ok(Some(Event::ProbeSuccessful {
1247-
payment_id,
1248-
payment_hash,
1249-
path: path.unwrap(),
1249+
payment_id: payment_id.0.unwrap(),
1250+
payment_hash: payment_hash.0.unwrap(),
1251+
path: Path { hops: path.unwrap(), blinded_tail },
12501252
}))
12511253
};
12521254
f()
12531255
},
12541256
23u8 => {
12551257
let f = || {
1256-
let mut payment_id = PaymentId([0; 32]);
1257-
let mut payment_hash = PaymentHash([0; 32]);
1258-
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1259-
let mut short_channel_id = None;
1260-
read_tlv_fields!(reader, {
1258+
_init_and_read_tlv_fields!(reader, {
12611259
(0, payment_id, required),
12621260
(2, payment_hash, required),
12631261
(4, path, vec_type),
12641262
(6, short_channel_id, option),
1263+
(8, blinded_tail, option),
12651264
});
12661265
Ok(Some(Event::ProbeFailed {
1267-
payment_id,
1268-
payment_hash,
1269-
path: path.unwrap(),
1266+
payment_id: payment_id.0.unwrap(),
1267+
payment_hash: payment_hash.0.unwrap(),
1268+
path: Path { hops: path.unwrap(), blinded_tail },
12701269
short_channel_id,
12711270
}))
12721271
};

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8133,15 +8133,15 @@ mod tests {
81338133
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
81348134
assert_eq!(payment_id, *actual_payment_id);
81358135
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());
8136-
assert_eq!(route.paths[0].hops, *path);
8136+
assert_eq!(route.paths[0], *path);
81378137
},
81388138
_ => panic!("Unexpected event"),
81398139
}
81408140
match events[2] {
81418141
Event::PaymentPathSuccessful { payment_id: ref actual_payment_id, ref payment_hash, ref path } => {
81428142
assert_eq!(payment_id, *actual_payment_id);
81438143
assert_eq!(our_payment_hash, *payment_hash.as_ref().unwrap());
8144-
assert_eq!(route.paths[0].hops, *path);
8144+
assert_eq!(route.paths[0], *path);
81458145
},
81468146
_ => panic!("Unexpected event"),
81478147
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ pub fn pass_failed_payment_back<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
23142314
assert_eq!(payment_hash, our_payment_hash);
23152315
assert!(payment_failed_permanently);
23162316
for (idx, hop) in expected_route.iter().enumerate() {
2317-
assert_eq!(hop.node.get_our_node_id(), path[idx].pubkey);
2317+
assert_eq!(hop.node.get_our_node_id(), path.hops[idx].pubkey);
23182318
}
23192319
payment_id.unwrap()
23202320
},

lightning/src/ln/outbound_payment.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl OutboundPayments {
787787
payment_hash,
788788
payment_failed_permanently: false,
789789
failure: events::PathFailure::InitialSend { err: e },
790-
path: path.hops,
790+
path,
791791
short_channel_id: failed_scid,
792792
#[cfg(test)]
793793
error_code: None,
@@ -1042,7 +1042,7 @@ impl OutboundPayments {
10421042
events::Event::PaymentPathSuccessful {
10431043
payment_id,
10441044
payment_hash,
1045-
path: path.hops,
1045+
path,
10461046
}
10471047
);
10481048
}
@@ -1066,7 +1066,7 @@ impl OutboundPayments {
10661066
events::Event::PaymentPathSuccessful {
10671067
payment_id,
10681068
payment_hash: payment.get().payment_hash(),
1069-
path: path.hops,
1069+
path,
10701070
}
10711071
);
10721072
}
@@ -1192,13 +1192,13 @@ impl OutboundPayments {
11921192
events::Event::ProbeSuccessful {
11931193
payment_id: *payment_id,
11941194
payment_hash: payment_hash.clone(),
1195-
path: path.hops.clone(),
1195+
path: path.clone(),
11961196
}
11971197
} else {
11981198
events::Event::ProbeFailed {
11991199
payment_id: *payment_id,
12001200
payment_hash: payment_hash.clone(),
1201-
path: path.hops.clone(),
1201+
path: path.clone(),
12021202
short_channel_id,
12031203
}
12041204
}
@@ -1214,7 +1214,7 @@ impl OutboundPayments {
12141214
payment_hash: payment_hash.clone(),
12151215
payment_failed_permanently: !payment_retryable,
12161216
failure: events::PathFailure::OnPath { network_update },
1217-
path: path.hops.clone(),
1217+
path: path.clone(),
12181218
short_channel_id,
12191219
#[cfg(test)]
12201220
error_code: onion_error_code,

0 commit comments

Comments
 (0)