Merge pull request #1116 from TheBlueMatt/2021-10-test-local-chan-routing
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 12 Oct 2021 18:29:05 +0000 (18:29 +0000)
committerGitHub <noreply@github.com>
Tue, 12 Oct 2021 18:29:05 +0000 (18:29 +0000)
Use local channel state when constructing routes in test macro  + Fix compile-warning

lightning/src/ln/functional_test_utils.rs
lightning/src/util/events.rs

index 00a680dfe83474d9493b943e8b16ba9100e20ffe..0d01961cd1b3f023f7bec7c3a6559b330d4bf34d 100644 (file)
@@ -973,8 +973,9 @@ macro_rules! commitment_signed_dance {
 macro_rules! get_payment_preimage_hash {
        ($dest_node: expr) => {
                {
-                       let payment_preimage = PaymentPreimage([*$dest_node.network_payment_count.borrow(); 32]);
-                       *$dest_node.network_payment_count.borrow_mut() += 1;
+                       let mut payment_count = $dest_node.network_payment_count.borrow_mut();
+                       let payment_preimage = PaymentPreimage([*payment_count; 32]);
+                       *payment_count += 1;
                        let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
                        let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, None, 7200, 0).unwrap();
                        (payment_preimage, payment_hash, payment_secret)
@@ -989,7 +990,9 @@ macro_rules! get_route_and_payment_hash {
                let net_graph_msg_handler = &$send_node.net_graph_msg_handler;
                let route = get_route(&$send_node.node.get_our_node_id(),
                        &net_graph_msg_handler.network_graph,
-                       &$recv_node.node.get_our_node_id(), None, None, &Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
+                       &$recv_node.node.get_our_node_id(), None,
+                       Some(&$send_node.node.list_usable_channels().iter().map(|a| a).collect::<Vec<_>>()),
+                       &Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
                (route, payment_hash, payment_preimage, payment_secret)
        }}
 }
index 37c64364b1817bf89e4477ce650a70f52ba0b938..08fc164f4baf10f8a2240a64e09d6bd77b8fa165 100644 (file)
@@ -480,23 +480,29 @@ impl MaybeReadable for Event {
                                f()
                        },
                        9u8 => {
-                               let mut channel_id = [0; 32];
-                               let mut reason = None;
-                               read_tlv_fields!(reader, {
-                                       (0, channel_id, required),
-                                       (2, reason, ignorable),
-                               });
-                               if reason.is_none() { return Ok(None); }
-                               Ok(Some(Event::ChannelClosed { channel_id, reason: reason.unwrap() }))
+                               let f = || {
+                                       let mut channel_id = [0; 32];
+                                       let mut reason = None;
+                                       read_tlv_fields!(reader, {
+                                               (0, channel_id, required),
+                                               (2, reason, ignorable),
+                                       });
+                                       if reason.is_none() { return Ok(None); }
+                                       Ok(Some(Event::ChannelClosed { channel_id, reason: reason.unwrap() }))
+                               };
+                               f()
                        },
                        11u8 => {
-                               let mut channel_id = [0; 32];
-                               let mut transaction = Transaction{ version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
-                               read_tlv_fields!(reader, {
-                                       (0, channel_id, required),
-                                       (2, transaction, required),
-                               });
-                               Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
+                               let f = || {
+                                       let mut channel_id = [0; 32];
+                                       let mut transaction = Transaction{ version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
+                                       read_tlv_fields!(reader, {
+                                               (0, channel_id, required),
+                                               (2, transaction, required),
+                                       });
+                                       Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
+                               };
+                               f()
                        },
                        // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
                        // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt