Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 0384ccd

Browse files
committed
Track peers and intercept scids by channel id
1 parent 8e4ec14 commit 0384ccd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lsps2/service.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ impl OutboundJITChannel {
257257
struct PeerState {
258258
outbound_channels_by_intercept_scid: HashMap<u64, OutboundJITChannel>,
259259
intercept_scid_by_user_channel_id: HashMap<u128, u64>,
260+
intercept_scid_by_channel_id: HashMap<ChannelId, u64>,
260261
pending_requests: HashMap<RequestId, LSPS2Request>,
261262
}
262263

@@ -265,10 +266,12 @@ impl PeerState {
265266
let outbound_channels_by_intercept_scid = HashMap::new();
266267
let pending_requests = HashMap::new();
267268
let intercept_scid_by_user_channel_id = HashMap::new();
269+
let intercept_scid_by_channel_id = HashMap::new();
268270
Self {
269271
outbound_channels_by_intercept_scid,
270272
pending_requests,
271273
intercept_scid_by_user_channel_id,
274+
intercept_scid_by_channel_id,
272275
}
273276
}
274277

@@ -287,6 +290,7 @@ where
287290
pending_events: Arc<EventQueue>,
288291
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
289292
peer_by_intercept_scid: RwLock<HashMap<u64, PublicKey>>,
293+
peer_by_channel_id: RwLock<HashMap<ChannelId, PublicKey>>,
290294
config: LSPS2ServiceConfig,
291295
}
292296

@@ -304,6 +308,7 @@ where
304308
pending_events,
305309
per_peer_state: RwLock::new(HashMap::new()),
306310
peer_by_intercept_scid: RwLock::new(HashMap::new()),
311+
peer_by_channel_id: RwLock::new(HashMap::new()),
307312
channel_manager,
308313
config,
309314
}
@@ -523,13 +528,18 @@ where
523528
pub fn channel_ready(
524529
&self, user_channel_id: u128, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
525530
) -> Result<(), APIError> {
531+
{
532+
let mut peer_by_channel_id = self.peer_by_channel_id.write().unwrap();
533+
peer_by_channel_id.insert(*channel_id, *counterparty_node_id);
534+
}
526535
let outer_state_lock = self.per_peer_state.read().unwrap();
527536
match outer_state_lock.get(counterparty_node_id) {
528537
Some(inner_state_lock) => {
529538
let mut peer_state = inner_state_lock.lock().unwrap();
530539
if let Some(intercept_scid) =
531540
peer_state.intercept_scid_by_user_channel_id.get(&user_channel_id).copied()
532541
{
542+
peer_state.intercept_scid_by_channel_id.insert(*channel_id, intercept_scid);
533543
if let Some(jit_channel) =
534544
peer_state.outbound_channels_by_intercept_scid.get_mut(&intercept_scid)
535545
{

0 commit comments

Comments
 (0)