Consider many first-hop paths to the same counterparty in routing
[rust-lightning] / lightning / src / routing / network_graph.rs
index ca656039d122021fe500be7e7252d540160b591c..bdb305e7870a2b9a30e9236c34b516dc2328c873 100644 (file)
@@ -58,6 +58,18 @@ pub struct NetworkGraph {
        nodes: RwLock<BTreeMap<PublicKey, NodeInfo>>,
 }
 
+impl Clone for NetworkGraph {
+       fn clone(&self) -> Self {
+               let channels = self.channels.read().unwrap();
+               let nodes = self.nodes.read().unwrap();
+               Self {
+                       genesis_hash: self.genesis_hash.clone(),
+                       channels: RwLock::new(channels.clone()),
+                       nodes: RwLock::new(nodes.clone()),
+               }
+       }
+}
+
 /// A read-only view of [`NetworkGraph`].
 pub struct ReadOnlyNetworkGraph<'a> {
        channels: RwLockReadGuard<'a, BTreeMap<u64, ChannelInfo>>,
@@ -113,7 +125,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
 impl<C: Deref, L: Deref> EventHandler for NetGraphMsgHandler<C, L>
 where C::Target: chain::Access, L::Target: Logger {
        fn handle_event(&self, event: &Event) {
-               if let Event::PaymentFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
+               if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
                        if let Some(network_update) = network_update {
                                self.handle_network_update(network_update);
                        }
@@ -127,7 +139,7 @@ where C::Target: chain::Access, L::Target: Logger {
 /// Provides interface to help with initial routing sync by
 /// serving historical announcements.
 ///
-/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentFailed`] to the
+/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
 /// [`NetworkGraph`].
 pub struct NetGraphMsgHandler<C: Deref, L: Deref>
 where C::Target: chain::Access, L::Target: Logger
@@ -1725,9 +1737,11 @@ mod tests {
 
                        assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
 
-                       net_graph_msg_handler.handle_event(&Event::PaymentFailed {
+                       net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
                                payment_hash: PaymentHash([0; 32]),
                                rejected_by_dest: false,
+                               all_paths_failed: true,
+                               path: vec![],
                                network_update: Some(NetworkUpdate::ChannelUpdateMessage {
                                        msg: valid_channel_update,
                                }),
@@ -1747,9 +1761,11 @@ mod tests {
                                }
                        };
 
-                       net_graph_msg_handler.handle_event(&Event::PaymentFailed {
+                       net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
                                payment_hash: PaymentHash([0; 32]),
                                rejected_by_dest: false,
+                               all_paths_failed: true,
+                               path: vec![],
                                network_update: Some(NetworkUpdate::ChannelClosed {
                                        short_channel_id,
                                        is_permanent: false,
@@ -1768,9 +1784,11 @@ mod tests {
 
                // Permanent closing deletes a channel
                {
-                       net_graph_msg_handler.handle_event(&Event::PaymentFailed {
+                       net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
                                payment_hash: PaymentHash([0; 32]),
                                rejected_by_dest: false,
+                               all_paths_failed: true,
+                               path: vec![],
                                network_update: Some(NetworkUpdate::ChannelClosed {
                                        short_channel_id,
                                        is_permanent: true,