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

Commit 5e0076c

Browse files
authored
Merge pull request #86 from tnull/2024-01-remove-versioning
Remove versioning and cleanup warnings
2 parents a514c46 + 7712297 commit 5e0076c

File tree

19 files changed

+123
-399
lines changed

19 files changed

+123
-399
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: Check formatting
4343
if: matrix.check-fmt
4444
run: rustup component add rustfmt && cargo fmt --all -- --check
45+
- name: Set RUSTFLAGS to deny warnings
46+
if: "matrix.toolchain == 'stable'"
47+
run: echo "RUSTFLAGS=-D warnings" >> "$GITHUB_ENV"
4548
- name: Test on Rust ${{ matrix.toolchain }}
4649
run: |
4750
cargo test

src/events.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,12 @@ impl Future for EventFuture {
131131

132132
#[cfg(test)]
133133
mod tests {
134-
use super::*;
135-
use crate::lsps0::event::LSPS0ClientEvent;
136-
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
137-
138134
#[tokio::test]
139135
#[cfg(feature = "std")]
140136
async fn event_queue_works() {
137+
use super::*;
138+
use crate::lsps0::event::LSPS0ClientEvent;
139+
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
141140
use core::sync::atomic::{AtomicU16, Ordering};
142141
use std::sync::Arc;
143142
use std::time::Duration;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ compile_error!("at least one of the `std` or `no-std` features must be enabled")
2525
extern crate alloc;
2626

2727
mod prelude {
28+
#![allow(unused_imports)]
2829
#[cfg(feature = "hashbrown")]
2930
extern crate hashbrown;
3031

@@ -41,6 +42,8 @@ mod prelude {
4142
pub mod events;
4243
pub mod lsps0;
4344
#[cfg(lsps1)]
45+
// TODO: disallow warnings once the implementation is finished
46+
#[allow(warnings)]
4447
pub mod lsps1;
4548
pub mod lsps2;
4649
mod manager;

src/lsps0/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod tests {
115115
use alloc::sync::Arc;
116116

117117
use crate::lsps0::msgs::{LSPSMessage, RequestId};
118-
use crate::tests::utils::TestEntropy;
118+
use crate::tests::utils::{self, TestEntropy};
119119

120120
use super::*;
121121

src/lsps0/msgs.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::lsps1::msgs::{
99
};
1010
use crate::lsps2::msgs::{
1111
LSPS2Message, LSPS2Request, LSPS2Response, LSPS2_BUY_METHOD_NAME, LSPS2_GET_INFO_METHOD_NAME,
12-
LSPS2_GET_VERSIONS_METHOD_NAME,
1312
};
1413
use crate::prelude::{HashMap, String, ToString, Vec};
1514

@@ -294,9 +293,6 @@ impl Serialize for LSPSMessage {
294293
jsonrpc_object.serialize_field(JSONRPC_METHOD_FIELD_KEY, request.method())?;
295294

296295
match request {
297-
LSPS2Request::GetVersions(params) => {
298-
jsonrpc_object.serialize_field(JSONRPC_PARAMS_FIELD_KEY, params)?
299-
}
300296
LSPS2Request::GetInfo(params) => {
301297
jsonrpc_object.serialize_field(JSONRPC_PARAMS_FIELD_KEY, params)?
302298
}
@@ -309,9 +305,6 @@ impl Serialize for LSPSMessage {
309305
jsonrpc_object.serialize_field(JSONRPC_ID_FIELD_KEY, &request_id.0)?;
310306

311307
match response {
312-
LSPS2Response::GetVersions(result) => {
313-
jsonrpc_object.serialize_field(JSONRPC_RESULT_FIELD_KEY, result)?
314-
}
315308
LSPS2Response::GetInfo(result) => {
316309
jsonrpc_object.serialize_field(JSONRPC_RESULT_FIELD_KEY, result)?
317310
}
@@ -423,14 +416,6 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
423416
LSPS1Request::GetOrder(request),
424417
)))
425418
}
426-
LSPS2_GET_VERSIONS_METHOD_NAME => {
427-
let request = serde_json::from_value(params.unwrap_or(json!({})))
428-
.map_err(de::Error::custom)?;
429-
Ok(LSPSMessage::LSPS2(LSPS2Message::Request(
430-
RequestId(id),
431-
LSPS2Request::GetVersions(request),
432-
)))
433-
}
434419
LSPS2_GET_INFO_METHOD_NAME => {
435420
let request = serde_json::from_value(params.unwrap_or(json!({})))
436421
.map_err(de::Error::custom)?;
@@ -471,18 +456,6 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
471456
Err(de::Error::custom("Received invalid JSON-RPC object: one of method, result, or error required"))
472457
}
473458
}
474-
LSPS2_GET_VERSIONS_METHOD_NAME => {
475-
if let Some(result) = result {
476-
let response =
477-
serde_json::from_value(result).map_err(de::Error::custom)?;
478-
Ok(LSPSMessage::LSPS2(LSPS2Message::Response(
479-
RequestId(id),
480-
LSPS2Response::GetVersions(response),
481-
)))
482-
} else {
483-
Err(de::Error::custom("Received invalid lsps2.get_versions response."))
484-
}
485-
}
486459
#[cfg(lsps1)]
487460
LSPS1_CREATE_ORDER_METHOD_NAME => {
488461
if let Some(error) = error {

src/lsps0/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl ProtocolMessageHandler for LSPS0ServiceHandler {
8282
mod tests {
8383

8484
use crate::lsps0::msgs::{LSPSMessage, ListProtocolsRequest};
85-
use crate::utils;
85+
use crate::tests::utils;
8686
use alloc::string::ToString;
8787
use alloc::sync::Arc;
8888

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.

0 commit comments

Comments
 (0)