Add some trace logging in peer_handler
[rust-lightning] / src / ln / router.rs
index 665a24d2886ec5d8106333ef504ec565277c9348..f4bf32a042513c5582b22c2d38387dd8029afc67 100644 (file)
@@ -89,6 +89,18 @@ impl NetworkMap {
        fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 {
                short_channel_id
        }
+
+       #[cfg(feature = "non_bitcoin_chain_hash_routing")]
+       #[inline]
+       fn get_short_id(id: &(u64, Sha256dHash)) -> &u64 {
+               &id.0
+       }
+
+       #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
+       #[inline]
+       fn get_short_id(id: &u64) -> &u64 {
+               id
+       }
 }
 
 /// A channel descriptor which provides a last-hop route to get_route
@@ -224,7 +236,14 @@ impl RoutingMessageHandler for Router {
                        },
                        &msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id } => {
                                let mut network = self.network_map.write().unwrap();
-                               network.channels.remove(short_channel_id);
+                               if let Some(chan) = network.channels.remove(short_channel_id) {
+                                       network.nodes.get_mut(&chan.one_to_two.src_node_id).unwrap().channels.retain(|chan_id| {
+                                               chan_id != NetworkMap::get_short_id(chan_id)
+                                       });
+                                       network.nodes.get_mut(&chan.two_to_one.src_node_id).unwrap().channels.retain(|chan_id| {
+                                               chan_id != NetworkMap::get_short_id(chan_id)
+                                       });
+                               }
                        },
                }
        }
@@ -448,7 +467,7 @@ impl Router {
                                                                node.lowest_inbound_channel_fee_base_msat,
                                                                node.lowest_inbound_channel_fee_proportional_millionths,
                                                                RouteHop {
-                                                                       pubkey: PublicKey::new(),
+                                                                       pubkey: $dest_node_id.clone(),
                                                                        short_channel_id: 0,
                                                                        fee_msat: 0,
                                                                        cltv_expiry_delta: 0,
@@ -537,7 +556,10 @@ impl Router {
                        if pubkey == network.our_node_id {
                                let mut res = vec!(dist.remove(&network.our_node_id).unwrap().3);
                                while res.last().unwrap().pubkey != *target {
-                                       let new_entry = dist.remove(&res.last().unwrap().pubkey).unwrap().3;
+                                       let new_entry = match dist.remove(&res.last().unwrap().pubkey) {
+                                               Some(hop) => hop.3,
+                                               None => return Err(HandleError{err: "Failed to find a non-fee-overflowing path to the given destination", action: None}),
+                                       };
                                        res.last_mut().unwrap().fee_msat = new_entry.fee_msat;
                                        res.last_mut().unwrap().cltv_expiry_delta = new_entry.cltv_expiry_delta;
                                        res.push(new_entry);