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

Commit 0fcaa1c

Browse files
rename scid to intercept_scid
1 parent 61746a3 commit 0fcaa1c

File tree

4 files changed

+73
-59
lines changed

4 files changed

+73
-59
lines changed

src/lsps2/client.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use core::ops::Deref;
2727

2828
use crate::lsps2::msgs::{
2929
BuyRequest, BuyResponse, GetInfoRequest, GetInfoResponse, GetVersionsRequest,
30-
GetVersionsResponse, JITChannelScid, LSPS2Message, LSPS2Request, LSPS2Response,
30+
GetVersionsResponse, InterceptScid, LSPS2Message, LSPS2Request, LSPS2Response,
3131
OpeningFeeParams,
3232
};
3333

@@ -57,7 +57,7 @@ enum InboundJITChannelState {
5757
MenuRequested { version: u16 },
5858
PendingMenuSelection { version: u16 },
5959
BuyRequested { version: u16 },
60-
PendingPayment { client_trusts_lsp: bool, short_channel_id: JITChannelScid },
60+
PendingPayment { client_trusts_lsp: bool, intercept_scid: InterceptScid },
6161
}
6262

6363
impl InboundJITChannelState {
@@ -108,11 +108,11 @@ impl InboundJITChannelState {
108108
}
109109

110110
fn invoice_params_received(
111-
&self, client_trusts_lsp: bool, short_channel_id: JITChannelScid,
111+
&self, client_trusts_lsp: bool, intercept_scid: InterceptScid,
112112
) -> Result<Self, ChannelStateError> {
113113
match self {
114114
InboundJITChannelState::BuyRequested { .. } => {
115-
Ok(InboundJITChannelState::PendingPayment { client_trusts_lsp, short_channel_id })
115+
Ok(InboundJITChannelState::PendingPayment { client_trusts_lsp, intercept_scid })
116116
}
117117
state => Err(ChannelStateError(format!(
118118
"Invoice params received when JIT Channel was in state: {:?}",
@@ -167,9 +167,9 @@ impl InboundJITChannel {
167167
}
168168

169169
fn invoice_params_received(
170-
&mut self, client_trusts_lsp: bool, jit_channel_scid: JITChannelScid,
170+
&mut self, client_trusts_lsp: bool, intercept_scid: InterceptScid,
171171
) -> Result<(), LightningError> {
172-
self.state = self.state.invoice_params_received(client_trusts_lsp, jit_channel_scid)?;
172+
self.state = self.state.invoice_params_received(client_trusts_lsp, intercept_scid)?;
173173
Ok(())
174174
}
175175
}
@@ -519,17 +519,17 @@ where
519519

520520
if let Err(e) = jit_channel.invoice_params_received(
521521
result.client_trusts_lsp,
522-
result.jit_channel_scid.clone(),
522+
result.intercept_scid.clone(),
523523
) {
524524
peer_state.remove_inbound_channel(jit_channel_id);
525525
return Err(e);
526526
}
527527

528-
if let Ok(scid) = result.jit_channel_scid.to_scid() {
528+
if let Ok(intercept_scid) = result.intercept_scid.to_scid() {
529529
self.pending_events.enqueue(Event::LSPS2Client(
530530
LSPS2ClientEvent::InvoiceGenerationReady {
531531
counterparty_node_id: *counterparty_node_id,
532-
scid,
532+
intercept_scid,
533533
cltv_expiry_delta: result.lsp_cltv_expiry_delta,
534534
payment_size_msat: jit_channel.config.payment_size_msat,
535535
client_trusts_lsp: result.client_trusts_lsp,
@@ -539,8 +539,8 @@ where
539539
} else {
540540
return Err(LightningError {
541541
err: format!(
542-
"Received buy response with an invalid scid {:?}",
543-
result.jit_channel_scid
542+
"Received buy response with an invalid intercept scid {:?}",
543+
result.intercept_scid
544544
),
545545
action: ErrorAction::IgnoreAndLog(Level::Info),
546546
});

src/lsps2/event.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub enum LSPS2ClientEvent {
5252
InvoiceGenerationReady {
5353
/// The node id of the LSP.
5454
counterparty_node_id: PublicKey,
55-
/// The short channel id to use in the route hint.
56-
scid: u64,
55+
/// The intercept short channel id to use in the route hint.
56+
intercept_scid: u64,
5757
/// The `cltv_expiry_delta` to use in the route hint.
5858
cltv_expiry_delta: u32,
5959
/// The initial payment size you specified.
@@ -98,7 +98,7 @@ pub enum LSPS2ServiceEvent {
9898
/// If `payment_size_msat` is [`Option::Some`] then the payer is allowed to use MPP.
9999
/// If `payment_size_msat` is [`Option::None`] then the payer cannot use MPP.
100100
///
101-
/// You must generate an scid and `cltv_expiry_delta` for them to use
101+
/// You must generate an intercept scid and `cltv_expiry_delta` for them to use
102102
/// and call [`LSPS2ServiceHandler::invoice_parameters_generated`].
103103
///
104104
/// [`LSPS2ServiceHandler::invoice_parameters_generated`]: crate::lsps2::service::LSPS2ServiceHandler::invoice_parameters_generated
@@ -128,7 +128,7 @@ pub enum LSPS2ServiceEvent {
128128
opening_fee_msat: u64,
129129
/// A user specified id used to track channel open.
130130
user_channel_id: u128,
131-
/// The short channel id to use in the route hint.
132-
scid: u64,
131+
/// The intercept short channel id to use in the route hint.
132+
intercept_scid: u64,
133133
},
134134
}

src/lsps2/msgs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ pub struct BuyRequest {
128128

129129
/// A newtype that holds a `short_channel_id` in human readable format of BBBxTTTx000.
130130
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
131-
pub struct JITChannelScid(String);
131+
pub struct InterceptScid(String);
132132

133-
impl From<u64> for JITChannelScid {
133+
impl From<u64> for InterceptScid {
134134
fn from(scid: u64) -> Self {
135135
let block = utils::block_from_scid(&scid);
136136
let tx_index = utils::tx_index_from_scid(&scid);
@@ -140,8 +140,8 @@ impl From<u64> for JITChannelScid {
140140
}
141141
}
142142

143-
impl JITChannelScid {
144-
/// Try to convert a [`JITChannelScid`] into a u64 used by LDK.
143+
impl InterceptScid {
144+
/// Try to convert a [`InterceptScid`] into a u64 used by LDK.
145145
pub fn to_scid(&self) -> Result<u64, ()> {
146146
utils::scid_from_human_readable_string(&self.0)
147147
}
@@ -152,8 +152,8 @@ impl JITChannelScid {
152152
/// Includes information needed to construct an invoice.
153153
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
154154
pub struct BuyResponse {
155-
/// The short channel id used by LSP to identify need to open channel.
156-
pub jit_channel_scid: JITChannelScid,
155+
/// The intercept short channel id used by LSP to identify need to open channel.
156+
pub intercept_scid: InterceptScid,
157157
/// The locktime expiry delta the lsp requires.
158158
pub lsp_cltv_expiry_delta: u32,
159159
/// A flag that indicates who is trusting who.

src/lsps2/service.rs

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,20 @@ impl OutboundJITChannelState {
176176

177177
struct OutboundJITChannel {
178178
state: OutboundJITChannelState,
179-
scid: u64,
179+
intercept_scid: u64,
180180
cltv_expiry_delta: u32,
181181
client_trusts_lsp: bool,
182182
user_channel_id: u128,
183183
}
184184

185185
impl OutboundJITChannel {
186186
fn new(
187-
scid: u64, cltv_expiry_delta: u32, client_trusts_lsp: bool, payment_size_msat: Option<u64>,
188-
opening_fee_params: OpeningFeeParams, user_channel_id: u128,
187+
intercept_scid: u64, cltv_expiry_delta: u32, client_trusts_lsp: bool,
188+
payment_size_msat: Option<u64>, opening_fee_params: OpeningFeeParams,
189+
user_channel_id: u128,
189190
) -> Self {
190191
Self {
191-
scid,
192+
intercept_scid,
192193
cltv_expiry_delta,
193194
client_trusts_lsp,
194195
user_channel_id,
@@ -240,25 +241,29 @@ impl OutboundJITChannel {
240241
}
241242

242243
struct PeerState {
243-
outbound_channels_by_scid: HashMap<u64, OutboundJITChannel>,
244-
scid_by_user_channel_id: HashMap<u128, u64>,
244+
outbound_channels_by_intercept_scid: HashMap<u64, OutboundJITChannel>,
245+
intercept_scid_by_user_channel_id: HashMap<u128, u64>,
245246
pending_requests: HashMap<RequestId, LSPS2Request>,
246247
}
247248

248249
impl PeerState {
249250
fn new() -> Self {
250-
let outbound_channels_by_scid = HashMap::new();
251+
let outbound_channels_by_intercept_scid = HashMap::new();
251252
let pending_requests = HashMap::new();
252-
let scid_by_user_channel_id = HashMap::new();
253-
Self { outbound_channels_by_scid, pending_requests, scid_by_user_channel_id }
253+
let intercept_scid_by_user_channel_id = HashMap::new();
254+
Self {
255+
outbound_channels_by_intercept_scid,
256+
pending_requests,
257+
intercept_scid_by_user_channel_id,
258+
}
254259
}
255260

256-
fn insert_outbound_channel(&mut self, scid: u64, channel: OutboundJITChannel) {
257-
self.outbound_channels_by_scid.insert(scid, channel);
261+
fn insert_outbound_channel(&mut self, intercept_scid: u64, channel: OutboundJITChannel) {
262+
self.outbound_channels_by_intercept_scid.insert(intercept_scid, channel);
258263
}
259264

260-
fn remove_outbound_channel(&mut self, scid: u64) {
261-
self.outbound_channels_by_scid.remove(&scid);
265+
fn remove_outbound_channel(&mut self, intercept_scid: u64) {
266+
self.outbound_channels_by_intercept_scid.remove(&intercept_scid);
262267
}
263268
}
264269

@@ -272,7 +277,7 @@ where
272277
pending_messages: MQ,
273278
pending_events: Arc<EventQueue>,
274279
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
275-
peer_by_scid: RwLock<HashMap<u64, PublicKey>>,
280+
peer_by_intercept_scid: RwLock<HashMap<u64, PublicKey>>,
276281
config: LSPS2ServiceConfig,
277282
}
278283

@@ -290,7 +295,7 @@ where
290295
pending_messages,
291296
pending_events,
292297
per_peer_state: RwLock::new(HashMap::new()),
293-
peer_by_scid: RwLock::new(HashMap::new()),
298+
peer_by_intercept_scid: RwLock::new(HashMap::new()),
294299
channel_manager,
295300
config,
296301
}
@@ -378,13 +383,13 @@ where
378383
}
379384
}
380385

381-
/// Used by LSP to provide client with the scid and cltv_expiry_delta to use in their invoice.
386+
/// Used by LSP to provide client with the intercept scid and cltv_expiry_delta to use in their invoice.
382387
///
383388
/// Should be called in response to receiving a [`LSPS2ServiceEvent::BuyRequest`] event.
384389
///
385390
/// [`LSPS2ServiceEvent::BuyRequest`]: crate::lsps2::event::LSPS2ServiceEvent::BuyRequest
386391
pub fn invoice_parameters_generated(
387-
&self, counterparty_node_id: &PublicKey, request_id: RequestId, scid: u64,
392+
&self, counterparty_node_id: &PublicKey, request_id: RequestId, intercept_scid: u64,
388393
cltv_expiry_delta: u32, client_trusts_lsp: bool, user_channel_id: u128,
389394
) -> Result<(), APIError> {
390395
let outer_state_lock = self.per_peer_state.read().unwrap();
@@ -396,27 +401,30 @@ where
396401
match peer_state.pending_requests.remove(&request_id) {
397402
Some(LSPS2Request::Buy(buy_request)) => {
398403
{
399-
let mut peer_by_scid = self.peer_by_scid.write().unwrap();
400-
peer_by_scid.insert(scid, *counterparty_node_id);
404+
let mut peer_by_intercept_scid =
405+
self.peer_by_intercept_scid.write().unwrap();
406+
peer_by_intercept_scid.insert(intercept_scid, *counterparty_node_id);
401407
}
402408

403409
let outbound_jit_channel = OutboundJITChannel::new(
404-
scid,
410+
intercept_scid,
405411
cltv_expiry_delta,
406412
client_trusts_lsp,
407413
buy_request.payment_size_msat,
408414
buy_request.opening_fee_params,
409415
user_channel_id,
410416
);
411417

412-
peer_state.scid_by_user_channel_id.insert(user_channel_id, scid);
413-
peer_state.insert_outbound_channel(scid, outbound_jit_channel);
418+
peer_state
419+
.intercept_scid_by_user_channel_id
420+
.insert(user_channel_id, intercept_scid);
421+
peer_state.insert_outbound_channel(intercept_scid, outbound_jit_channel);
414422

415423
self.enqueue_response(
416424
counterparty_node_id,
417425
request_id,
418426
LSPS2Response::Buy(BuyResponse {
419-
jit_channel_scid: scid.into(),
427+
intercept_scid: intercept_scid.into(),
420428
lsp_cltv_expiry_delta: cltv_expiry_delta,
421429
client_trusts_lsp,
422430
}),
@@ -437,26 +445,28 @@ where
437445

438446
/// Forward [`Event::HTLCIntercepted`] event parameters into this function.
439447
///
440-
/// Will fail the intercepted HTLC if the scid matches a payment we are expecting
448+
/// Will fail the intercepted HTLC if the intercept scid matches a payment we are expecting
441449
/// but the payment amount is incorrect or the expiry has passed.
442450
///
443-
/// Will generate a [`LSPS2ServiceEvent::OpenChannel`] event if the scid matches a payment we are expected
451+
/// Will generate a [`LSPS2ServiceEvent::OpenChannel`] event if the intercept scid matches a payment we are expected
444452
/// and the payment amount is correct and the offer has not expired.
445453
///
446-
/// Will do nothing if the scid does not match any of the ones we gave out.
454+
/// Will do nothing if the intercept scid does not match any of the ones we gave out.
447455
///
448456
/// [`Event::HTLCIntercepted`]: lightning::events::Event::HTLCIntercepted
449457
/// [`LSPS2ServiceEvent::OpenChannel`]: crate::lsps2::event::LSPS2ServiceEvent::OpenChannel
450458
pub fn htlc_intercepted(
451-
&self, scid: u64, intercept_id: InterceptId, expected_outbound_amount_msat: u64,
459+
&self, intercept_scid: u64, intercept_id: InterceptId, expected_outbound_amount_msat: u64,
452460
) -> Result<(), APIError> {
453-
let peer_by_scid = self.peer_by_scid.read().unwrap();
454-
if let Some(counterparty_node_id) = peer_by_scid.get(&scid) {
461+
let peer_by_intercept_scid = self.peer_by_intercept_scid.read().unwrap();
462+
if let Some(counterparty_node_id) = peer_by_intercept_scid.get(&intercept_scid) {
455463
let outer_state_lock = self.per_peer_state.read().unwrap();
456464
match outer_state_lock.get(counterparty_node_id) {
457465
Some(inner_state_lock) => {
458466
let mut peer_state = inner_state_lock.lock().unwrap();
459-
if let Some(jit_channel) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
467+
if let Some(jit_channel) =
468+
peer_state.outbound_channels_by_intercept_scid.get_mut(&intercept_scid)
469+
{
460470
let htlc = InterceptedHTLC { intercept_id, expected_outbound_amount_msat };
461471
match jit_channel.htlc_intercepted(htlc) {
462472
Ok(Some((opening_fee_msat, amt_to_forward_msat))) => {
@@ -466,7 +476,7 @@ where
466476
amt_to_forward_msat,
467477
opening_fee_msat,
468478
user_channel_id: jit_channel.user_channel_id,
469-
scid,
479+
intercept_scid,
470480
},
471481
));
472482
}
@@ -475,16 +485,18 @@ where
475485
self.channel_manager
476486
.get_cm()
477487
.fail_intercepted_htlc(intercept_id)?;
478-
peer_state.outbound_channels_by_scid.remove(&scid);
479-
// TODO: cleanup peer_by_scid
488+
peer_state
489+
.outbound_channels_by_intercept_scid
490+
.remove(&intercept_scid);
491+
// TODO: cleanup peer_by_intercept_scid
480492
return Err(APIError::APIMisuseError { err: e.err });
481493
}
482494
}
483495
}
484496
}
485497
None => {
486498
return Err(APIError::APIMisuseError {
487-
err: format!("No counterparty found for scid: {}", scid),
499+
err: format!("No counterparty found for scid: {}", intercept_scid),
488500
});
489501
}
490502
}
@@ -506,10 +518,12 @@ where
506518
match outer_state_lock.get(counterparty_node_id) {
507519
Some(inner_state_lock) => {
508520
let mut peer_state = inner_state_lock.lock().unwrap();
509-
if let Some(scid) =
510-
peer_state.scid_by_user_channel_id.get(&user_channel_id).copied()
521+
if let Some(intercept_scid) =
522+
peer_state.intercept_scid_by_user_channel_id.get(&user_channel_id).copied()
511523
{
512-
if let Some(jit_channel) = peer_state.outbound_channels_by_scid.get_mut(&scid) {
524+
if let Some(jit_channel) =
525+
peer_state.outbound_channels_by_intercept_scid.get_mut(&intercept_scid)
526+
{
513527
match jit_channel.channel_ready() {
514528
Ok((htlcs, total_amt_to_forward_msat)) => {
515529
let amounts_to_forward_msat = calculate_amount_to_forward_per_htlc(

0 commit comments

Comments
 (0)