fn drop(&mut self) {
if !panicking() {
// Check that we processed all pending events
- assert!(self.node.get_and_clear_pending_msg_events().is_empty());
- assert!(self.node.get_and_clear_pending_events().is_empty());
- assert!(self.chain_monitor.added_monitors.lock().unwrap().is_empty());
+ let msg_events = self.node.get_and_clear_pending_msg_events();
+ if !msg_events.is_empty() {
+ panic!("Had excess message events on node {}: {:?}", self.logger.id, msg_events);
+ }
+ let events = self.node.get_and_clear_pending_events();
+ if !events.is_empty() {
+ panic!("Had excess events on node {}: {:?}", self.logger.id, events);
+ }
+ let added_monitors = self.chain_monitor.added_monitors.lock().unwrap().split_off(0);
+ if !added_monitors.is_empty() {
+ panic!("Had {} excess added monitors on node {}", added_monitors.len(), self.logger.id);
+ }
// Check that if we serialize the Router, we can deserialize it again.
{
}
pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate) {
- nodes[a].node.broadcast_node_announcement([0, 0, 0], [0; 32], Vec::new());
- let a_events = nodes[a].node.get_and_clear_pending_msg_events();
- assert!(a_events.len() >= 2);
-
- // ann should be re-generated by broadcast_node_announcement - check that we have it.
- let mut found_ann_1 = false;
- for event in a_events.iter() {
- match event {
- MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
- if msg == ann { found_ann_1 = true; }
- },
- MessageSendEvent::BroadcastNodeAnnouncement { .. } => {},
- _ => panic!("Unexpected event {:?}", event),
- }
- }
- assert!(found_ann_1);
-
- let a_node_announcement = match a_events.last().unwrap() {
- MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
- (*msg).clone()
- },
- _ => panic!("Unexpected event"),
- };
-
- nodes[b].node.broadcast_node_announcement([1, 1, 1], [1; 32], Vec::new());
- let b_events = nodes[b].node.get_and_clear_pending_msg_events();
- assert!(b_events.len() >= 2);
-
- // ann should be re-generated by broadcast_node_announcement - check that we have it.
- let mut found_ann_2 = false;
- for event in b_events.iter() {
- match event {
- MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
- if msg == ann { found_ann_2 = true; }
- },
- MessageSendEvent::BroadcastNodeAnnouncement { .. } => {},
- _ => panic!("Unexpected event"),
- }
- }
- assert!(found_ann_2);
-
- let b_node_announcement = match b_events.last().unwrap() {
- MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
- (*msg).clone()
- },
- _ => panic!("Unexpected event"),
- };
-
for node in nodes {
assert!(node.gossip_sync.handle_channel_announcement(ann).unwrap());
node.gossip_sync.handle_channel_update(upd_1).unwrap();
node.gossip_sync.handle_channel_update(upd_2).unwrap();
- node.gossip_sync.handle_node_announcement(&a_node_announcement).unwrap();
- node.gossip_sync.handle_node_announcement(&b_node_announcement).unwrap();
// Note that channel_updates are also delivered to ChannelManagers to ensure we have
// forwarding info for local channels even if its not accepted in the network graph.
#[cfg(test)]
macro_rules! expect_payment_failed_with_update {
- ($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
+ ($node: expr, $expected_payment_hash: expr, $payment_failed_permanently: expr, $scid: expr, $chan_closed: expr) => {
$crate::ln::functional_test_utils::expect_payment_failed_conditions(
- &$node, $expected_payment_hash, $rejected_by_dest,
+ &$node, $expected_payment_hash, $payment_failed_permanently,
$crate::ln::functional_test_utils::PaymentFailedConditions::new()
.blamed_scid($scid).blamed_chan_closed($chan_closed));
}
#[cfg(test)]
macro_rules! expect_payment_failed {
- ($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
+ ($node: expr, $expected_payment_hash: expr, $payment_failed_permanently: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
#[allow(unused_mut)]
let mut conditions = $crate::ln::functional_test_utils::PaymentFailedConditions::new();
$(
conditions = conditions.expected_htlc_error_data($expected_error_code, &$expected_error_data);
)*
- $crate::ln::functional_test_utils::expect_payment_failed_conditions(&$node, $expected_payment_hash, $rejected_by_dest, conditions);
+ $crate::ln::functional_test_utils::expect_payment_failed_conditions(&$node, $expected_payment_hash, $payment_failed_permanently, conditions);
};
}
pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
node: &'a Node<'b, 'c, 'd>, payment_failed_event: Event, expected_payment_hash: PaymentHash,
- expected_rejected_by_dest: bool, conditions: PaymentFailedConditions<'e>
+ expected_payment_failed_permanently: bool, conditions: PaymentFailedConditions<'e>
) {
let expected_payment_id = match payment_failed_event {
- Event::PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update, short_channel_id,
+ Event::PaymentPathFailed { payment_hash, payment_failed_permanently, path, retry, payment_id, network_update, short_channel_id,
#[cfg(test)]
error_code,
#[cfg(test)]
error_data, .. } => {
assert_eq!(payment_hash, expected_payment_hash, "unexpected payment_hash");
- assert_eq!(rejected_by_dest, expected_rejected_by_dest, "unexpected rejected_by_dest value");
+ assert_eq!(payment_failed_permanently, expected_payment_failed_permanently, "unexpected payment_failed_permanently value");
assert!(retry.is_some(), "expected retry.is_some()");
assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
}
pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
- node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
+ node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_payment_failed_permanently: bool,
conditions: PaymentFailedConditions<'e>
) {
let mut events = node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
- expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_rejected_by_dest, conditions);
+ expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_payment_failed_permanently, conditions);
}
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
let events = origin_node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
let expected_payment_id = match events[0] {
- Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, ref path, ref payment_id, .. } => {
+ Event::PaymentPathFailed { payment_hash, payment_failed_permanently, all_paths_failed, ref path, ref payment_id, .. } => {
assert_eq!(payment_hash, our_payment_hash);
- assert!(rejected_by_dest);
+ assert!(payment_failed_permanently);
assert_eq!(all_paths_failed, i == expected_paths.len() - 1);
for (idx, hop) in expected_route.iter().enumerate() {
assert_eq!(hop.node.get_our_node_id(), path[idx].pubkey);
macro_rules! get_chan_reestablish_msgs {
($src_node: expr, $dst_node: expr) => {
{
+ let mut announcements = $crate::prelude::HashSet::new();
let mut res = Vec::with_capacity(1);
for msg in $src_node.node.get_and_clear_pending_msg_events() {
if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
assert_eq!(*node_id, $dst_node.node.get_our_node_id());
res.push(msg.clone());
+ } else if let MessageSendEvent::SendChannelAnnouncement { ref node_id, ref msg, .. } = msg {
+ assert_eq!(*node_id, $dst_node.node.get_our_node_id());
+ announcements.insert(msg.contents.short_channel_id);
} else {
panic!("Unexpected event")
}
}
+ for chan in $src_node.node.list_channels() {
+ if chan.is_public && chan.counterparty.node_id != $dst_node.node.get_our_node_id() {
+ if let Some(scid) = chan.short_channel_id {
+ assert!(announcements.remove(&scid));
+ }
+ }
+ }
+ assert!(announcements.is_empty());
res
}
}