]> git.bitcoin.ninja Git - rust-lightning/blobdiff - lightning/src/ln/router.rs
Merge pull request #447 from ariard/2020-01-fix-weight-computation
[rust-lightning] / lightning / src / ln / router.rs
index 5a21055cab6d5e4d1d3edb7f5192a19b08fc35c2..15390f98ef74db04b2dd9bf2d64a9a76321f56d5 100644 (file)
@@ -14,7 +14,8 @@ use bitcoin::blockdata::opcodes;
 
 use chain::chaininterface::{ChainError, ChainWatchInterface};
 use ln::channelmanager;
-use ln::msgs::{DecodeError,ErrorAction,LightningError,RoutingMessageHandler,NetAddress,ChannelFeatures,NodeFeatures};
+use ln::features::{ChannelFeatures, NodeFeatures};
+use ln::msgs::{DecodeError,ErrorAction,LightningError,RoutingMessageHandler,NetAddress};
 use ln::msgs;
 use util::ser::{Writeable, Readable, Writer, ReadableArgs};
 use util::logger::Logger;
@@ -274,21 +275,6 @@ impl<R: ::std::io::Read> Readable<R> for NetworkMap {
        }
 }
 
-struct MutNetworkMap<'a> {
-       #[cfg(feature = "non_bitcoin_chain_hash_routing")]
-       channels: &'a mut BTreeMap<(u64, Sha256dHash), ChannelInfo>,
-       #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
-       channels: &'a mut BTreeMap<u64, ChannelInfo>,
-       nodes: &'a mut BTreeMap<PublicKey, NodeInfo>,
-}
-impl NetworkMap {
-       fn borrow_parts(&mut self) -> MutNetworkMap {
-               MutNetworkMap {
-                       channels: &mut self.channels,
-                       nodes: &mut self.nodes,
-               }
-       }
-}
 impl std::fmt::Display for NetworkMap {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
                write!(f, "Node id {} network map\n[Channels]\n", log_pubkey!(self.our_node_id))?;
@@ -473,7 +459,7 @@ impl RoutingMessageHandler for Router {
                };
 
                let mut network_lock = self.network_map.write().unwrap();
-               let network = network_lock.borrow_parts();
+               let network = &mut *network_lock;
 
                let should_relay = msg.contents.excess_data.is_empty();
 
@@ -516,7 +502,7 @@ impl RoutingMessageHandler for Router {
                                        // b) we don't track UTXOs of channels we know about and remove them if they
                                        //    get reorg'd out.
                                        // c) it's unclear how to do so without exposing ourselves to massive DoS risk.
-                                       Self::remove_channel_in_nodes(network.nodes, &entry.get(), msg.contents.short_channel_id);
+                                       Self::remove_channel_in_nodes(&mut network.nodes, &entry.get(), msg.contents.short_channel_id);
                                        *entry.get_mut() = chan_info;
                                } else {
                                        return Err(LightningError{err: "Already have knowledge of channel", action: ErrorAction::IgnoreError})
@@ -538,7 +524,7 @@ impl RoutingMessageHandler for Router {
                                                        channels: vec!(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)),
                                                        lowest_inbound_channel_fee_base_msat: u32::max_value(),
                                                        lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
-                                                       features: NodeFeatures::new(),
+                                                       features: NodeFeatures::empty(),
                                                        last_update: 0,
                                                        rgb: [0; 3],
                                                        alias: [0; 32],
@@ -740,7 +726,7 @@ impl Router {
                        channels: Vec::new(),
                        lowest_inbound_channel_fee_base_msat: u32::max_value(),
                        lowest_inbound_channel_fee_proportional_millionths: u32::max_value(),
-                       features: NodeFeatures::new(),
+                       features: NodeFeatures::empty(),
                        last_update: 0,
                        rgb: [0; 3],
                        alias: [0; 32],
@@ -1011,7 +997,8 @@ mod tests {
        use chain::chaininterface;
        use ln::channelmanager;
        use ln::router::{Router,NodeInfo,NetworkMap,ChannelInfo,DirectionalChannelInfo,RouteHint};
-       use ln::msgs::{ChannelFeatures, NodeFeatures, LightningError, ErrorAction};
+       use ln::features::{ChannelFeatures, NodeFeatures};
+       use ln::msgs::{LightningError, ErrorAction};
        use util::test_utils;
        use util::test_utils::TestVecWriter;
        use util::logger::Logger;
@@ -1111,7 +1098,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(1, zero_hash.clone()), NetworkMap::get_key(3, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 100,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1119,7 +1106,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(1, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: our_id.clone(),
                                        last_update: 0,
@@ -1145,7 +1132,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(2, zero_hash.clone()), NetworkMap::get_key(4, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1153,7 +1140,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(2, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: our_id.clone(),
                                        last_update: 0,
@@ -1179,7 +1166,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(12, zero_hash.clone()), NetworkMap::get_key(13, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1187,7 +1174,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(12, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: our_id.clone(),
                                        last_update: 0,
@@ -1219,7 +1206,7 @@ mod tests {
                                        NetworkMap::get_key(7, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1227,7 +1214,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(3, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node1.clone(),
                                        last_update: 0,
@@ -1250,7 +1237,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(4, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node2.clone(),
                                        last_update: 0,
@@ -1273,7 +1260,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(13, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node8.clone(),
                                        last_update: 0,
@@ -1299,7 +1286,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(5, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1307,7 +1294,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(5, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node3.clone(),
                                        last_update: 0,
@@ -1333,7 +1320,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(6, zero_hash.clone()), NetworkMap::get_key(11, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1341,7 +1328,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(6, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node3.clone(),
                                        last_update: 0,
@@ -1364,7 +1351,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(11, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node5.clone(),
                                        last_update: 0,
@@ -1390,7 +1377,7 @@ mod tests {
                                channels: vec!(NetworkMap::get_key(7, zero_hash.clone())),
                                lowest_inbound_channel_fee_base_msat: 0,
                                lowest_inbound_channel_fee_proportional_millionths: 0,
-                               features: NodeFeatures::new(),
+                               features: NodeFeatures::empty(),
                                last_update: 1,
                                rgb: [0; 3],
                                alias: [0; 32],
@@ -1398,7 +1385,7 @@ mod tests {
                                announcement_message: None,
                        });
                        network.channels.insert(NetworkMap::get_key(7, zero_hash.clone()), ChannelInfo {
-                               features: ChannelFeatures::new(),
+                               features: ChannelFeatures::empty(),
                                one_to_two: DirectionalChannelInfo {
                                        src_node_id: node3.clone(),
                                        last_update: 0,