]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Copy `Payee` into `Route`s to provide them to `ChannelManager`
authorMatt Corallo <git@bluematt.me>
Mon, 25 Oct 2021 04:42:29 +0000 (04:42 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 25 Oct 2021 17:58:18 +0000 (17:58 +0000)
fuzz/src/chanmon_consistency.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/onion_utils.rs
lightning/src/routing/router.rs

index 28bab5a28f8942550e26c9036984f57cd6a84f3b..464e784d5142e81a2d8e07310b1dc8bad7d15aa4 100644 (file)
@@ -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
index 61e2afef34c4af6ca67ad5fe3ec7a1be8027476b..fc35a030d8ddd7f407fb62ff0f90c62d316ce4d6 100644 (file)
@@ -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);
index 20ff0c8344d4836738b7a63bad1c41db4fc3e36b..c1767c025a3531fe61e523ea39a7250eef5f9732 100644 (file)
@@ -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();
index 099661bb7f7347429534cfd86903950a2df10550..5de71fb6cf1350598908ad3fde56f7a475e98077 100644 (file)
@@ -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<Vec<RouteHop>>,
+       /// 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<Payee>,
 }
 
 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::<Result<Vec<_>, _>>()? };
+       let route = Route {
+               paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::<Result<Vec<_>, _>>()?,
+               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);