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

Commit 718dd2b

Browse files
committed
f Revert unnecessary renames to jit_channel
1 parent 68158e7 commit 718dd2b

File tree

3 files changed

+86
-66
lines changed

3 files changed

+86
-66
lines changed

src/lsps2/channel_manager.rs

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ impl InboundJITChannel {
185185
}
186186

187187
pub fn invoice_params_received(
188-
&mut self, client_trusts_lsp: bool, lsps2_scid: JitChannelScid,
188+
&mut self, client_trusts_lsp: bool, jit_channel_scid: JitChannelScid,
189189
) -> Result<(), LightningError> {
190-
self.state = self.state.invoice_params_received(client_trusts_lsp, lsps2_scid)?;
190+
self.state = self.state.invoice_params_received(client_trusts_lsp, jit_channel_scid)?;
191191
Ok(())
192192
}
193193
}
@@ -370,20 +370,20 @@ struct PeerState {
370370
}
371371

372372
impl PeerState {
373-
pub fn insert_inbound_channel(&mut self, lsps2_id: u128, channel: InboundJITChannel) {
374-
self.inbound_channels_by_id.insert(lsps2_id, channel);
373+
pub fn insert_inbound_channel(&mut self, jit_channel_id: u128, channel: InboundJITChannel) {
374+
self.inbound_channels_by_id.insert(jit_channel_id, channel);
375375
}
376376

377377
pub fn insert_outbound_channel(&mut self, scid: u64, channel: OutboundJITChannel) {
378378
self.outbound_channels_by_scid.insert(scid, channel);
379379
}
380380

381-
pub fn insert_request(&mut self, request_id: RequestId, lsps2_id: u128) {
382-
self.request_to_cid.insert(request_id, lsps2_id);
381+
pub fn insert_request(&mut self, request_id: RequestId, jit_channel_id: u128) {
382+
self.request_to_cid.insert(request_id, jit_channel_id);
383383
}
384384

385-
pub fn remove_inbound_channel(&mut self, lsps2_id: u128) {
386-
self.inbound_channels_by_id.remove(&lsps2_id);
385+
pub fn remove_inbound_channel(&mut self, jit_channel_id: u128) {
386+
self.inbound_channels_by_id.remove(&jit_channel_id);
387387
}
388388

389389
pub fn remove_outbound_channel(&mut self, scid: u64) {
@@ -490,18 +490,19 @@ where
490490
&self, counterparty_node_id: PublicKey, payment_size_msat: Option<u64>,
491491
token: Option<String>, user_channel_id: u128,
492492
) {
493-
let lsps2_id = self.generate_lsps2_id();
494-
let channel = InboundJITChannel::new(lsps2_id, user_channel_id, payment_size_msat, token);
493+
let jit_channel_id = self.generate_jit_channel_id();
494+
let channel =
495+
InboundJITChannel::new(jit_channel_id, user_channel_id, payment_size_msat, token);
495496

496497
let mut outer_state_lock = self.per_peer_state.write().unwrap();
497498
let inner_state_lock = outer_state_lock
498499
.entry(counterparty_node_id)
499500
.or_insert(Mutex::new(PeerState::default()));
500501
let peer_state = inner_state_lock.get_mut().unwrap();
501-
peer_state.insert_inbound_channel(lsps2_id, channel);
502+
peer_state.insert_inbound_channel(jit_channel_id, channel);
502503

503504
let request_id = self.generate_request_id();
504-
peer_state.insert_request(request_id.clone(), lsps2_id);
505+
peer_state.insert_request(request_id.clone(), jit_channel_id);
505506

506507
{
507508
let mut pending_messages = self.pending_messages.lock().unwrap();
@@ -588,25 +589,27 @@ where
588589
}
589590

590591
pub fn opening_fee_params_selected(
591-
&self, counterparty_node_id: PublicKey, lsps2_id: u128,
592+
&self, counterparty_node_id: PublicKey, jit_channel_id: u128,
592593
opening_fee_params: OpeningFeeParams,
593594
) -> Result<(), APIError> {
594595
let outer_state_lock = self.per_peer_state.read().unwrap();
595596
match outer_state_lock.get(&counterparty_node_id) {
596597
Some(inner_state_lock) => {
597598
let mut peer_state = inner_state_lock.lock().unwrap();
598-
if let Some(lsps2) = peer_state.inbound_channels_by_id.get_mut(&lsps2_id) {
599-
let version = match lsps2.opening_fee_params_selected() {
599+
if let Some(jit_channel) =
600+
peer_state.inbound_channels_by_id.get_mut(&jit_channel_id)
601+
{
602+
let version = match jit_channel.opening_fee_params_selected() {
600603
Ok(version) => version,
601604
Err(e) => {
602-
peer_state.remove_inbound_channel(lsps2_id);
605+
peer_state.remove_inbound_channel(jit_channel_id);
603606
return Err(APIError::APIMisuseError { err: e.err });
604607
}
605608
};
606609

607610
let request_id = self.generate_request_id();
608-
let payment_size_msat = lsps2.config.payment_size_msat;
609-
peer_state.insert_request(request_id.clone(), lsps2_id);
611+
let payment_size_msat = jit_channel.config.payment_size_msat;
612+
peer_state.insert_request(request_id.clone(), jit_channel_id);
610613

611614
{
612615
let mut pending_messages = self.pending_messages.lock().unwrap();
@@ -628,7 +631,7 @@ where
628631
}
629632
} else {
630633
return Err(APIError::APIMisuseError {
631-
err: format!("Channel with id {} not found", lsps2_id),
634+
err: format!("Channel with id {} not found", jit_channel_id),
632635
});
633636
}
634637
}
@@ -659,21 +662,21 @@ where
659662
peer_by_scid.insert(scid, counterparty_node_id);
660663
}
661664

662-
let outbound_lsps2 = OutboundJITChannel::new(
665+
let outbound_jit_channel = OutboundJITChannel::new(
663666
scid,
664667
cltv_expiry_delta,
665668
client_trusts_lsp,
666669
buy_request.payment_size_msat,
667670
buy_request.opening_fee_params,
668671
);
669672

670-
peer_state.insert_outbound_channel(scid, outbound_lsps2);
673+
peer_state.insert_outbound_channel(scid, outbound_jit_channel);
671674

672675
self.enqueue_response(
673676
counterparty_node_id,
674677
request_id,
675678
LSPS2Response::Buy(BuyResponse {
676-
lsps2_scid: scid.into(),
679+
jit_channel_scid: scid.into(),
677680
lsp_cltv_expiry_delta: cltv_expiry_delta,
678681
client_trusts_lsp,
679682
}),
@@ -701,9 +704,9 @@ where
701704
match outer_state_lock.get(counterparty_node_id) {
702705
Some(inner_state_lock) => {
703706
let mut peer_state = inner_state_lock.lock().unwrap();
704-
if let Some(lsps2) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
707+
if let Some(jit_channel) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
705708
let htlc = InterceptedHTLC { intercept_id, expected_outbound_amount_msat };
706-
match lsps2.htlc_intercepted(htlc) {
709+
match jit_channel.htlc_intercepted(htlc) {
707710
Ok(Some((opening_fee_msat, amt_to_forward_msat))) => {
708711
self.enqueue_event(Event::LSPS2(LSPS2Event::OpenChannel {
709712
their_network_key: counterparty_node_id.clone(),
@@ -742,8 +745,8 @@ where
742745
match outer_state_lock.get(counterparty_node_id) {
743746
Some(inner_state_lock) => {
744747
let mut peer_state = inner_state_lock.lock().unwrap();
745-
if let Some(lsps2) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
746-
match lsps2.channel_ready() {
748+
if let Some(jit_channel) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
749+
match jit_channel.channel_ready() {
747750
Ok((htlcs, total_amt_to_forward_msat)) => {
748751
let amounts_to_forward_msat = calculate_amount_to_forward_per_htlc(
749752
&htlcs,
@@ -790,7 +793,7 @@ where
790793
Ok(())
791794
}
792795

793-
fn generate_lsps2_id(&self) -> u128 {
796+
fn generate_jit_channel_id(&self) -> u128 {
794797
let bytes = self.entropy_source.get_secure_random_bytes();
795798
let mut id_bytes: [u8; 16] = [0; 16];
796799
id_bytes.copy_from_slice(&bytes[0..16]);
@@ -841,7 +844,7 @@ where
841844
Some(inner_state_lock) => {
842845
let mut peer_state = inner_state_lock.lock().unwrap();
843846

844-
let lsps2_id =
847+
let jit_channel_id =
845848
peer_state.request_to_cid.remove(&request_id).ok_or(LightningError {
846849
err: format!(
847850
"Received get_versions response for an unknown request: {:?}",
@@ -850,27 +853,29 @@ where
850853
action: ErrorAction::IgnoreAndLog(Level::Info),
851854
})?;
852855

853-
let lsps2 =
854-
peer_state.inbound_channels_by_id.get_mut(&lsps2_id).ok_or(LightningError {
856+
let jit_channel = peer_state
857+
.inbound_channels_by_id
858+
.get_mut(&jit_channel_id)
859+
.ok_or(LightningError {
855860
err: format!(
856861
"Received get_versions response for an unknown channel: {:?}",
857-
lsps2_id
862+
jit_channel_id,
858863
),
859864
action: ErrorAction::IgnoreAndLog(Level::Info),
860865
})?;
861866

862-
let token = lsps2.config.token.clone();
867+
let token = jit_channel.config.token.clone();
863868

864-
let version = match lsps2.versions_received(result.versions) {
869+
let version = match jit_channel.versions_received(result.versions) {
865870
Ok(version) => version,
866871
Err(e) => {
867-
peer_state.remove_inbound_channel(lsps2_id);
872+
peer_state.remove_inbound_channel(jit_channel_id);
868873
return Err(e);
869874
}
870875
};
871876

872877
let request_id = self.generate_request_id();
873-
peer_state.insert_request(request_id.clone(), lsps2_id);
878+
peer_state.insert_request(request_id.clone(), jit_channel_id);
874879

875880
{
876881
let mut pending_messages = self.pending_messages.lock().unwrap();
@@ -947,7 +952,7 @@ where
947952
Some(inner_state_lock) => {
948953
let mut peer_state = inner_state_lock.lock().unwrap();
949954

950-
let lsps2_id =
955+
let jit_channel_id =
951956
peer_state.request_to_cid.remove(&request_id).ok_or(LightningError {
952957
err: format!(
953958
"Received get_info response for an unknown request: {:?}",
@@ -956,17 +961,19 @@ where
956961
action: ErrorAction::IgnoreAndLog(Level::Info),
957962
})?;
958963

959-
let lsps2 =
960-
peer_state.inbound_channels_by_id.get_mut(&lsps2_id).ok_or(LightningError {
964+
let jit_channel = peer_state
965+
.inbound_channels_by_id
966+
.get_mut(&jit_channel_id)
967+
.ok_or(LightningError {
961968
err: format!(
962969
"Received get_info response for an unknown channel: {:?}",
963-
lsps2_id
970+
jit_channel_id
964971
),
965972
action: ErrorAction::IgnoreAndLog(Level::Info),
966973
})?;
967974

968-
if let Err(e) = lsps2.info_received() {
969-
peer_state.remove_inbound_channel(lsps2_id);
975+
if let Err(e) = jit_channel.info_received() {
976+
peer_state.remove_inbound_channel(jit_channel_id);
970977
return Err(e);
971978
}
972979

@@ -975,8 +982,8 @@ where
975982
opening_fee_params_menu: result.opening_fee_params_menu,
976983
min_payment_size_msat: result.min_payment_size_msat,
977984
max_payment_size_msat: result.max_payment_size_msat,
978-
lsps2_id: lsps2.id,
979-
user_channel_id: lsps2.config.user_id,
985+
jit_channel_id,
986+
user_channel_id: jit_channel.config.user_id,
980987
}));
981988
}
982989
None => {
@@ -1001,7 +1008,7 @@ where
10011008
Some(inner_state_lock) => {
10021009
let mut peer_state = inner_state_lock.lock().unwrap();
10031010

1004-
let lsps2_id =
1011+
let jit_channel_id =
10051012
peer_state.request_to_cid.remove(&request_id).ok_or(LightningError {
10061013
err: format!(
10071014
"Received get_info error for an unknown request: {:?}",
@@ -1010,10 +1017,15 @@ where
10101017
action: ErrorAction::IgnoreAndLog(Level::Info),
10111018
})?;
10121019

1013-
peer_state.inbound_channels_by_id.remove(&lsps2_id).ok_or(LightningError {
1014-
err: format!("Received get_info error for an unknown channel: {:?}", lsps2_id),
1015-
action: ErrorAction::IgnoreAndLog(Level::Info),
1016-
})?;
1020+
peer_state.inbound_channels_by_id.remove(&jit_channel_id).ok_or(
1021+
LightningError {
1022+
err: format!(
1023+
"Received get_info error for an unknown channel: {:?}",
1024+
jit_channel_id
1025+
),
1026+
action: ErrorAction::IgnoreAndLog(Level::Info),
1027+
},
1028+
)?;
10171029
Ok(())
10181030
}
10191031
None => {
@@ -1161,7 +1173,7 @@ where
11611173
Some(inner_state_lock) => {
11621174
let mut peer_state = inner_state_lock.lock().unwrap();
11631175

1164-
let lsps2_id =
1176+
let jit_channel_id =
11651177
peer_state.request_to_cid.remove(&request_id).ok_or(LightningError {
11661178
err: format!(
11671179
"Received buy response for an unknown request: {:?}",
@@ -1170,36 +1182,39 @@ where
11701182
action: ErrorAction::IgnoreAndLog(Level::Info),
11711183
})?;
11721184

1173-
let lsps2 =
1174-
peer_state.inbound_channels_by_id.get_mut(&lsps2_id).ok_or(LightningError {
1185+
let jit_channel = peer_state
1186+
.inbound_channels_by_id
1187+
.get_mut(&jit_channel_id)
1188+
.ok_or(LightningError {
11751189
err: format!(
11761190
"Received buy response for an unknown channel: {:?}",
1177-
lsps2_id
1191+
jit_channel_id
11781192
),
11791193
action: ErrorAction::IgnoreAndLog(Level::Info),
11801194
})?;
11811195

1182-
if let Err(e) = lsps2
1183-
.invoice_params_received(result.client_trusts_lsp, result.lsps2_scid.clone())
1184-
{
1185-
peer_state.remove_inbound_channel(lsps2_id);
1196+
if let Err(e) = jit_channel.invoice_params_received(
1197+
result.client_trusts_lsp,
1198+
result.jit_channel_scid.clone(),
1199+
) {
1200+
peer_state.remove_inbound_channel(jit_channel_id);
11861201
return Err(e);
11871202
}
11881203

1189-
if let Ok(scid) = result.lsps2_scid.to_scid() {
1204+
if let Ok(scid) = result.jit_channel_scid.to_scid() {
11901205
self.enqueue_event(Event::LSPS2(LSPS2Event::InvoiceGenerationReady {
11911206
counterparty_node_id: *counterparty_node_id,
11921207
scid,
11931208
cltv_expiry_delta: result.lsp_cltv_expiry_delta,
1194-
payment_size_msat: lsps2.config.payment_size_msat,
1209+
payment_size_msat: jit_channel.config.payment_size_msat,
11951210
client_trusts_lsp: result.client_trusts_lsp,
1196-
user_channel_id: lsps2.config.user_id,
1211+
user_channel_id: jit_channel.config.user_id,
11971212
}));
11981213
} else {
11991214
return Err(LightningError {
12001215
err: format!(
12011216
"Received buy response with an invalid scid {:?}",
1202-
result.lsps2_scid
1217+
result.jit_channel_scid
12031218
),
12041219
action: ErrorAction::IgnoreAndLog(Level::Info),
12051220
});
@@ -1226,15 +1241,20 @@ where
12261241
Some(inner_state_lock) => {
12271242
let mut peer_state = inner_state_lock.lock().unwrap();
12281243

1229-
let lsps2_id =
1244+
let jit_channel_id =
12301245
peer_state.request_to_cid.remove(&request_id).ok_or(LightningError {
12311246
err: format!("Received buy error for an unknown request: {:?}", request_id),
12321247
action: ErrorAction::IgnoreAndLog(Level::Info),
12331248
})?;
12341249

1235-
let _lsps2 =
1236-
peer_state.inbound_channels_by_id.remove(&lsps2_id).ok_or(LightningError {
1237-
err: format!("Received buy error for an unknown channel: {:?}", lsps2_id),
1250+
let _jit_channel = peer_state
1251+
.inbound_channels_by_id
1252+
.remove(&jit_channel_id)
1253+
.ok_or(LightningError {
1254+
err: format!(
1255+
"Received buy error for an unknown channel: {:?}",
1256+
jit_channel_id
1257+
),
12381258
action: ErrorAction::IgnoreAndLog(Level::Info),
12391259
})?;
12401260
Ok(())

src/lsps2/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub enum LSPS2Event {
4949
/// It needs to be passed to [`LiquidityManager::opening_fee_params_selected`].
5050
///
5151
/// [`LiquidityManager::opening_fee_params_selected`]: crate::LiquidityManager::opening_fee_params_selected
52-
lsps2_id: u128,
52+
jit_channel_id: u128,
5353
/// The node id of the LSP that provided this response.
5454
counterparty_node_id: PublicKey,
5555
/// The menu of fee parameters the LSP is offering at this time.

src/lsps2/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl JitChannelScid {
150150
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
151151
pub struct BuyResponse {
152152
/// The short channel id used by LSP to identify need to open channel.
153-
pub lsps2_scid: JitChannelScid,
153+
pub jit_channel_scid: JitChannelScid,
154154
/// The locktime expiry delta the lsp requires.
155155
pub lsp_cltv_expiry_delta: u32,
156156
/// A flag that indicates who is trusting who.

0 commit comments

Comments
 (0)