Skip to content

Commit 19675e7

Browse files
committed
Replace a route hop data tuple with a struct
1 parent 992cc63 commit 19675e7

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

lightning/src/routing/router.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ struct DummyDirectionalChannelInfo {
165165
fees: RoutingFees,
166166
}
167167

168+
struct RouteHopInGraph {
169+
route_hop: RouteHop,
170+
total_fee: u64,
171+
available_msat: Option<u64>,
172+
node_lowest_inbound_fees: RoutingFees,
173+
}
168174

169175
/// Gets a route from us to the given target node.
170176
///
@@ -267,26 +273,29 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, targ
267273
fee_base_msat = fees.base_msat;
268274
fee_proportional_millionths = fees.proportional_millionths;
269275
};
270-
(u64::max_value(),
271-
fee_base_msat,
272-
fee_proportional_millionths,
273-
RouteHop {
276+
RouteHopInGraph {
277+
route_hop: RouteHop {
274278
pubkey: $dest_node_id.clone(),
275279
node_features: NodeFeatures::empty(),
276280
short_channel_id: 0,
277281
channel_features: $chan_features.clone(),
278282
fee_msat: 0,
279283
cltv_expiry_delta: 0,
280284
},
281-
None,
282-
)
285+
total_fee: u64::max_value(),
286+
node_lowest_inbound_fees: RoutingFees {
287+
base_msat: fee_base_msat,
288+
proportional_millionths: fee_proportional_millionths,
289+
},
290+
available_msat: None,
291+
}
283292
});
284293
if $src_node_id != *our_node_id {
285294
// Ignore new_fee for channel-from-us as we assume all channels-from-us
286295
// will have the same effective-fee
287296
total_fee += new_fee;
288-
if let Some(fee_inc) = final_value_msat.checked_add(total_fee).and_then(|inc| { (old_entry.2 as u64).checked_mul(inc) }) {
289-
total_fee += fee_inc / 1000000 + (old_entry.1 as u64);
297+
if let Some(fee_inc) = final_value_msat.checked_add(total_fee).and_then(|inc| { (old_entry.node_lowest_inbound_fees.proportional_millionths as u64).checked_mul(inc) }) {
298+
total_fee += fee_inc / 1000000 + (old_entry.node_lowest_inbound_fees.base_msat as u64);
290299
} else {
291300
// max_value means we'll always fail the old_entry.0 > total_fee check
292301
total_fee = u64::max_value();
@@ -297,18 +306,18 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, targ
297306
lowest_fee_to_peer_through_node: total_fee,
298307
lowest_fee_to_node: $starting_fee_msat as u64 + new_fee,
299308
};
300-
if old_entry.0 > total_fee {
309+
if old_entry.total_fee > total_fee {
301310
targets.push(new_graph_node);
302-
old_entry.0 = total_fee;
303-
old_entry.3 = RouteHop {
311+
old_entry.total_fee = total_fee;
312+
old_entry.route_hop = RouteHop {
304313
pubkey: $dest_node_id.clone(),
305314
node_features: NodeFeatures::empty(),
306315
short_channel_id: $chan_id.clone(),
307316
channel_features: $chan_features.clone(),
308317
fee_msat: new_fee, // This field is ignored on the last-hop anyway
309318
cltv_expiry_delta: $directional_info.cltv_expiry_delta as u32,
310319
};
311-
old_entry.4 = available_msat;
320+
old_entry.available_msat = available_msat;
312321
}
313322
}
314323
}
@@ -387,7 +396,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, targ
387396

388397
while let Some(RouteGraphNode { pubkey, lowest_fee_to_node, .. }) = targets.pop() {
389398
if pubkey == *our_node_id {
390-
let mut res = vec!(dist.remove(&our_node_id).unwrap().3);
399+
let mut res = vec!(dist.remove(&our_node_id).unwrap().route_hop);
391400
loop {
392401
if let Some(&(_, ref features)) = first_hop_targets.get(&res.last().unwrap().pubkey) {
393402
res.last_mut().unwrap().node_features = features.to_context();
@@ -409,7 +418,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, targ
409418
}
410419

411420
let new_entry = match dist.remove(&res.last().unwrap().pubkey) {
412-
Some(hop) => hop.3,
421+
Some(hop) => hop.route_hop,
413422
None => return Err(LightningError{err: "Failed to find a non-fee-overflowing path to the given destination".to_owned(), action: ErrorAction::IgnoreError}),
414423
};
415424
res.last_mut().unwrap().fee_msat = new_entry.fee_msat;

0 commit comments

Comments
 (0)