Skip to content

Commit 47a3e5c

Browse files
committed
Debug-Assert that there are no queued messages when a peer connects
In the previous two commits we stopped enqueueing messages for disconnected peers. Here we add some basic test coverage of these changes by asserting that there are no queued messages for a peer when they (re-)connect. We also add a few assertions that a peer is connected when we push a message onto the queu, in cases where we expect a peer to be connected.
1 parent a06ebee commit 47a3e5c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9559,6 +9559,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95599559
msg: msgs::ErrorMessage { channel_id: *temporary_channel_id, data: "No zero confirmation channels accepted".to_owned(), }
95609560
}
95619561
};
9562+
debug_assert!(peer_state.is_connected);
95629563
peer_state.pending_msg_events.push(send_msg_err_event);
95639564
let err_str = "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned();
95649565
log_error!(logger, "{}", err_str);
@@ -9575,6 +9576,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95759576
msg: msgs::ErrorMessage { channel_id: *temporary_channel_id, data: "Have too many peers with unfunded channels, not accepting new ones".to_owned(), }
95769577
}
95779578
};
9579+
debug_assert!(peer_state.is_connected);
95789580
peer_state.pending_msg_events.push(send_msg_err_event);
95799581
let err_str = "Too many peers with unfunded channels, refusing to accept new ones".to_owned();
95809582
log_error!(logger, "{}", err_str);
@@ -9588,6 +9590,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95889590
channel.context_mut().set_outbound_scid_alias(outbound_scid_alias);
95899591

95909592
if let Some(message_send_event) = message_send_event {
9593+
debug_assert!(peer_state.is_connected);
95919594
peer_state.pending_msg_events.push(message_send_event);
95929595
}
95939596
peer_state.channel_by_id.insert(channel_id, channel);
@@ -13339,7 +13342,7 @@ where
1333913342

1334013343
{
1334113344
let mut peer_state_lock = self.per_peer_state.write().unwrap();
13342-
match peer_state_lock.entry(counterparty_node_id.clone()) {
13345+
match peer_state_lock.entry(counterparty_node_id) {
1334313346
hash_map::Entry::Vacant(e) => {
1334413347
if inbound_peer_limited {
1334513348
res = Err(());
@@ -13371,6 +13374,9 @@ where
1337113374
return NotifyOption::SkipPersistNoEvents;
1337213375
}
1337313376

13377+
debug_assert!(peer_state.pending_msg_events.is_empty());
13378+
peer_state.pending_msg_events.clear();
13379+
1337413380
debug_assert!(!peer_state.is_connected, "A peer shouldn't be connected twice");
1337513381
peer_state.is_connected = true;
1337613382
},

0 commit comments

Comments
 (0)