Skip to content

Commit cfc636c

Browse files
committed
Prefix BLIP-52/LSPS2 message types to avoid naming collisions
1 parent 6b720fd commit cfc636c

File tree

6 files changed

+65
-61
lines changed

6 files changed

+65
-61
lines changed

lightning-liquidity/src/lsps2/client.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use core::default::Default;
2626
use core::ops::Deref;
2727

2828
use crate::lsps2::msgs::{
29-
BuyRequest, BuyResponse, GetInfoRequest, GetInfoResponse, LSPS2Message, LSPS2Request,
30-
LSPS2Response, OpeningFeeParams,
29+
LSPS2BuyRequest, LSPS2BuyResponse, LSPS2GetInfoRequest, LSPS2GetInfoResponse, LSPS2Message,
30+
LSPS2OpeningFeeParams, LSPS2Request, LSPS2Response,
3131
};
3232

3333
/// Client-side configuration options for JIT channels.
@@ -122,7 +122,7 @@ where
122122
peer_state_lock.pending_get_info_requests.insert(request_id.clone());
123123
}
124124

125-
let request = LSPS2Request::GetInfo(GetInfoRequest { token });
125+
let request = LSPS2Request::GetInfo(LSPS2GetInfoRequest { token });
126126
let msg = LSPS2Message::Request(request_id.clone(), request).into();
127127
self.pending_messages.enqueue(&counterparty_node_id, msg);
128128

@@ -149,7 +149,7 @@ where
149149
/// [`InvoiceParametersReady`]: crate::lsps2::event::LSPS2ClientEvent::InvoiceParametersReady
150150
pub fn select_opening_params(
151151
&self, counterparty_node_id: PublicKey, payment_size_msat: Option<u64>,
152-
opening_fee_params: OpeningFeeParams,
152+
opening_fee_params: LSPS2OpeningFeeParams,
153153
) -> Result<RequestId, APIError> {
154154
let request_id = crate::utils::generate_request_id(&self.entropy_source);
155155

@@ -173,15 +173,16 @@ where
173173
}
174174
}
175175

176-
let request = LSPS2Request::Buy(BuyRequest { opening_fee_params, payment_size_msat });
176+
let request = LSPS2Request::Buy(LSPS2BuyRequest { opening_fee_params, payment_size_msat });
177177
let msg = LSPS2Message::Request(request_id.clone(), request).into();
178178
self.pending_messages.enqueue(&counterparty_node_id, msg);
179179

180180
Ok(request_id)
181181
}
182182

