]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add ChainWatchInterface in Router
authorAntoine Riard <ariard@student.42.fr>
Thu, 30 Aug 2018 01:37:37 +0000 (01:37 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 3 Sep 2018 21:40:05 +0000 (17:40 -0400)
fuzz/fuzz_targets/full_stack_target.rs
fuzz/fuzz_targets/router_target.rs
src/ln/channelmanager.rs
src/ln/router.rs

index e5c12539ecee3d2e373163da96e1987fb73efbf2..ced754acb514d58acc5fc9c628c8db276088e7f8 100644 (file)
@@ -232,12 +232,12 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
                Err(_) => return,
        };
 
-       let watch = Arc::new(ChainWatchInterfaceUtil::new(Arc::clone(&logger)));
+       let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
        let broadcast = Arc::new(TestBroadcaster{});
        let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
 
        let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger)).unwrap();
-       let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), Arc::clone(&logger)));
+       let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), watch.clone(), Arc::clone(&logger)));
 
        let peers = RefCell::new([false; 256]);
        let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler {
index 469db990ffcbd8e949fc8d722304d75dfb3f4a3b..5d374f9538a8dff00e81f19e674621e5d892ccbd 100644 (file)
@@ -2,6 +2,9 @@ extern crate bitcoin;
 extern crate lightning;
 extern crate secp256k1;
 
+use bitcoin::network::constants::Network;
+
+use lightning::chain::chaininterface;
 use lightning::ln::channelmanager::ChannelDetails;
 use lightning::ln::msgs;
 use lightning::ln::msgs::{MsgDecodable, RoutingMessageHandler};
@@ -107,9 +110,10 @@ pub fn do_test(data: &[u8]) {
        }
 
        let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
+       let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
 
        let our_pubkey = get_pubkey!();
-       let router = Router::new(our_pubkey.clone(), Arc::clone(&logger));
+       let router = Router::new(our_pubkey.clone(), chain_monitor, Arc::clone(&logger));
 
        loop {
                match get_slice!(1)[0] {
index 6a0e55a2c8a601bb778188a7c07befb333d73647..2c28e595e270030bada951faad448734f7c7ae5d 100644 (file)
@@ -2816,7 +2816,7 @@ mod tests {
 
                for _ in 0..node_count {
                        let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 });
-                       let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Arc::clone(&logger)));
+                       let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
                        let tx_broadcaster = Arc::new(test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())});
                        let chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(chain_monitor.clone(), tx_broadcaster.clone()));
                        let node_id = {
@@ -2825,7 +2825,7 @@ mod tests {
                                SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
                        };
                        let node = ChannelManager::new(node_id.clone(), 0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger)).unwrap();
-                       let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), Arc::clone(&logger));
+                       let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), chain_monitor.clone(), Arc::clone(&logger));
                        nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router });
                }
 
index a71eb913ce521c1765087ba27a79b2bf8b2a293e..e329b7e696c4b08aec2889797064f6f2a757725f 100644 (file)
@@ -4,6 +4,7 @@ use secp256k1;
 
 use bitcoin::util::hash::Sha256dHash;
 
+use chain::chaininterface::ChainWatchInterface;
 use ln::channelmanager;
 use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,MsgEncodable,NetAddress,GlobalFeatures};
 use ln::msgs;
@@ -155,6 +156,7 @@ pub struct RouteHint {
 pub struct Router {
        secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
        network_map: RwLock<NetworkMap>,
+       chain_monitor: Arc<ChainWatchInterface>,
        logger: Arc<Logger>,
 }
 
@@ -388,7 +390,7 @@ struct DummyDirectionalChannelInfo {
 }
 
 impl Router {
-       pub fn new(our_pubkey: PublicKey, logger: Arc<Logger>) -> Router {
+       pub fn new(our_pubkey: PublicKey, chain_monitor: Arc<ChainWatchInterface>, logger: Arc<Logger>) -> Router {
                let mut nodes = HashMap::new();
                nodes.insert(our_pubkey.clone(), NodeInfo {
                        channels: Vec::new(),
@@ -407,6 +409,7 @@ impl Router {
                                our_node_id: our_pubkey,
                                nodes: nodes,
                        }),
+                       chain_monitor,
                        logger,
                }
        }
@@ -632,6 +635,7 @@ impl Router {
 
 #[cfg(test)]
 mod tests {
+       use chain::chaininterface;
        use ln::channelmanager;
        use ln::router::{Router,NodeInfo,NetworkMap,ChannelInfo,DirectionalChannelInfo,RouteHint};
        use ln::msgs::GlobalFeatures;
@@ -652,7 +656,8 @@ mod tests {
                let secp_ctx = Secp256k1::new();
                let our_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap());
                let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
-               let router = Router::new(our_id, Arc::clone(&logger));
+               let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
+               let router = Router::new(our_id, chain_monitor, Arc::clone(&logger));
 
                // Build network from our_id to node8:
                //