Skip to content

Commit 5a356ca

Browse files
authored
Merge pull request #1116 from TheBlueMatt/2021-10-test-local-chan-routing
Use local channel state when constructing routes in test macro + Fix compile-warning
2 parents d665748 + 00ffa43 commit 5a356ca

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

lightning/src/ln/functional_test_utils.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,9 @@ macro_rules! commitment_signed_dance {
973973
macro_rules! get_payment_preimage_hash {
974974
($dest_node: expr) => {
975975
{
976-
let payment_preimage = PaymentPreimage([*$dest_node.network_payment_count.borrow(); 32]);
977-
*$dest_node.network_payment_count.borrow_mut() += 1;
976+
let mut payment_count = $dest_node.network_payment_count.borrow_mut();
977+
let payment_preimage = PaymentPreimage([*payment_count; 32]);
978+
*payment_count += 1;
978979
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
979980
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, None, 7200, 0).unwrap();
980981
(payment_preimage, payment_hash, payment_secret)
@@ -989,7 +990,9 @@ macro_rules! get_route_and_payment_hash {
989990
let net_graph_msg_handler = &$send_node.net_graph_msg_handler;
990991
let route = get_route(&$send_node.node.get_our_node_id(),
991992
&net_graph_msg_handler.network_graph,
992-
&$recv_node.node.get_our_node_id(), None, None, &Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
993+
&$recv_node.node.get_our_node_id(), None,
994+
Some(&$send_node.node.list_usable_channels().iter().map(|a| a).collect::<Vec<_>>()),
995+
&Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
993996
(route, payment_hash, payment_preimage, payment_secret)
994997
}}
995998
}

lightning/src/util/events.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -480,23 +480,29 @@ impl MaybeReadable for Event {
480480
f()
481481
},
482482
9u8 => {
483-
let mut channel_id = [0; 32];
484-
let mut reason = None;
485-
read_tlv_fields!(reader, {
486-
(0, channel_id, required),
487-
(2, reason, ignorable),
488-
});
489-
if reason.is_none() { return Ok(None); }
490-
Ok(Some(Event::ChannelClosed { channel_id, reason: reason.unwrap() }))
483+
let f = || {
484+
let mut channel_id = [0; 32];
485+
let mut reason = None;
486+
read_tlv_fields!(reader, {
487+
(0, channel_id, required),
488+
(2, reason, ignorable),
489+
});
490+
if reason.is_none() { return Ok(None); }
491+
Ok(Some(Event::ChannelClosed { channel_id, reason: reason.unwrap() }))
492+
};
493+
f()
491494
},
492495
11u8 => {
493-
let mut channel_id = [0; 32];
494-
let mut transaction = Transaction{ version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
495-
read_tlv_fields!(reader, {
496-
(0, channel_id, required),
497-
(2, transaction, required),
498-
});
499-
Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
496+
let f = || {
497+
let mut channel_id = [0; 32];
498+
let mut transaction = Transaction{ version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
499+
read_tlv_fields!(reader, {
500+
(0, channel_id, required),
501+
(2, transaction, required),
502+
});
503+
Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
504+
};
505+
f()
500506
},
501507
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
502508
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt

0 commit comments

Comments
 (0)