Skip to content

Commit 90a6003

Browse files
f adapt to having a RouteHop for the intro node
1 parent 877ba47 commit 90a6003

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ where
25312531
// The top-level caller should hold the total_consistency_lock read lock.
25322532
debug_assert!(self.total_consistency_lock.try_write().is_err());
25332533

2534-
log_trace!(self.logger, "Attempting to send payment for path with next hop {}", path.first_hop_scid());
2534+
log_trace!(self.logger, "Attempting to send payment for path with next hop {}", path.hops.first().unwrap().short_channel_id);
25352535
let prng_seed = self.entropy_source.get_secure_random_bytes();
25362536
let session_priv = SecretKey::from_slice(&session_priv_bytes[..]).expect("RNG is busted");
25372537

@@ -2544,7 +2544,7 @@ where
25442544
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, prng_seed, payment_hash);
25452545

25462546
let err: Result<(), _> = loop {
2547-
let (counterparty_node_id, id) = match self.short_to_chan_info.read().unwrap().get(&path.first_hop_scid()) {
2547+
let (counterparty_node_id, id) = match self.short_to_chan_info.read().unwrap().get(&path.hops.first().unwrap().short_channel_id) {
25482548
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}),
25492549
Some((cp_id, chan_id)) => (cp_id.clone(), chan_id.clone()),
25502550
};
@@ -2595,7 +2595,7 @@ where
25952595
return Ok(());
25962596
};
25972597

2598-
match handle_error!(self, err, path.first_hop_node_id()) {
2598+
match handle_error!(self, err, path.hops.first().unwrap().pubkey) {
25992599
Ok(_) => unreachable!(),
26002600
Err(e) => {
26012601
Err(APIError::ChannelUnavailable { err: e.err })
@@ -7588,7 +7588,7 @@ where
75887588
if id_to_peer.get(&monitor.get_funding_txo().0.to_channel_id()).is_none() {
75897589
for (htlc_source, (htlc, _)) in monitor.get_pending_or_resolved_outbound_htlcs() {
75907590
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, .. } = htlc_source {
7591-
if path.len() == 0 {
7591+
if path.hops.is_empty() {
75927592
log_error!(args.logger, "Got an empty path for a pending payment");
75937593
return Err(DecodeError::InvalidValue);
75947594
}

lightning/src/ln/outbound_payment.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ impl OutboundPayments {
685685
}
686686
};
687687
for path in route.paths.iter() {
688-
if path.len() == 0 {
689-
log_error!(logger, "length-0 path in route");
688+
if path.hops.len() == 0 {
689+
log_error!(logger, "Unusable path in route (path.hops.len() must be at least 1)");
690690
self.abandon_payment(payment_id, PaymentFailureReason::UnexpectedError, pending_events);
691691
return
692692
}
@@ -827,7 +827,7 @@ impl OutboundPayments {
827827
log_error!(logger, "Failed to send along path due to error: {:?}", e);
828828
let mut failed_scid = None;
829829
if let APIError::ChannelUnavailable { .. } = e {
830-
let scid = path.first_hop_scid();
830+
let scid = path.hops[0].short_channel_id;
831831
failed_scid = Some(scid);
832832
route_params.payment_params.previously_failed_channels.push(scid);
833833
}
@@ -953,14 +953,11 @@ impl OutboundPayments {
953953
path_errs.push(Err(APIError::InvalidRoute{err: "Path didn't go anywhere/had bogus size".to_owned()}));
954954
continue 'path_check;
955955
}
956-
let we_are_intermed_hop = path.blinded_tail.as_ref().map_or_else(
957-
|| path.hops.split_last().map_or(false, |(_, path_prefix)| path_prefix.iter().any(|hop| hop.pubkey == our_node_id)),
958-
|tail|
959-
(tail.path.introduction_node_id == our_node_id && tail.path.blinded_hops.len() > 1)
960-
|| path.hops.iter().any(|hop| hop.pubkey == our_node_id));
961-
if we_are_intermed_hop {
962-
path_errs.push(Err(APIError::InvalidRoute{err: "Path went through us but wasn't a simple rebalance loop to us".to_owned()}));
963-
continue 'path_check;
956+
for (idx, hop) in path.hops.iter().enumerate() {
957+
if idx != path.hops.len() - 1 && hop.pubkey == our_node_id {
958+
path_errs.push(Err(APIError::InvalidRoute{err: "Path went through us but wasn't a simple rebalance loop to us".to_owned()}));
959+
continue 'path_check;
960+
}
964961
}
965962
total_value += path.final_value_msat();
966963
path_errs.push(Ok(()));

lightning/src/routing/router.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl Path {
299299
/// Returns the total amount of fees paid on this [`Path`].
300300
pub fn fee_msat(&self) -> u64 {
301301
match &self.blinded_tail {
302-
Some(tail) => self.hops.iter().map(|hop| hop.fee_msat).sum::<u64>() + tail.fee_msat,
302+
Some(_) => self.hops.iter().map(|hop| hop.fee_msat).sum::<u64>(),
303303
None =>
304304
self.hops.split_last().map_or(0,
305305
|(_, path_prefix)| path_prefix.iter().map(|hop| hop.fee_msat).sum())
@@ -318,18 +318,6 @@ impl Path {
318318
pub fn len(&self) -> usize {
319319
self.hops.len() + self.blinded_tail.as_ref().map_or(0, |tail| tail.hops.len().saturating_sub(1)) // Don't double count the intro node
320320
}
321-
322-
pub(crate) fn first_hop_node_id(&self) -> PublicKey {
323-
self.hops.first().map_or_else(
324-
|| self.blinded_tail.as_ref().expect("Path had 0 hops").path.introduction_node_id,
325-
|hop| hop.pubkey)
326-
}
327-
328-
pub(crate) fn first_hop_scid(&self) -> u64 {
329-
self.hops.first().map_or_else(
330-
|| self.blinded_tail.as_ref().expect("Path had 0 hops").intro_node_scid,
331-
|hop| hop.short_channel_id)
332-
}
333321
}
334322

335323
/// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,

0 commit comments

Comments
 (0)