Skip to content

Commit 1febb34

Browse files
LSPS1: Service refactor - Part 1.
- Remove dead / unnecesary functions, dependencies, etc. - Add the first LSPS1 integration test. There are no breaking API changes, ldk-node should function as usual
1 parent 3ff0350 commit 1febb34

File tree

3 files changed

+261
-41
lines changed

3 files changed

+261
-41
lines changed

lightning-liquidity/src/lsps1/service.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ use crate::prelude::{new_hash_map, HashMap};
3030
use crate::sync::{Arc, Mutex, RwLock};
3131
use crate::utils;
3232

33-
use lightning::chain::Filter;
34-
use lightning::ln::channelmanager::AChannelManager;
3533
use lightning::ln::msgs::{ErrorAction, LightningError};
3634
use lightning::sign::EntropySource;
3735
use lightning::util::errors::APIError;
3836
use lightning::util::logger::Level;
3937

4038
use bitcoin::secp256k1::PublicKey;
4139

42-
use chrono::Utc;
43-
4440
/// Server-side configuration options for bLIP-51 / LSPS1 channel requests.
4541
#[derive(Clone, Debug)]
4642
pub struct LSPS1ServiceConfig {
@@ -62,7 +58,6 @@ impl From<ChannelStateError> for LightningError {
6258
enum OutboundRequestState {
6359
OrderCreated { order_id: LSPS1OrderId },
6460
WaitingPayment { order_id: LSPS1OrderId },
65-
Ready,
6661
}
6762

6863
impl OutboundRequestState {
@@ -101,67 +96,43 @@ impl OutboundCRChannel {
10196
self.state = self.state.awaiting_payment()?;
10297
Ok(())
10398
}
104-
105-
fn check_order_validity(&self, supported_options: &LSPS1Options) -> bool {
106-
let order = &self.config.order;
107-
108-
is_valid(order, supported_options)
109-
}
11099
}
111100

112101
#[derive(Default)]
113102
struct PeerState {
114103
outbound_channels_by_order_id: HashMap<LSPS1OrderId, OutboundCRChannel>,
115-
request_to_cid: HashMap<LSPSRequestId, u128>,
116104
pending_requests: HashMap<LSPSRequestId, LSPS1Request>,
117105
}
118106

119107
impl PeerState {
120108
fn insert_outbound_channel(&mut self, order_id: LSPS1OrderId, channel: OutboundCRChannel) {
121109
self.outbound_channels_by_order_id.insert(order_id, channel);
122110
}
123-
124-
fn insert_request(&mut self, request_id: LSPSRequestId, channel_id: u128) {
125-
self.request_to_cid.insert(request_id, channel_id);
126-
}
127-
128-
fn remove_outbound_channel(&mut self, order_id: LSPS1OrderId) {
129-
self.outbound_channels_by_order_id.remove(&order_id);
130-
}
131111
}
132112

133113
/// The main object allowing to send and receive bLIP-51 / LSPS1 messages.
134-
pub struct LSPS1ServiceHandler<ES: Deref, CM: Deref + Clone, C: Deref>
114+
pub struct LSPS1ServiceHandler<ES: Deref>
135115
where
136116
ES::Target: EntropySource,
137-
CM::Target: AChannelManager,
138-
C::Target: Filter,
139117
{
140118
entropy_source: ES,
141-
channel_manager: CM,
142-
chain_source: Option<C>,
143119
pending_messages: Arc<MessageQueue>,
144120
pending_events: Arc<EventQueue>,
145121
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
146122
config: LSPS1ServiceConfig,
147123
}
148124

149-
impl<ES: Deref, CM: Deref + Clone, C: Deref> LSPS1ServiceHandler<ES, CM, C>
125+
impl<ES: Deref> LSPS1ServiceHandler<ES>
150126
where
151127
ES::Target: EntropySource,
152-
CM::Target: AChannelManager,
153-
C::Target: Filter,
154-
ES::Target: EntropySource,
155128
{
156129
/// Constructs a `LSPS1ServiceHandler`.
157130
pub(crate) fn new(
158131
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
159-
channel_manager: CM, chain_source: Option<C>, config: LSPS1ServiceConfig,
132+
config: LSPS1ServiceConfig,
160133
) -> Self {
161134
Self {
162135
entropy_source,
163-
channel_manager,
164-
chain_source,
165136
pending_messages,
166137
pending_events,
167138
per_peer_state: RwLock::new(new_hash_map()),
@@ -432,12 +403,9 @@ where
432403
}
433404
}
434405

435-
impl<ES: Deref, CM: Deref + Clone, C: Deref> LSPSProtocolMessageHandler
436-
for LSPS1ServiceHandler<ES, CM, C>
406+
impl<ES: Deref> LSPSProtocolMessageHandler for LSPS1ServiceHandler<ES>
437407
where
438408
ES::Target: EntropySource,
439-
CM::Target: AChannelManager,
440-
C::Target: Filter,
441409
{
442410
type ProtocolMessage = LSPS1Message;
443411
const PROTOCOL_NUMBER: Option<u16> = Some(1);

lightning-liquidity/src/manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ where
140140
lsps0_client_handler: LSPS0ClientHandler<ES>,
141141
lsps0_service_handler: Option<LSPS0ServiceHandler>,
142142
#[cfg(lsps1_service)]
143-
lsps1_service_handler: Option<LSPS1ServiceHandler<ES, CM, C>>,
143+
lsps1_service_handler: Option<LSPS1ServiceHandler<ES>>,
144144
lsps1_client_handler: Option<LSPS1ClientHandler<ES>>,
145145
lsps2_service_handler: Option<LSPS2ServiceHandler<CM>>,
146146
lsps2_client_handler: Option<LSPS2ClientHandler<ES>>,
@@ -212,7 +212,7 @@ where {
212212
#[cfg(lsps1_service)]
213213
let lsps1_service_handler = service_config.as_ref().and_then(|config| {
214214
if let Some(number) =
215-
<LSPS1ServiceHandler<ES, CM, C> as LSPSProtocolMessageHandler>::PROTOCOL_NUMBER
215+
<LSPS1ServiceHandler<ES> as LSPSProtocolMessageHandler>::PROTOCOL_NUMBER
216216
{
217217
supported_protocols.push(number);
218218
}
@@ -221,8 +221,6 @@ where {
221221
entropy_source.clone(),
222222
Arc::clone(&pending_messages),
223223
Arc::clone(&pending_events),
224-
channel_manager.clone(),
225-
chain_source.clone(),
226224
config.clone(),
227225
)
228226
})
@@ -279,7 +277,7 @@ where {
279277

280278
/// Returns a reference to the LSPS1 server-side handler.
281279
#[cfg(lsps1_service)]
282-
pub fn lsps1_service_handler(&self) -> Option<&LSPS1ServiceHandler<ES, CM, C>> {
280+
pub fn lsps1_service_handler(&self) -> Option<&LSPS1ServiceHandler<ES>> {
283281
self.lsps1_service_handler.as_ref()
284282
}
285283

0 commit comments

Comments
 (0)