Skip to content

Commit

Permalink
LSPS2: Also prune expired OutboundJITChannels pending initial payments
Browse files Browse the repository at this point in the history
We're now also pruning any expired `OutboundJITChannels` if we haven't
seen any related HTLCs.
  • Loading branch information
tnull committed Dec 10, 2024
1 parent 4d20463 commit 3a318f8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lightning-liquidity/src/lsps2/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ impl OutboundJITChannel {
self.state = new_state;
Ok(action)
}

fn is_prunable(&self) -> bool {
// We deem an OutboundJITChannel prunable if our offer expired and we haven't intercepted
// any HTLCs initiating the flow yet.
let is_pending_initial_payment = match self.state {
OutboundJITChannelState::PendingInitialPayment { .. } => true,
_ => false,
};

let is_expired = is_expired_opening_fee_params(&self.opening_fee_params);
is_pending_initial_payment && is_expired
}
}

struct PeerState {
Expand Down Expand Up @@ -488,6 +500,16 @@ impl PeerState {
},
}
});

self.outbound_channels_by_intercept_scid.retain(|intercept_scid, entry| {
if entry.is_prunable() {
// We abort the flow, and prune any data kept.
self.intercept_scid_by_channel_id.retain(|_, iscid| intercept_scid != iscid);
self.intercept_scid_by_user_channel_id.retain(|_, iscid| intercept_scid != iscid);
return false;
}
true
});
}
}

Expand Down

0 comments on commit 3a318f8

Please sign in to comment.