Skip to content

Commit 6451a43

Browse files
committed
LSPS2: Clean pending get_info request state on disconnection
We clean up any `get_info` request state when peers disconnect.
1 parent f75f124 commit 6451a43

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lightning-liquidity/src/lsps2/service.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ impl PeerState {
459459
fn insert_outbound_channel(&mut self, intercept_scid: u64, channel: OutboundJITChannel) {
460460
self.outbound_channels_by_intercept_scid.insert(intercept_scid, channel);
461461
}
462+
463+
fn peer_disconnected(&mut self) {
464+
// Clean any pending `get_info` requests.
465+
self.pending_requests.retain(|_, entry| !matches!(entry, LSPS2Request::GetInfo(_)));
466+
}
462467
}
463468

464469
/// The main object allowing to send and receive LSPS2 messages.
@@ -1232,6 +1237,14 @@ where
12321237
"total_pending_requests counter out-of-sync! This should never happen!"
12331238
);
12341239
}
1240+
1241+
pub(crate) fn peer_disconnected(&self, counterparty_node_id: PublicKey) {
1242+
let outer_state_lock = self.per_peer_state.write().unwrap();
1243+
if let Some(inner_state_lock) = outer_state_lock.get(&counterparty_node_id) {
1244+
let mut peer_state_lock = inner_state_lock.lock().unwrap();
1245+
peer_state_lock.peer_disconnected();
1246+
}
1247+
}
12351248
}
12361249

12371250
impl<CM: Deref + Clone> ProtocolMessageHandler for LSPS2ServiceHandler<CM>

lightning-liquidity/src/manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ where
612612
features
613613
}
614614

615-
fn peer_disconnected(&self, _: bitcoin::secp256k1::PublicKey) {}
615+
fn peer_disconnected(&self, counterparty_node_id: bitcoin::secp256k1::PublicKey) {
616+
if let Some(lsps2_service_handler) = self.lsps2_service_handler.as_ref() {
617+
lsps2_service_handler.peer_disconnected(counterparty_node_id);
618+
}
619+
}
616620
fn peer_connected(
617621
&self, _: bitcoin::secp256k1::PublicKey, _: &lightning::ln::msgs::Init, _: bool,
618622
) -> Result<(), ()> {

0 commit comments

Comments
 (0)