From: Matt Corallo Date: Mon, 25 Oct 2021 04:42:29 +0000 (+0000) Subject: Copy `Payee` into `Route`s to provide them to `ChannelManager` X-Git-Tag: v0.0.103~9^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=fe237f9280ae78883104be64c28d6cfc6b61a4c7;p=rust-lightning Copy `Payee` into `Route`s to provide them to `ChannelManager` --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 28bab5a28..464e784d5 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -305,6 +305,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p fee_msat: amt, cltv_expiry_delta: 200, }]], + payee: None, }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false @@ -330,6 +331,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des fee_msat: amt, cltv_expiry_delta: 200, }]], + payee: None, }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 61e2afef3..fc35a030d 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -919,7 +919,7 @@ fn fake_network_test() { }); 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; 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; - let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops] }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0; + let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0; let mut hops = Vec::with_capacity(3); hops.push(RouteHop { @@ -948,7 +948,7 @@ fn fake_network_test() { }); 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; 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; - let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops] }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1; + let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1; // Claim the rebalances... fail_payment(&nodes[1], &vec!(&nodes[3], &nodes[2], &nodes[1])[..], payment_hash_2); diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 20ff0c834..c1767c025 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -555,6 +555,7 @@ mod tests { 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 }, ]], + payee: None, }; let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap(); diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 099661bb7..5de71fb6c 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -70,6 +70,12 @@ pub struct Route { /// given path is variable, keeping the length of any path to less than 20 should currently /// ensure it is viable. pub paths: Vec>, + /// The `payee` parameter passed to [`get_route`]. + /// This is used by `ChannelManager` to track information which may be required for retries, + /// provided back to you via [`Event::PaymentPathFailed`]. + /// + /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed + pub payee: Option, } impl Route { @@ -106,7 +112,9 @@ impl Writeable for Route { hop.write(writer)?; } } - write_tlv_fields!(writer, {}); + write_tlv_fields!(writer, { + (1, self.payee, option), + }); Ok(()) } } @@ -124,8 +132,11 @@ impl Readable for Route { } paths.push(hops); } - read_tlv_fields!(reader, {}); - Ok(Route { paths }) + let mut payee = None; + read_tlv_fields!(reader, { + (1, payee, option), + }); + Ok(Route { paths, payee }) } } @@ -153,7 +164,7 @@ impl_writeable_tlv_based!(PaymentPathRetry, { }); /// The recipient of a payment. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct Payee { /// The node id of the payee. pub pubkey: PublicKey, @@ -1442,7 +1453,10 @@ where L::Target: Logger { } } - let route = Route { paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::, _>>()? }; + let route = Route { + paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::, _>>()?, + payee: Some(payee.clone()), + }; log_info!(logger, "Got route to {}: {}", payee.pubkey, log_route!(route)); Ok(route) } @@ -4600,6 +4614,7 @@ mod tests { short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0 }, ]], + payee: None, }; assert_eq!(route.get_total_fees(), 250); @@ -4632,6 +4647,7 @@ mod tests { short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0 }, ]], + payee: None, }; assert_eq!(route.get_total_fees(), 200); @@ -4643,7 +4659,7 @@ mod tests { // In an earlier version of `Route::get_total_fees` and `Route::get_total_amount`, they // would both panic if the route was completely empty. We test to ensure they return 0 // here, even though its somewhat nonsensical as a route. - let route = Route { paths: Vec::new() }; + let route = Route { paths: Vec::new(), payee: None }; assert_eq!(route.get_total_fees(), 0); assert_eq!(route.get_total_amount(), 0);