Skip to content

Commit fe237f9

Browse files
committed
Copy Payee into Routes to provide them to ChannelManager
1 parent 87da910 commit fe237f9

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

fuzz/src/chanmon_consistency.rs

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
305305
fee_msat: amt,
306306
cltv_expiry_delta: 200,
307307
}]],
308+
payee: None,
308309
}, payment_hash, &Some(payment_secret)) {
309310
check_payment_err(err);
310311
false
@@ -330,6 +331,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
330331
fee_msat: amt,
331332
cltv_expiry_delta: 200,
332333
}]],
334+
payee: None,
333335
}, payment_hash, &Some(payment_secret)) {
334336
check_payment_err(err);
335337
false

lightning/src/ln/functional_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ fn fake_network_test() {
919919
});
920920
hops[1].fee_msat = chan_4.1.contents.fee_base_msat as u64 + chan_4.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
921921
hops[0].fee_msat = chan_3.0.contents.fee_base_msat as u64 + chan_3.0.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
922-
let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops] }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;
922+
let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;
923923

924924
let mut hops = Vec::with_capacity(3);
925925
hops.push(RouteHop {
@@ -948,7 +948,7 @@ fn fake_network_test() {
948948
});
949949
hops[1].fee_msat = chan_2.1.contents.fee_base_msat as u64 + chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
950950
hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64 + chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
951-
let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops] }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;
951+
let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;
952952

953953
// Claim the rebalances...
954954
fail_payment(&nodes[1], &vec!(&nodes[3], &nodes[2], &nodes[1])[..], payment_hash_2);

lightning/src/ln/onion_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ mod tests {
555555
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
556556
},
557557
]],
558+
payee: None,
558559
};
559560

560561
let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap();

lightning/src/routing/router.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ pub struct Route {
7070
/// given path is variable, keeping the length of any path to less than 20 should currently
7171
/// ensure it is viable.
7272
pub paths: Vec<Vec<RouteHop>>,
73+
/// The `payee` parameter passed to [`get_route`].
74+
/// This is used by `ChannelManager` to track information which may be required for retries,
75+
/// provided back to you via [`Event::PaymentPathFailed`].
76+
///
77+
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
78+
pub payee: Option<Payee>,
7379
}
7480

7581
impl Route {
@@ -106,7 +112,9 @@ impl Writeable for Route {
106112
hop.write(writer)?;
107113
}
108114
}
109-
write_tlv_fields!(writer, {});
115+
write_tlv_fields!(writer, {
116+
(1, self.payee, option),
117+
});
110118
Ok(())
111119
}
112120
}
@@ -124,8 +132,11 @@ impl Readable for Route {
124132
}
125133
paths.push(hops);
126134
}
127-
read_tlv_fields!(reader, {});
128-
Ok(Route { paths })
135+
let mut payee = None;
136+
read_tlv_fields!(reader, {
137+
(1, payee, option),
138+
});
139+
Ok(Route { paths, payee })
129140
}
130141
}
131142

@@ -153,7 +164,7 @@ impl_writeable_tlv_based!(PaymentPathRetry, {
153164
});
154165

155166
/// The recipient of a payment.
156-
#[derive(Clone, Debug)]
167+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
157168
pub struct Payee {
158169
/// The node id of the payee.
159170
pub pubkey: PublicKey,
@@ -1442,7 +1453,10 @@ where L::Target: Logger {
14421453
}
14431454
}
14441455

1445-
let route = Route { paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::<Result<Vec<_>, _>>()? };
1456+
let route = Route {
1457+
paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::<Result<Vec<_>, _>>()?,
1458+
payee: Some(payee.clone()),
1459+
};
14461460
log_info!(logger, "Got route to {}: {}", payee.pubkey, log_route!(route));
14471461
Ok(route)
14481462
}
@@ -4600,6 +4614,7 @@ mod tests {
46004614
short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0
46014615
},
46024616
]],
4617+
payee: None,
46034618
};
46044619

46054620
assert_eq!(route.get_total_fees(), 250);
@@ -4632,6 +4647,7 @@ mod tests {
46324647
short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0
46334648
},
46344649
]],
4650+
payee: None,
46354651
};
46364652

46374653
assert_eq!(route.get_total_fees(), 200);
@@ -4643,7 +4659,7 @@ mod tests {
46434659
// In an earlier version of `Route::get_total_fees` and `Route::get_total_amount`, they
46444660
// would both panic if the route was completely empty. We test to ensure they return 0
46454661
// here, even though its somewhat nonsensical as a route.
4646-
let route = Route { paths: Vec::new() };
4662+
let route = Route { paths: Vec::new(), payee: None };
46474663

46484664
assert_eq!(route.get_total_fees(), 0);
46494665
assert_eq!(route.get_total_amount(), 0);

0 commit comments

Comments
 (0)