LSPS2: Clean pending get_info request state on disconnection

We clean up any `get_info` request state when peers disconnect.
This commit is contained in:
Elias Rohrer 2024-12-09 13:50:33 +01:00
parent f75f124e02
commit 6451a432cc
No known key found for this signature in database
GPG key ID: 36153082BDF676FD
2 changed files with 18 additions and 1 deletions

View file

@ -459,6 +459,11 @@ impl PeerState {
fn insert_outbound_channel(&mut self, intercept_scid: u64, channel: OutboundJITChannel) {
self.outbound_channels_by_intercept_scid.insert(intercept_scid, channel);
}
fn peer_disconnected(&mut self) {
// Clean any pending `get_info` requests.
self.pending_requests.retain(|_, entry| !matches!(entry, LSPS2Request::GetInfo(_)));
}
}
/// The main object allowing to send and receive LSPS2 messages.
@ -1232,6 +1237,14 @@ where
"total_pending_requests counter out-of-sync! This should never happen!"
);
}
pub(crate) fn peer_disconnected(&self, counterparty_node_id: PublicKey) {
let outer_state_lock = self.per_peer_state.write().unwrap();
if let Some(inner_state_lock) = outer_state_lock.get(&counterparty_node_id) {
let mut peer_state_lock = inner_state_lock.lock().unwrap();
peer_state_lock.peer_disconnected();
}
}
}
impl<CM: Deref + Clone> ProtocolMessageHandler for LSPS2ServiceHandler<CM>

View file

@ -612,7 +612,11 @@ where
features
}
fn peer_disconnected(&self, _: bitcoin::secp256k1::PublicKey) {}
fn peer_disconnected(&self, counterparty_node_id: bitcoin::secp256k1::PublicKey) {
if let Some(lsps2_service_handler) = self.lsps2_service_handler.as_ref() {
lsps2_service_handler.peer_disconnected(counterparty_node_id);
}
}
fn peer_connected(
&self, _: bitcoin::secp256k1::PublicKey, _: &lightning::ln::msgs::Init, _: bool,
) -> Result<(), ()> {