183183
fn handle_get_info_response(
184-
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: GetInfoResponse,
184+
&self, request_id: RequestId, counterparty_node_id: &PublicKey,
185+
result: LSPS2GetInfoResponse,
185186
) -> Result<(), LightningError> {
186187
let outer_state_lock = self.per_peer_state.read().unwrap();
187188
match outer_state_lock.get(counterparty_node_id) {
@@ -245,7 +246,7 @@ where
245246
}
246247

247248
fn handle_buy_response(
248-
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: BuyResponse,
249+
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: LSPS2BuyResponse,
249250
) -> Result<(), LightningError> {
250251
let outer_state_lock = self.per_peer_state.read().unwrap();
251252
match outer_state_lock.get(counterparty_node_id) {

lightning-liquidity/src/lsps2/event.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
//! Contains bLIP-52 / LSPS2 event types
1111
12-
use super::msgs::OpeningFeeParams;
12+
use super::msgs::LSPS2OpeningFeeParams;
1313
use crate::lsps0::ser::RequestId;
1414
use crate::prelude::{String, Vec};
1515

@@ -36,7 +36,7 @@ pub enum LSPS2ClientEvent {
3636
counterparty_node_id: PublicKey,
3737
/// The menu of fee parameters the LSP is offering at this time.
3838
/// You must select one of these if you wish to proceed.
39-
opening_fee_params_menu: Vec<OpeningFeeParams>,
39+
opening_fee_params_menu: Vec<LSPS2OpeningFeeParams>,
4040
},
4141
/// Provides the necessary information to generate a payable invoice that then may be given to
4242
/// the payer.
@@ -103,7 +103,7 @@ pub enum LSPS2ServiceEvent {
103103
/// The client node id that is making this request.
104104
counterparty_node_id: PublicKey,
105105
/// The channel parameters they have selected.
106-
opening_fee_params: OpeningFeeParams,
106+
opening_fee_params: LSPS2OpeningFeeParams,
107107
/// The size of the initial payment they would like to receive.
108108
payment_size_msat: Option<u64>,
109109
},

lightning-liquidity/src/lsps2/msgs.rs

+36-34
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_LARGE_ERROR_CODE: i32 = 203;
2727

2828
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
2929
/// A request made to an LSP to learn their current channel fees and parameters.
30-
pub struct GetInfoRequest {
30+
pub struct LSPS2GetInfoRequest {
3131
/// An optional token to provide to the LSP.
3232
pub token: Option<String>,
3333
}
3434

3535
/// Fees and parameters for a JIT Channel without the promise.
3636
///
3737
/// The promise will be calculated automatically for the LSP and this type converted
38-
/// into an [`OpeningFeeParams`] for transit over the wire.
39-
pub struct RawOpeningFeeParams {
38+
/// into an [`LSPS2OpeningFeeParams`] for transit over the wire.
39+
pub struct LSPS2RawOpeningFeeParams {
4040
/// The minimum fee required for the channel open.
4141
pub min_fee_msat: u64,
4242
/// A fee proportional to the size of the initial payment.
@@ -53,8 +53,10 @@ pub struct RawOpeningFeeParams {
5353
pub max_payment_size_msat: u64,
5454
}
5555

56-
impl RawOpeningFeeParams {
57-
pub(crate) fn into_opening_fee_params(self, promise_secret: &[u8; 32]) -> OpeningFeeParams {
56+
impl LSPS2RawOpeningFeeParams {
57+
pub(crate) fn into_opening_fee_params(
58+
self, promise_secret: &[u8; 32],
59+
) -> LSPS2OpeningFeeParams {
5860
let mut hmac = HmacEngine::<Sha256>::new(promise_secret);
5961
hmac.input(&self.min_fee_msat.to_be_bytes());
6062
hmac.input(&self.proportional.to_be_bytes());
@@ -65,7 +67,7 @@ impl RawOpeningFeeParams {
6567
hmac.input(&self.max_payment_size_msat.to_be_bytes());
6668
let promise_bytes = Hmac::from_engine(hmac).to_byte_array();
6769
let promise = utils::hex_str(&promise_bytes[..]);
68-
OpeningFeeParams {
70+
LSPS2OpeningFeeParams {
6971
min_fee_msat: self.min_fee_msat,
7072
proportional: self.proportional,
7173
valid_until: self.valid_until.clone(),
@@ -82,9 +84,9 @@ impl RawOpeningFeeParams {
8284
/// Fees and parameters for a JIT Channel including the promise.
8385
///
8486
/// The promise is an HMAC calculated using a secret known to the LSP and the rest of the fields as input.
85-
/// It exists so the LSP can verify the authenticity of a client provided OpeningFeeParams by recalculating
87+
/// It exists so the LSP can verify the authenticity of a client provided LSPS2OpeningFeeParams by recalculating
8688
/// the promise using the secret. Once verified they can be confident it was not modified by the client.
87-
pub struct OpeningFeeParams {
89+
pub struct LSPS2OpeningFeeParams {
8890
/// The minimum fee required for the channel open.
8991
#[serde(with = "string_amount")]
9092
pub min_fee_msat: u64,
@@ -106,18 +108,18 @@ pub struct OpeningFeeParams {
106108
pub promise: String,
107109
}
108110

109-
/// A response to a [`GetInfoRequest`]
111+
/// A response to a [`LSPS2GetInfoRequest`]
110112
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
111-
pub struct GetInfoResponse {
113+
pub struct LSPS2GetInfoResponse {
112114
/// A set of opening fee parameters.
113-
pub opening_fee_params_menu: Vec<OpeningFeeParams>,
115+
pub opening_fee_params_menu: Vec<LSPS2OpeningFeeParams>,
114116
}
115117

116118
/// A request to buy a JIT channel.
117119
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
118-
pub struct BuyRequest {
120+
pub struct LSPS2BuyRequest {
119121
/// The fee parameters you would like to use.
120-
pub opening_fee_params: OpeningFeeParams,
122+
pub opening_fee_params: LSPS2OpeningFeeParams,
121123
/// The size of the initial payment you expect to receive.
122124
#[serde(default)]
123125
#[serde(skip_serializing_if = "Option::is_none")]
@@ -127,9 +129,9 @@ pub struct BuyRequest {
127129

128130
/// A newtype that holds a `short_channel_id` in human readable format of BBBxTTTx000.
129131
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
130-
pub struct InterceptScid(String);
132+
pub struct LSPS2InterceptScid(String);
131133

132-
impl From<u64> for InterceptScid {
134+
impl From<u64> for LSPS2InterceptScid {
133135
fn from(scid: u64) -> Self {
134136
let block = scid_utils::block_from_scid(scid);
135137
let tx_index = scid_utils::tx_index_from_scid(scid);
@@ -139,20 +141,20 @@ impl From<u64> for InterceptScid {
139141
}
140142
}
141143

142-
impl InterceptScid {
143-
/// Try to convert a [`InterceptScid`] into a u64 used by LDK.
144+
impl LSPS2InterceptScid {
145+
/// Try to convert a [`LSPS2InterceptScid`] into a u64 used by LDK.
144146
pub fn to_scid(&self) -> Result<u64, ()> {
145147
utils::scid_from_human_readable_string(&self.0)
146148
}
147149
}
148150

149-
/// A response to a [`BuyRequest`].
151+
/// A response to a [`LSPS2BuyRequest`].
150152
///
151153
/// Includes information needed to construct an invoice.
152154
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
153-
pub struct BuyResponse {
155+
pub struct LSPS2BuyResponse {
154156
/// The intercept short channel id used by LSP to identify need to open channel.
155-
pub jit_channel_scid: InterceptScid,
157+
pub jit_channel_scid: LSPS2InterceptScid,
156158
/// The locktime expiry delta the lsp requires.
157159
pub lsp_cltv_expiry_delta: u32,
158160
/// A flag that indicates who is trusting who.
@@ -164,20 +166,20 @@ pub struct BuyResponse {
164166
/// An enum that captures all the valid JSON-RPC requests in the bLIP-52 / LSPS2 protocol.
165167
pub enum LSPS2Request {
166168
/// A request to learn an LSP's channel fees and parameters.
167-
GetInfo(GetInfoRequest),
169+
GetInfo(LSPS2GetInfoRequest),
168170
/// A request to buy a JIT channel from an LSP.
169-
Buy(BuyRequest),
171+
Buy(LSPS2BuyRequest),
170172
}
171173

172174
#[derive(Clone, Debug, PartialEq, Eq)]
173175
/// An enum that captures all the valid JSON-RPC responses in the bLIP-52 / LSPS2 protocol.
174176
pub enum LSPS2Response {
175177
/// A successful response to a [`LSPS2Request::GetInfo`] request.
176-
GetInfo(GetInfoResponse),
178+
GetInfo(LSPS2GetInfoResponse),
177179
/// An error response to a [`LSPS2Request::GetInfo`] request.
178180
GetInfoError(ResponseError),
179181
/// A successful response to a [`LSPS2Request::Buy`] request.
180-
Buy(BuyResponse),
182+
Buy(LSPS2BuyResponse),
181183
/// An error response to a [`LSPS2Request::Buy`] request.
182184
BuyError(ResponseError),
183185
}
@@ -226,7 +228,7 @@ mod tests {
226228
let min_payment_size_msat = 1;
227229
let max_payment_size_msat = 100_000_000;
228230

229-
let raw = RawOpeningFeeParams {
231+
let raw = LSPS2RawOpeningFeeParams {
230232
min_fee_msat,
231233
proportional,
232234
valid_until: valid_until.clone().into(),
@@ -261,7 +263,7 @@ mod tests {
261263
let min_payment_size_msat = 1;
262264
let max_payment_size_msat = 100_000_000;
263265

264-
let raw = RawOpeningFeeParams {
266+
let raw = LSPS2RawOpeningFeeParams {
265267
min_fee_msat,
266268
proportional,
267269
valid_until: valid_until.into(),
@@ -288,7 +290,7 @@ mod tests {
288290
let min_payment_size_msat = 1;
289291
let max_payment_size_msat = 100_000_000;
290292

291-
let raw = RawOpeningFeeParams {
293+
let raw = LSPS2RawOpeningFeeParams {
292294
min_fee_msat,
293295
proportional,
294296
valid_until: valid_until.into(),
@@ -317,7 +319,7 @@ mod tests {
317319
let min_payment_size_msat = 1;
318320
let max_payment_size_msat = 100_000_000;
319321

320-
let raw = RawOpeningFeeParams {
322+
let raw = LSPS2RawOpeningFeeParams {
321323
min_fee_msat,
322324
proportional,
323325
valid_until: valid_until.into(),
@@ -343,7 +345,7 @@ mod tests {
343345
let min_payment_size_msat = 1;
344346
let max_payment_size_msat = 100_000_000;
345347

346-
let raw = RawOpeningFeeParams {
348+
let raw = LSPS2RawOpeningFeeParams {
347349
min_fee_msat,
348350
proportional,
349351
valid_until: valid_until.into(),
@@ -362,13 +364,13 @@ mod tests {
362364

363365
let payment_size_msat = Some(1234);
364366
let buy_request_fixed =
365-
BuyRequest { opening_fee_params: opening_fee_params.clone(), payment_size_msat };
367+
LSPS2BuyRequest { opening_fee_params: opening_fee_params.clone(), payment_size_msat };
366368
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"},"payment_size_msat":"1234"}"#;
367369
assert_eq!(json_str, serde_json::json!(buy_request_fixed).to_string());
368370
assert_eq!(buy_request_fixed, serde_json::from_str(json_str).unwrap());
369371

370372
let payment_size_msat = None;
371-
let buy_request_variable = BuyRequest { opening_fee_params, payment_size_msat };
373+
let buy_request_variable = LSPS2BuyRequest { opening_fee_params, payment_size_msat };
372374

373375
// Check we skip serialization if payment_size_msat is None.
374376
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"}}"#;
@@ -407,7 +409,7 @@ mod tests {
407409
}
408410
]
409411
}"#;
410-
let _get_info_response: GetInfoResponse = serde_json::from_str(json_str).unwrap();
412+
let _get_info_response: LSPS2GetInfoResponse = serde_json::from_str(json_str).unwrap();
411413

412414
let json_str = r#"{
413415
"opening_fee_params": {
@@ -422,13 +424,13 @@ mod tests {
422424
},
423425
"payment_size_msat": "42000"
424426
}"#;
425-
let _buy_request: BuyRequest = serde_json::from_str(json_str).unwrap();
427+
let _buy_request: LSPS2BuyRequest = serde_json::from_str(json_str).unwrap();
426428

427429
let json_str = r#"{
428430
"jit_channel_scid": "29451x4815x1",
429431
"lsp_cltv_expiry_delta" : 144,
430432
"client_trusts_lsp": false
431433
}"#;
432-
let _buy_response: BuyResponse = serde_json::from_str(json_str).unwrap();
434+
let _buy_response: LSPS2BuyResponse = serde_json::from_str(json_str).unwrap();
433435
}
434436
}

0 commit comments

Comments
 (0)