Skip to content

Type Renames for lightning-liquidity bindings #3574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lightning-liquidity/src/events.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine for now, but given that we eventually might want to get away from LSPS nomenclature, we could consider naming it differently (LiquidityEvent?). Then again, moving away from LSPS will be a larger refactor at some point anyways, so might as well rename it accordingly again at that point.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use core::task::{Poll, Waker};
pub const MAX_EVENT_QUEUE_SIZE: usize = 1000;

pub(crate) struct EventQueue {
queue: Arc<Mutex<VecDeque<Event>>>,
queue: Arc<Mutex<VecDeque<LSPSEvent>>>,
waker: Arc<Mutex<Option<Waker>>>,
#[cfg(feature = "std")]
condvar: crate::sync::Condvar,
Expand All @@ -47,7 +47,7 @@ impl EventQueue {
Self { queue, waker }
}

pub fn enqueue(&self, event: Event) {
pub fn enqueue(&self, event: LSPSEvent) {
{
let mut queue = self.queue.lock().unwrap();
if queue.len() < MAX_EVENT_QUEUE_SIZE {
Expand All @@ -64,19 +64,19 @@ impl EventQueue {
self.condvar.notify_one();
}

pub fn next_event(&self) -> Option<Event> {
pub fn next_event(&self) -> Option<LSPSEvent> {
self.queue.lock().unwrap().pop_front()
}

pub async fn next_event_async(&self) -> Event {
pub async fn next_event_async(&self) -> LSPSEvent {
EventFuture { event_queue: Arc::clone(&self.queue), waker: Arc::clone(&self.waker) }.await
}

#[cfg(feature = "std")]
pub fn wait_next_event(&self) -> Event {
pub fn wait_next_event(&self) -> LSPSEvent {
let mut queue = self
.condvar
.wait_while(self.queue.lock().unwrap(), |queue: &mut VecDeque<Event>| queue.is_empty())
.wait_while(self.queue.lock().unwrap(), |queue: &mut VecDeque<LSPSEvent>| queue.is_empty())
.unwrap();

let event = queue.pop_front().expect("non-empty queue");
Expand All @@ -95,14 +95,14 @@ impl EventQueue {
event
}

pub fn get_and_clear_pending_events(&self) -> Vec<Event> {
pub fn get_and_clear_pending_events(&self) -> Vec<LSPSEvent> {
self.queue.lock().unwrap().split_off(0).into()
}
}

/// An event which you should probably take some action in response to.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
pub enum LSPSEvent {
/// An LSPS0 client event.
LSPS0Client(lsps0::event::LSPS0ClientEvent),
/// An LSPS1 (Channel Request) client event.
Expand All @@ -117,12 +117,12 @@ pub enum Event {
}

struct EventFuture {
event_queue: Arc<Mutex<VecDeque<Event>>>,
event_queue: Arc<Mutex<VecDeque<LSPSEvent>>>,
waker: Arc<Mutex<Option<Waker>>>,
}

impl Future for EventFuture {
type Output = Event;
type Output = LSPSEvent;

fn poll(
self: core::pin::Pin<&mut Self>, cx: &mut core::task::Context<'_>,
Expand Down Expand Up @@ -154,7 +154,7 @@ mod tests {
let secp_ctx = Secp256k1::new();
let counterparty_node_id =
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
let expected_event = Event::LSPS0Client(LSPS0ClientEvent::ListProtocolsResponse {
let expected_event = LSPSEvent::LSPS0Client(LSPS0ClientEvent::ListProtocolsResponse {
counterparty_node_id,
protocols: Vec::new(),
});
Expand Down
4 changes: 2 additions & 2 deletions lightning-liquidity/src/lsps0/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! specifcation](https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS0) for more
//! information.

use crate::events::{Event, EventQueue};
use crate::events::{LSPSEvent, EventQueue};
use crate::lsps0::event::LSPS0ClientEvent;
use crate::lsps0::msgs::{
LSPS0Message, LSPS0Request, LSPS0Response, ListProtocolsRequest, ListProtocolsResponse,
Expand Down Expand Up @@ -62,7 +62,7 @@ where
) -> Result<(), LightningError> {
match response {
LSPS0Response::ListProtocols(ListProtocolsResponse { protocols }) => {
self.pending_events.enqueue(Event::LSPS0Client(
self.pending_events.enqueue(LSPSEvent::LSPS0Client(
LSPS0ClientEvent::ListProtocolsResponse {
counterparty_node_id: *counterparty_node_id,
protocols,
Expand Down
2 changes: 1 addition & 1 deletion lightning-liquidity/src/lsps0/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum LSPS0Request {

impl LSPS0Request {
/// Returns the method name associated with the given request variant.
pub fn method(&self) -> &str {
pub fn method(&self) -> &'static str {
match self {
LSPS0Request::ListProtocols(_) => LSPS0_LISTPROTOCOLS_METHOD_NAME,
}
Expand Down
20 changes: 10 additions & 10 deletions lightning-liquidity/src/lsps1/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

use super::event::LSPS1ClientEvent;
use super::msgs::{
CreateOrderRequest, CreateOrderResponse, GetInfoRequest, GetInfoResponse, GetOrderRequest,
CreateOrderRequest, CreateOrderResponse, LSPS1GetInfoRequest, LSPS1GetInfoResponse, GetOrderRequest,
Copy link
Contributor

@tnull tnull Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have to do so, can we at least rename all LSPS1 and LSPS2 message types accordingly? I.e., please prefix everything, not just the types that might clash.

Also note to adjust all the testcases accordingly.

LSPS1Message, LSPS1Request, LSPS1Response, OrderId, OrderParameters,
};
use crate::message_queue::MessageQueue;

use crate::events::{Event, EventQueue};
use crate::events::{LSPSEvent, EventQueue};
use crate::lsps0::ser::{ProtocolMessageHandler, RequestId, ResponseError};
use crate::prelude::{new_hash_map, HashMap, HashSet};
use crate::sync::{Arc, Mutex, RwLock};
Expand Down Expand Up @@ -94,14 +94,14 @@ where
peer_state_lock.pending_get_info_requests.insert(request_id.clone());
}

let request = LSPS1Request::GetInfo(GetInfoRequest {});
let request = LSPS1Request::GetInfo(LSPS1GetInfoRequest {});
let msg = LSPS1Message::Request(request_id.clone(), request).into();
self.pending_messages.enqueue(&counterparty_node_id, msg);
request_id
}

fn handle_get_info_response(
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: GetInfoResponse,
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: LSPS1GetInfoResponse,
) -> Result<(), LightningError> {
let outer_state_lock = self.per_peer_state.write().unwrap();

Expand All @@ -119,7 +119,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(
self.pending_events.enqueue(LSPSEvent::LSPS1Client(
LSPS1ClientEvent::SupportedOptionsReady {
counterparty_node_id: *counterparty_node_id,
supported_options: result.options,
Expand Down Expand Up @@ -156,7 +156,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(
self.pending_events.enqueue(LSPSEvent::LSPS1Client(
LSPS1ClientEvent::SupportedOptionsRequestFailed {
request_id: request_id.clone(),
counterparty_node_id: *counterparty_node_id,
Expand Down Expand Up @@ -233,7 +233,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(LSPS1ClientEvent::OrderCreated {
self.pending_events.enqueue(LSPSEvent::LSPS1Client(LSPS1ClientEvent::OrderCreated {
request_id,
counterparty_node_id: *counterparty_node_id,
order_id: response.order_id,
Expand Down Expand Up @@ -274,7 +274,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(
self.pending_events.enqueue(LSPSEvent::LSPS1Client(
LSPS1ClientEvent::OrderRequestFailed {
request_id: request_id.clone(),
counterparty_node_id: *counterparty_node_id,
Expand Down Expand Up @@ -352,7 +352,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(LSPS1ClientEvent::OrderStatus {
self.pending_events.enqueue(LSPSEvent::LSPS1Client(LSPS1ClientEvent::OrderStatus {
request_id,
counterparty_node_id: *counterparty_node_id,
order_id: response.order_id,
Expand Down Expand Up @@ -393,7 +393,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS1Client(
self.pending_events.enqueue(LSPSEvent::LSPS1Client(
LSPS1ClientEvent::OrderRequestFailed {
request_id: request_id.clone(),
counterparty_node_id: *counterparty_node_id,
Expand Down
6 changes: 3 additions & 3 deletions lightning-liquidity/src/lsps1/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! Contains LSPS1 event types

use super::msgs::OrderId;
use super::msgs::{ChannelInfo, LSPS1Options, OrderParameters, PaymentInfo};
use super::msgs::{LSPS1ChannelInfo, LSPS1Options, OrderParameters, PaymentInfo};

use crate::lsps0::ser::{RequestId, ResponseError};

Expand Down Expand Up @@ -84,7 +84,7 @@ pub enum LSPS1ClientEvent {
/// The details regarding payment of the order
payment: PaymentInfo,
/// The details regarding state of the channel ordered.
channel: Option<ChannelInfo>,
channel: Option<LSPS1ChannelInfo>,
},
/// Information from the LSP about the status of a previously created order.
///
Expand All @@ -108,7 +108,7 @@ pub enum LSPS1ClientEvent {
/// The details regarding payment of the order
payment: PaymentInfo,
/// The details regarding state of the channel ordered.
channel: Option<ChannelInfo>,
channel: Option<LSPS1ChannelInfo>,
},
/// A request previously issued via [`LSPS1ClientHandler::create_order`] or [`LSPS1ClientHandler::check_order_status`].
/// failed as the LSP returned an error response.
Expand Down
20 changes: 10 additions & 10 deletions lightning-liquidity/src/lsps1/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct OrderId(pub String);
/// for more information.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(default)]
pub struct GetInfoRequest {}
pub struct LSPS1GetInfoRequest {}

/// An object representing the supported protocol options.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -68,9 +68,9 @@ pub struct LSPS1Options {
pub max_channel_balance_sat: u64,
}

/// A response to a [`GetInfoRequest`].
/// A response to a [`LSPS1GetInfoRequest`].
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GetInfoResponse {
pub struct LSPS1GetInfoResponse {
/// All options supported by the LSP.
#[serde(flatten)]
pub options: LSPS1Options,
Expand Down Expand Up @@ -131,7 +131,7 @@ pub struct CreateOrderResponse {
/// Contains details about how to pay for the order.
pub payment: PaymentInfo,
/// Contains information about the channel state.
pub channel: Option<ChannelInfo>,
pub channel: Option<LSPS1ChannelInfo>,
}

/// An object representing the state of an order.
Expand Down Expand Up @@ -233,7 +233,7 @@ pub struct OnchainPayment {

/// Details regarding the state of an ordered channel.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ChannelInfo {
pub struct LSPS1ChannelInfo {
/// The datetime when the funding transaction has been published.
pub funded_at: chrono::DateTime<Utc>,
/// The outpoint of the funding transaction.
Expand All @@ -256,7 +256,7 @@ pub struct GetOrderRequest {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LSPS1Request {
/// A request to learn about the options supported by the LSP.
GetInfo(GetInfoRequest),
GetInfo(LSPS1GetInfoRequest),
/// A request to create a channel order.
CreateOrder(CreateOrderRequest),
/// A request to query a previously created channel order.
Expand All @@ -266,9 +266,9 @@ pub enum LSPS1Request {
/// An enum that captures all the valid JSON-RPC responses in the LSPS1 protocol.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LSPS1Response {
/// A successful response to a [`GetInfoRequest`].
GetInfo(GetInfoResponse),
/// An error response to a [`GetInfoRequest`].
/// A successful response to a [`LSPS1GetInfoRequest`].
GetInfo(LSPS1GetInfoResponse),
/// An error response to a [`LSPS1GetInfoRequest`].
GetInfoError(ResponseError),
/// A successful response to a [`CreateOrderRequest`].
CreateOrder(CreateOrderResponse),
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
"funding_outpoint": "0301e0480b374b32851a9462db29dc19fe830a7f7d7a88b81612b9d42099c0ae:0",
"expires_at": "2012-04-23T18:25:43.511Z"
}"#;
let _channel: ChannelInfo = serde_json::from_str(json_str).unwrap();
let _channel: LSPS1ChannelInfo = serde_json::from_str(json_str).unwrap();

let json_str = r#""CANCELLED""#;
let payment_state: PaymentState = serde_json::from_str(json_str).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions lightning-liquidity/src/lsps1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use super::event::LSPS1ServiceEvent;
use super::msgs::{
ChannelInfo, CreateOrderRequest, CreateOrderResponse, GetInfoResponse, GetOrderRequest,
LSPS1ChannelInfo, CreateOrderRequest, CreateOrderResponse, GetInfoResponse, GetOrderRequest,
LSPS1Message, LSPS1Options, LSPS1Request, LSPS1Response, OrderId, OrderParameters, OrderState,
PaymentInfo, LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
};
Expand Down Expand Up @@ -364,7 +364,7 @@ where
/// [`LSPS1ServiceEvent::CheckPaymentConfirmation`]: crate::lsps1::event::LSPS1ServiceEvent::CheckPaymentConfirmation
pub fn update_order_status(
&self, request_id: RequestId, counterparty_node_id: PublicKey, order_id: OrderId,
order_state: OrderState, channel: Option<ChannelInfo>,
order_state: OrderState, channel: Option<LSPS1ChannelInfo>,
) -> Result<(), APIError> {
let (result, response) = {
let outer_state_lock = self.per_peer_state.read().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions lightning-liquidity/src/lsps2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! Contains the main LSPS2 client object, [`LSPS2ClientHandler`].

use crate::events::{Event, EventQueue};
use crate::events::{LSPSEvent, EventQueue};
use crate::lsps0::ser::{ProtocolMessageHandler, RequestId, ResponseError};
use crate::lsps2::event::LSPS2ClientEvent;
use crate::message_queue::MessageQueue;
Expand All @@ -26,7 +26,7 @@ use core::default::Default;
use core::ops::Deref;

use crate::lsps2::msgs::{
BuyRequest, BuyResponse, GetInfoRequest, GetInfoResponse, LSPS2Message, LSPS2Request,
BuyRequest, BuyResponse, LSPS2GetInfoRequest, LSPS2GetInfoResponse, LSPS2Message, LSPS2Request,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above: let's rename the world.

LSPS2Response, OpeningFeeParams,
};

Expand Down Expand Up @@ -122,7 +122,7 @@ where
peer_state_lock.pending_get_info_requests.insert(request_id.clone());
}

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

Expand Down Expand Up @@ -181,7 +181,7 @@ where
}

fn handle_get_info_response(
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: GetInfoResponse,
&self, request_id: RequestId, counterparty_node_id: &PublicKey, result: LSPS2GetInfoResponse,
) -> Result<(), LightningError> {
let outer_state_lock = self.per_peer_state.read().unwrap();
match outer_state_lock.get(counterparty_node_id) {
Expand All @@ -198,7 +198,7 @@ where
});
}

self.pending_events.enqueue(Event::LSPS2Client(
self.pending_events.enqueue(LSPSEvent::LSPS2Client(
LSPS2ClientEvent::OpeningParametersReady {
request_id,
counterparty_node_id: *counterparty_node_id,
Expand Down Expand Up @@ -264,7 +264,7 @@ where
})?;

if let Ok(intercept_scid) = result.jit_channel_scid.to_scid() {
self.pending_events.enqueue(Event::LSPS2Client(
self.pending_events.enqueue(LSPSEvent::LSPS2Client(
LSPS2ClientEvent::InvoiceParametersReady {
request_id,
counterparty_node_id: *counterparty_node_id,
Expand Down
Loading
Loading