X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Frouting%2Fnetwork_graph.rs;h=bdb305e7870a2b9a30e9236c34b516dc2328c873;hb=56c75f0bac02db2212f8ef5357befdd5425da55d;hp=16ff80189e96b7dd249d8d96b5112b305e2f272b;hpb=831f124721413323c32e523378969d119dd16526;p=rust-lightning diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 16ff8018..bdb305e7 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -58,6 +58,18 @@ pub struct NetworkGraph { nodes: RwLock>, } +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>, @@ -113,7 +125,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate, impl EventHandler for NetGraphMsgHandler 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 where C::Target: chain::Access, L::Target: Logger @@ -1725,10 +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, }), @@ -1748,10 +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, @@ -1770,10 +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,