Skip to content

Commit 5f8c54a

Browse files
committed
Don't prune pending_requests in persist
Previously, we would also prune any pending `GetInfo` or expired `Buy` requests before we `persist`. This could have lead to races where we drop a pending request and even remove the peer when calling `persist`. Here, we simply split the pruning logic for the `pending_requests` and expired JIT channel state, and only prune the latter before persisting. This generally makes sense, as `pending_requests` isn't currently persisted, so there is no need to prune before repersisting. Both are however still pruned on peer disconnection.
1 parent 7177cfc commit 5f8c54a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lightning-liquidity/src/lsps2/service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl PeerState {
619619
self.needs_persist |= true;
620620
}
621621

622-
fn prune_expired_request_state(&mut self) {
622+
fn prune_pending_requests(&mut self) {
623623
self.pending_requests.retain(|_, entry| {
624624
match entry {
625625
LSPS2Request::GetInfo(_) => false,
@@ -629,7 +629,9 @@ impl PeerState {
629629
},
630630
}
631631
});
632+
}
632633

634+
fn prune_expired_request_state(&mut self) {
633635
self.outbound_channels_by_intercept_scid.retain(|intercept_scid, entry| {
634636
if entry.is_prunable() {
635637
// We abort the flow, and prune any data kept.
@@ -1875,6 +1877,7 @@ where
18751877
let mut peer_state_lock = inner_state_lock.lock().unwrap();
18761878
// We clean up the peer state, but leave removing the peer entry to the prune logic in
18771879
// `persist` which removes it from the store.
1880+
peer_state_lock.prune_pending_requests();
18781881
peer_state_lock.prune_expired_request_state();
18791882
}
18801883
}

0 commit comments

Comments
 (0)