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

Commit 0e70831

Browse files
committed
Drop versioning from LSPS1
... as the spec dropped versioning, we now make the corresponding adjustments.
1 parent 8e74c18 commit 0e70831

File tree

4 files changed

+30
-79
lines changed

4 files changed

+30
-79
lines changed

src/lsps1/client.rs

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file is Copyright its original authors, visible in version contror
1+
// This file is Copyright its original authors, visible in version control
22
// history.
33
//
44
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
@@ -35,8 +35,6 @@ use bitcoin::secp256k1::PublicKey;
3535

3636
use core::ops::Deref;
3737

38-
const SUPPORTED_SPEC_VERSIONS: [u16; 1] = [1];
39-
4038
/// Client-side configuration options for LSPS1 channel requests.
4139
#[derive(Clone, Debug)]
4240
pub struct LSPS1ClientConfig {
@@ -55,43 +53,30 @@ impl From<ChannelStateError> for LightningError {
5553
#[derive(PartialEq, Debug)]
5654
enum InboundRequestState {
5755
InfoRequested,
58-
OptionsSupport { version: u16, options_supported: OptionsSupported },
59-
OrderRequested { version: u16, order: OrderParams },
56+
OptionsSupport { options_supported: OptionsSupported },
57+
OrderRequested { order: OrderParams },
6058
PendingPayment { order_id: OrderId },
6159
AwaitingConfirmation { id: u128, order_id: OrderId },
6260
}
6361

6462
impl InboundRequestState {
65-
fn info_received(
66-
&self, versions: Vec<u16>, options: OptionsSupported,
67-
) -> Result<Self, ChannelStateError> {
68-
let max_shared_version = versions
69-
.iter()
70-
.filter(|version| SUPPORTED_SPEC_VERSIONS.contains(version))
71-
.max()
72-
.cloned()
73-
.ok_or(ChannelStateError(format!(
74-
"LSP does not support any of our specification versions. ours = {:?}. theirs = {:?}",
75-
SUPPORTED_SPEC_VERSIONS, versions
76-
)))?;
77-
63+
fn info_received(&self, options: OptionsSupported) -> Result<Self, ChannelStateError> {
7864
match self {
79-
InboundRequestState::InfoRequested => Ok(InboundRequestState::OptionsSupport {
80-
version: max_shared_version,
81-
options_supported: options,
82-
}),
65+
InboundRequestState::InfoRequested => {
66+
Ok(InboundRequestState::OptionsSupport { options_supported: options })
67+
}
8368
state => Err(ChannelStateError(format!(
84-
"Received unexpected get_versions response. Channel was in state: {:?}",
69+
"Received unexpected get_info response. Channel was in state: {:?}",
8570
state
8671
))),
8772
}
8873
}
8974

9075
fn order_requested(&self, order: OrderParams) -> Result<Self, ChannelStateError> {
9176
match self {
92-
InboundRequestState::OptionsSupport { version, options_supported } => {
77+
InboundRequestState::OptionsSupport { options_supported } => {
9378
if is_valid(&order, options_supported) {
94-
Ok(InboundRequestState::OrderRequested { version: *version, order })
79+
Ok(InboundRequestState::OrderRequested { order })
9580
} else {
9681
return Err(ChannelStateError(format!(
9782
"The order created does not match options supported by LSP. Options Supported by LSP are {:?}. The order created was {:?}",
@@ -110,7 +95,7 @@ impl InboundRequestState {
11095
&self, response_order: &OrderParams, order_id: OrderId,
11196
) -> Result<Self, ChannelStateError> {
11297
match self {
113-
InboundRequestState::OrderRequested { version, order } => {
98+
InboundRequestState::OrderRequested { order } => {
11499
if response_order == order {
115100
Ok(InboundRequestState::PendingPayment { order_id })
116101
} else {
@@ -153,25 +138,23 @@ impl InboundCRChannel {
153138
Self { id, state: InboundRequestState::InfoRequested }
154139
}
155140

156-
fn info_received(
157-
&mut self, versions: Vec<u16>, options: OptionsSupported,
158-
) -> Result<u16, LightningError> {
159-
self.state = self.state.info_received(versions, options)?;
141+
fn info_received(&mut self, options: OptionsSupported) -> Result<(), LightningError> {
142+
self.state = self.state.info_received(options)?;
160143

161144
match self.state {
162-
InboundRequestState::OptionsSupport { version, .. } => Ok(version),
145+
InboundRequestState::OptionsSupport { .. } => Ok(()),
163146
_ => Err(LightningError {
164147
action: ErrorAction::IgnoreAndLog(Level::Error),
165148
err: "impossible state transition".to_string(),
166149
}),
167150
}
168151
}
169152

170-
fn order_requested(&mut self, order: OrderParams) -> Result<u16, LightningError> {
153+
fn order_requested(&mut self, order: OrderParams) -> Result<(), LightningError> {
171154
self.state = self.state.order_requested(order)?;
172155

173156
match self.state {
174-
InboundRequestState::OrderRequested { version, .. } => Ok(version),
157+
InboundRequestState::OrderRequested { .. } => Ok(()),
175158
_ => {
176159
return Err(LightningError {
177160
action: ErrorAction::IgnoreAndLog(Level::Error),
@@ -301,10 +284,8 @@ where
301284
action: ErrorAction::IgnoreAndLog(Level::Info),
302285
})?;
303286

304-
let version = match inbound_channel
305-
.info_received(result.supported_versions, result.options.clone())
306-
{
307-
Ok(version) => version,
287+
match inbound_channel.info_received(result.options.clone()) {
288+
Ok(()) => (),
308289
Err(e) => {
309290
peer_state_lock.remove_inbound_channel(channel_id);
310291
return Err(e);
@@ -315,7 +296,6 @@ where
315296
id: channel_id,
316297
request_id,
317298
counterparty_node_id: *counterparty_node_id,
318-
version,
319299
website: result.website,
320300
options_supported: result.options,
321301
}))
@@ -349,8 +329,8 @@ where
349329
err: format!("Channel with id {} not found", channel_id),
350330
})?;
351331

352-
let version = match inbound_channel.order_requested(order.clone()) {
353-
Ok(version) => version,
332+
match inbound_channel.order_requested(order.clone()) {
333+
Ok(()) => (),
354334
Err(e) => {
355335
peer_state_lock.remove_inbound_channel(channel_id);
356336
return Err(APIError::APIMisuseError { err: e.err });
@@ -364,7 +344,7 @@ where
364344
counterparty_node_id,
365345
LSPS1Message::Request(
366346
request_id,
367-
LSPS1Request::CreateOrder(CreateOrderRequest { order, version }),
347+
LSPS1Request::CreateOrder(CreateOrderRequest { order }),
368348
)
369349
.into(),
370350
);
@@ -540,7 +520,7 @@ where
540520
let channel_id =
541521
peer_state_lock.request_to_cid.remove(&request_id).ok_or(LightningError {
542522
err: format!(
543-
"Received get_versions response for an unknown request: {:?}",
523+
"Received get_order response for an unknown request: {:?}",
544524
request_id
545525
),
546526
action: ErrorAction::IgnoreAndLog(Level::Info),
@@ -551,7 +531,7 @@ where
551531
.get_mut(&channel_id)
552532
.ok_or(LightningError {
553533
err: format!(
554-
"Received get_versions response for an unknown channel: {:?}",
534+
"Received get_order response for an unknown channel: {:?}",
555535
channel_id
556536
),
557537
action: ErrorAction::IgnoreAndLog(Level::Info),

src/lsps1/event.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ pub enum LSPS1ClientEvent {
1919
/// TODO
2020
counterparty_node_id: PublicKey,
2121
/// TODO
22-
version: u16,
23-
/// TODO
2422
website: String,
2523
/// TODO
2624
options_supported: OptionsSupported,

src/lsps1/msgs.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub(crate) const LSPS1_GET_ORDER_METHOD_NAME: &str = "lsps1.get_order";
1616
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_INVALID_PARAMS_ERROR_CODE: i32 = -32602;
1717
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE: i32 = 1000;
1818
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_CLIENT_REJECTED_ERROR_CODE: i32 = 1001;
19-
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_INVALID_VERSION_ERROR_CODE: i32 = 1;
2019
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_INVALID_TOKEN_ERROR_CODE: i32 = 2;
2120

2221
/// The identifier of an order.
@@ -62,8 +61,6 @@ pub struct OptionsSupported {
6261
/// A response to an [`GetInfoRequest`].
6362
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
6463
pub struct GetInfoResponse {
65-
/// A list of all supported API versions by the LSP.
66-
pub supported_versions: Vec<u16>,
6764
/// The website of the LSP.
6865
pub website: String,
6966
/// All options supported by the LSP.
@@ -76,17 +73,13 @@ pub struct GetInfoResponse {
7673
/// for more information.
7774
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
7875
pub struct CreateOrderRequest {
79-
/// TODO: this is superfluous and should likely be removed.
80-
pub version: u16,
8176
/// The order made.
8277
pub order: OrderParams,
8378
}
8479

8580
/// An object representing an LSPS1 channel order.
8681
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
8782
pub struct OrderParams {
88-
/// The API version that the client wants to work with.
89-
pub api_version: u16,
9083
/// Indicates how many satoshi the LSP will provide on their side.
9184
pub lsp_balance_sat: u64,
9285
/// Indicates how many satoshi the client will provide on their side.

src/lsps1/service.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file is Copyright its original authors, visible in version contror
1+
// This file is Copyright its original authors, visible in version control
22
// history.
33
//
44
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
@@ -13,8 +13,7 @@ use super::event::LSPS1ServiceEvent;
1313
use super::msgs::{
1414
ChannelInfo, CreateOrderRequest, CreateOrderResponse, GetInfoResponse, GetOrderRequest,
1515
GetOrderResponse, LSPS1Message, LSPS1Request, LSPS1Response, OptionsSupported, OrderId,
16-
OrderParams, OrderPayment, OrderState, LSPS1_CREATE_ORDER_REQUEST_INVALID_VERSION_ERROR_CODE,
17-
LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
16+
OrderParams, OrderPayment, OrderState, LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
1817
};
1918
use super::utils::is_valid;
2019
use crate::message_queue::MessageQueue;
@@ -38,8 +37,6 @@ use bitcoin::secp256k1::PublicKey;
3837
use chrono::Utc;
3938
use core::ops::Deref;
4039

41-
const SUPPORTED_SPEC_VERSIONS: [u16; 1] = [1];
42-
4340
/// Server-side configuration options for LSPS1 channel requests.
4441
#[derive(Clone, Debug)]
4542
pub struct LSPS1ServiceConfig {
@@ -72,10 +69,7 @@ impl OutboundRequestState {
7269
OutboundRequestState::OrderCreated { order_id } => {
7370
Ok(OutboundRequestState::WaitingPayment { order_id: order_id.clone() })
7471
}
75-
state => Err(ChannelStateError(format!(
76-
"Received unexpected get_versions response. JIT Channel was in state: {:?}",
77-
state
78-
))),
72+
state => Err(ChannelStateError(format!("TODO. JIT Channel was in state: {:?}", state))),
7973
}
8074
}
8175
}
@@ -177,7 +171,6 @@ where
177171
&self, request_id: RequestId, counterparty_node_id: &PublicKey,
178172
) -> Result<(), LightningError> {
179173
let response = GetInfoResponse {
180-
supported_versions: SUPPORTED_SPEC_VERSIONS.to_vec(),
181174
website: self.config.website.clone().unwrap().to_string(),
182175
options: self
183176
.config
@@ -197,22 +190,6 @@ where
197190
fn handle_create_order_request(
198191
&self, request_id: RequestId, counterparty_node_id: &PublicKey, params: CreateOrderRequest,
199192
) -> Result<(), LightningError> {
200-
if !SUPPORTED_SPEC_VERSIONS.contains(&params.version) {
201-
self.enqueue_response(
202-
counterparty_node_id,
203-
request_id,
204-
LSPS1Response::CreateOrderError(ResponseError {
205-
code: LSPS1_CREATE_ORDER_REQUEST_INVALID_VERSION_ERROR_CODE,
206-
message: format!("version {} is not supported", params.version),
207-
data: Some(format!("Supported versions are {:?}", SUPPORTED_SPEC_VERSIONS)),
208-
}),
209-
);
210-
return Err(LightningError {
211-
err: format!("client requested unsupported version {}", params.version),
212-
action: ErrorAction::IgnoreAndLog(Level::Info),
213-
});
214-
}
215-
216193
if !is_valid(&params.order, &self.config.options_supported.as_ref().unwrap()) {
217194
self.enqueue_response(
218195
counterparty_node_id,
@@ -227,7 +204,10 @@ where
227204
}),
228205
);
229206
return Err(LightningError {
230-
err: format!("client requested unsupported version {}", params.version),
207+
err: format!(
208+
"Client order does not match any supported options: {:?}",
209+
params.order
210+
),
231211
action: ErrorAction::IgnoreAndLog(Level::Info),
232212
});
233213
}

0 commit comments

Comments
 (0)