Skip to content

Commit aa07bf4

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 f31f718 commit aa07bf4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lightning-liquidity/src/lsps2/service.rs

+13
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ impl PeerState {
475475
fn insert_outbound_channel(&mut self, intercept_scid: u64, channel: OutboundJITChannel) {
476476
self.outbound_channels_by_intercept_scid.insert(intercept_scid, channel);
477477
}
478+
479+
fn peer_disconnected(&mut self) {
480+
// Clean any pending `get_info` requests.
481+
self.pending_requests.retain(|_, entry| !matches!(entry, LSPS2Request::GetInfo(_)));
482+
}
478483
}
479484

480485
/// The main object allowing to send and receive LSPS2 messages.
@@ -1185,6 +1190,14 @@ where
11851190

11861191
result
11871192
}
1193+
1194+
pub(crate) fn peer_disconnected(&self, counterparty_node_id: PublicKey) {
1195+
let outer_state_lock = self.per_peer_state.write().unwrap();
1196+
if let Some(inner_state_lock) = outer_state_lock.get(&counterparty_node_id) {
1197+
let mut peer_state_lock = inner_state_lock.lock().unwrap();
1198+
peer_state_lock.peer_disconnected();
1199+
}
1200+
}
11881201
}
11891202

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

lightning-liquidity/src/manager.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,11 @@ where
603603
features
604604
}
605605

606-
fn peer_disconnected(&self, _: bitcoin::secp256k1::PublicKey) {}
606+
fn peer_disconnected(&self, counterparty_node_id: bitcoin::secp256k1::PublicKey) {
607+
if let Some(lsps2_service_handler) = self.lsps2_service_handler.as_ref() {
608+
lsps2_service_handler.peer_disconnected(counterparty_node_id);
609+
}
610+
}
607611
fn peer_connected(
608612
&self, _: bitcoin::secp256k1::PublicKey, _: &lightning::ln::msgs::Init, _: bool,
609613
) -> Result<(), ()> {

0 commit comments

Comments
 (0)