derive(Clone) for several pub simple data structs.
[rust-lightning] / lightning / src / routing / router.rs
index 23232a0d0fb85d05423b61f09788dfef0e9dc0e5..64a08e732ecbd6e032a154eacb46133fadc882a9 100644 (file)
@@ -113,6 +113,7 @@ impl Readable for Route {
 }
 
 /// A channel descriptor which provides a last-hop route to get_route
+#[derive(Clone)]
 pub struct RouteHint {
        /// The node_id of the non-target end of the route
        pub src_node_id: PublicKey,
@@ -410,7 +411,6 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, targ
 
 #[cfg(test)]
 mod tests {
-       use chain::chaininterface;
        use routing::router::{get_route, RouteHint, RoutingFees};
        use routing::network_graph::NetGraphMsgHandler;
        use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
@@ -424,7 +424,6 @@ mod tests {
        use bitcoin::hashes::Hash;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::genesis_block;
-       use bitcoin::util::hash::BitcoinHash;
 
        use hex;
 
@@ -434,14 +433,14 @@ mod tests {
        use std::sync::Arc;
 
        // Using the same keys for LN and BTC ids
-       fn add_channel(net_graph_msg_handler: &NetGraphMsgHandler<Arc<chaininterface::ChainWatchInterfaceUtil>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey,
+       fn add_channel(net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey,
           node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64) {
                let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
                let node_id_2 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
 
                let unsigned_announcement = UnsignedChannelAnnouncement {
                        features,
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id,
                        node_id_1,
                        node_id_2,
@@ -464,7 +463,7 @@ mod tests {
                };
        }
 
-       fn update_channel(net_graph_msg_handler: &NetGraphMsgHandler<Arc<chaininterface::ChainWatchInterfaceUtil>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate) {
+       fn update_channel(net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate) {
                let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]);
                let valid_channel_update = ChannelUpdate {
                        signature: secp_ctx.sign(&msghash, node_privkey),
@@ -479,7 +478,7 @@ mod tests {
        }
 
 
-       fn add_or_update_node(net_graph_msg_handler: &NetGraphMsgHandler<Arc<chaininterface::ChainWatchInterfaceUtil>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey,
+       fn add_or_update_node(net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>, secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey,
           features: NodeFeatures, timestamp: u32) {
                let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
                let unsigned_announcement = UnsignedNodeAnnouncement {
@@ -532,11 +531,10 @@ mod tests {
                }
        }
 
-       fn build_graph() -> (Secp256k1<All>, NetGraphMsgHandler<std::sync::Arc<crate::chain::chaininterface::ChainWatchInterfaceUtil>, std::sync::Arc<crate::util::test_utils::TestLogger>>, std::sync::Arc<test_utils::TestLogger>) {
+       fn build_graph() -> (Secp256k1<All>, NetGraphMsgHandler<std::sync::Arc<crate::util::test_utils::TestChainSource>, std::sync::Arc<crate::util::test_utils::TestLogger>>, std::sync::Arc<test_utils::TestLogger>) {
                let secp_ctx = Secp256k1::new();
                let logger = Arc::new(test_utils::TestLogger::new());
-               let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet));
-               let net_graph_msg_handler = NetGraphMsgHandler::new(chain_monitor, Arc::clone(&logger));
+               let net_graph_msg_handler = NetGraphMsgHandler::new(None, Arc::clone(&logger));
                // Build network from our_id to node7:
                //
                //        -1(1)2-  node0  -1(3)2-
@@ -598,7 +596,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 1,
                        timestamp: 1,
                        flags: 1,
@@ -614,7 +612,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
                update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 2,
                        timestamp: 1,
                        flags: 0,
@@ -626,7 +624,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 2,
                        timestamp: 1,
                        flags: 1,
@@ -642,7 +640,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12);
                update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 12,
                        timestamp: 1,
                        flags: 0,
@@ -654,7 +652,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 12,
                        timestamp: 1,
                        flags: 1,
@@ -670,7 +668,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 3,
                        timestamp: 1,
                        flags: 0,
@@ -682,7 +680,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 3,
                        timestamp: 1,
                        flags: 1,
@@ -696,7 +694,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 4,
                        timestamp: 1,
                        flags: 0,
@@ -708,7 +706,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 4,
                        timestamp: 1,
                        flags: 1,
@@ -722,7 +720,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 13,
                        timestamp: 1,
                        flags: 0,
@@ -734,7 +732,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 13,
                        timestamp: 1,
                        flags: 1,
@@ -750,7 +748,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 6,
                        timestamp: 1,
                        flags: 0,
@@ -762,7 +760,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 6,
                        timestamp: 1,
                        flags: 1,
@@ -776,7 +774,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 11,
                        timestamp: 1,
                        flags: 0,
@@ -788,7 +786,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 11,
                        timestamp: 1,
                        flags: 1,
@@ -806,7 +804,7 @@ mod tests {
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7);
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 7,
                        timestamp: 1,
                        flags: 0,
@@ -818,7 +816,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[5], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 7,
                        timestamp: 1,
                        flags: 1,
@@ -866,7 +864,7 @@ mod tests {
 
                // // Disable channels 4 and 12 by flags=2
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -878,7 +876,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
+                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 2, // to disable