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

Commit 3830611

Browse files
committed
Drop MessageQueue trait and rename DefaultMessageQueue
We previously introduced the `MessageQueue` trait in order to be able to move the `APeerManager` dependency to a single (optional) place. As we now got rid of the type dependency, we may as well drop this intermediary step again, as there is likely no immediate benefit in allowing users to implement their own custom message queues. However, removing the type parameter further cleans up our types and reduces overall complexity.
1 parent 2a9c244 commit 3830611

File tree

9 files changed

+54
-130
lines changed

9 files changed

+54
-130
lines changed

src/lsps0/client.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,22 @@ use bitcoin::secp256k1::PublicKey;
2323
use core::ops::Deref;
2424

2525
/// A message handler capable of sending and handling LSPS0 messages.
26-
pub struct LSPS0ClientHandler<ES: Deref, MQ: Deref>
26+
pub struct LSPS0ClientHandler<ES: Deref>
2727
where
2828
ES::Target: EntropySource,
29-
MQ::Target: MessageQueue,
3029
{
3130
entropy_source: ES,
32-
pending_messages: MQ,
31+
pending_messages: Arc<MessageQueue>,
3332
pending_events: Arc<EventQueue>,
3433
}
3534

36-
impl<ES: Deref, MQ: Deref> LSPS0ClientHandler<ES, MQ>
35+
impl<ES: Deref> LSPS0ClientHandler<ES>
3736
where
3837
ES::Target: EntropySource,
39-
MQ::Target: MessageQueue,
4038
{
4139
/// Returns a new instance of [`LSPS0ClientHandler`].
4240
pub(crate) fn new(
43-
entropy_source: ES, pending_messages: MQ, pending_events: Arc<EventQueue>,
41+
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
4442
) -> Self {
4543
Self { entropy_source, pending_messages, pending_events }
4644
}
@@ -85,10 +83,9 @@ where
8583
}
8684
}
8785

88-
impl<ES: Deref, MQ: Deref> ProtocolMessageHandler for LSPS0ClientHandler<ES, MQ>
86+
impl<ES: Deref> ProtocolMessageHandler for LSPS0ClientHandler<ES>
8987
where
9088
ES::Target: EntropySource,
91-
MQ::Target: MessageQueue,
9289
{
9390
type ProtocolMessage = LSPS0Message;
9491
const PROTOCOL_NUMBER: Option<u16> = None;
@@ -118,13 +115,13 @@ mod tests {
118115
use alloc::sync::Arc;
119116

120117
use crate::lsps0::msgs::{LSPSMessage, RequestId};
121-
use crate::tests::utils::{TestEntropy, TestMessageQueue};
118+
use crate::tests::utils::TestEntropy;
122119

123120
use super::*;
124121

125122
#[test]
126123
fn test_list_protocols() {
127-
let pending_messages = Arc::new(TestMessageQueue::new());
124+
let pending_messages = Arc::new(MessageQueue::new());
128125
let entropy_source = Arc::new(TestEntropy {});
129126
let event_queue = Arc::new(EventQueue::new());
130127

src/lsps0/service.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,22 @@ use crate::lsps0::msgs::{
1919
};
2020
use crate::message_queue::MessageQueue;
2121
use crate::prelude::Vec;
22+
use crate::sync::Arc;
2223

2324
use lightning::ln::msgs::{ErrorAction, LightningError};
2425
use lightning::util::logger::Level;
2526

2627
use bitcoin::secp256k1::PublicKey;
2728

28-
use core::ops::Deref;
29-
3029
/// The main server-side object allowing to send and receive LSPS0 messages.
31-
pub struct LSPS0ServiceHandler<MQ: Deref>
32-
where
33-
MQ::Target: MessageQueue,
34-
{
35-
pending_messages: MQ,
30+
pub struct LSPS0ServiceHandler {
31+
pending_messages: Arc<MessageQueue>,
3632
protocols: Vec<u16>,
3733
}
3834

39-
impl<MQ: Deref> LSPS0ServiceHandler<MQ>
40-
where
41-
MQ::Target: MessageQueue,
42-
{
35+
impl LSPS0ServiceHandler {
4336
/// Returns a new instance of [`LSPS0ServiceHandler`].
44-
pub(crate) fn new(protocols: Vec<u16>, pending_messages: MQ) -> Self {
37+
pub(crate) fn new(protocols: Vec<u16>, pending_messages: Arc<MessageQueue>) -> Self {
4538
Self { protocols, pending_messages }
4639
}
4740

@@ -63,10 +56,7 @@ where
6356
}
6457
}
6558

66-
impl<MQ: Deref> ProtocolMessageHandler for LSPS0ServiceHandler<MQ>
67-
where
68-
MQ::Target: MessageQueue,
69-
{
59+
impl ProtocolMessageHandler for LSPS0ServiceHandler {
7060
type ProtocolMessage = LSPS0Message;
7161
const PROTOCOL_NUMBER: Option<u16> = None;
7262

@@ -92,7 +82,6 @@ where
9282
mod tests {
9383

9484
use crate::lsps0::msgs::{LSPSMessage, ListProtocolsRequest};
95-
use crate::tests::utils::TestMessageQueue;
9685
use crate::utils;
9786
use alloc::string::ToString;
9887
use alloc::sync::Arc;
@@ -102,7 +91,7 @@ mod tests {
10291
#[test]
10392
fn test_handle_list_protocols_request() {
10493
let protocols: Vec<u16> = vec![];
105-
let pending_messages = Arc::new(TestMessageQueue::new());
94+
let pending_messages = Arc::new(MessageQueue::new());
10695

10796
let lsps0_handler = Arc::new(LSPS0ServiceHandler::new(protocols, pending_messages.clone()));
10897

src/lsps1/client.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,32 +216,30 @@ impl PeerState {
216216
}
217217

218218
/// The main object allowing to send and receive LSPS1 messages.
219-
pub struct LSPS1ClientHandler<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref>
219+
pub struct LSPS1ClientHandler<ES: Deref, CM: Deref + Clone, C: Deref>
220220
where
221221
ES::Target: EntropySource,
222222
CM::Target: AChannelManager,
223-
MQ::Target: MessageQueue,
224223
C::Target: Filter,
225224
{
226225
entropy_source: ES,
227226
channel_manager: CM,
228227
chain_source: Option<C>,
229-
pending_messages: MQ,
228+
pending_messages: Arc<MessageQueue>,
230229
pending_events: Arc<EventQueue>,
231230
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
232231
config: LSPS1ClientConfig,
233232
}
234233

235-
impl<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref> LSPS1ClientHandler<ES, CM, MQ, C>
234+
impl<ES: Deref, CM: Deref + Clone, C: Deref> LSPS1ClientHandler<ES, CM, C>
236235
where
237236
ES::Target: EntropySource,
238237
CM::Target: AChannelManager,
239-
MQ::Target: MessageQueue,
240238
C::Target: Filter,
241239
ES::Target: EntropySource,
242240
{
243241
pub(crate) fn new(
244-
entropy_source: ES, pending_messages: MQ, pending_events: Arc<EventQueue>,
242+
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
245243
channel_manager: CM, chain_source: Option<C>, config: LSPS1ClientConfig,
246244
) -> Self {
247245
Self {
@@ -609,12 +607,11 @@ where
609607
}
610608
}
611609

612-
impl<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref> ProtocolMessageHandler
613-
for LSPS1ClientHandler<ES, CM, MQ, C>
610+
impl<ES: Deref, CM: Deref + Clone, C: Deref> ProtocolMessageHandler
611+
for LSPS1ClientHandler<ES, CM, C>
614612
where
615613
ES::Target: EntropySource,
616614
CM::Target: AChannelManager,
617-
MQ::Target: MessageQueue,
618615
C::Target: Filter,
619616
{
620617
type ProtocolMessage = LSPS1Message;

src/lsps1/service.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,30 @@ impl PeerState {
136136
}
137137

138138
/// The main object allowing to send and receive LSPS1 messages.
139-
pub struct LSPS1ServiceHandler<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref>
139+
pub struct LSPS1ServiceHandler<ES: Deref, CM: Deref + Clone, C: Deref>
140140
where
141141
ES::Target: EntropySource,
142142
CM::Target: AChannelManager,
143-
MQ::Target: MessageQueue,
144143
C::Target: Filter,
145144
{
146145
entropy_source: ES,
147146
channel_manager: CM,
148147
chain_source: Option<C>,
149-
pending_messages: MQ,
148+
pending_messages: Arc<MessageQueue>,
150149
pending_events: Arc<EventQueue>,
151150
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
152151
config: LSPS1ServiceConfig,
153152
}
154153

155-
impl<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref> LSPS1ServiceHandler<ES, CM, MQ, C>
154+
impl<ES: Deref, CM: Deref + Clone, C: Deref> LSPS1ServiceHandler<ES, CM, C>
156155
where
157156
ES::Target: EntropySource,
158157
CM::Target: AChannelManager,
159-
MQ::Target: MessageQueue,
160158
C::Target: Filter,
161159
ES::Target: EntropySource,
162160
{
163161
pub(crate) fn new(
164-
entropy_source: ES, pending_messages: MQ, pending_events: Arc<EventQueue>,
162+
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
165163
channel_manager: CM, chain_source: Option<C>, config: LSPS1ServiceConfig,
166164
) -> Self {
167165
Self {
@@ -422,12 +420,11 @@ where
422420
}
423421
}
424422

425-
impl<ES: Deref, CM: Deref + Clone, MQ: Deref, C: Deref> ProtocolMessageHandler
426-
for LSPS1ServiceHandler<ES, CM, MQ, C>
423+
impl<ES: Deref, CM: Deref + Clone, C: Deref> ProtocolMessageHandler
424+
for LSPS1ServiceHandler<ES, CM, C>
427425
where
428426
ES::Target: EntropySource,
429427
CM::Target: AChannelManager,
430-
MQ::Target: MessageQueue,
431428
C::Target: Filter,
432429
{
433430
type ProtocolMessage = LSPS1Message;

src/lsps2/client.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,24 @@ impl PeerState {
200200
}
201201

202202
/// The main object allowing to send and receive LSPS2 messages.
203-
pub struct LSPS2ClientHandler<ES: Deref, MQ: Deref>
203+
pub struct LSPS2ClientHandler<ES: Deref>
204204
where
205205
ES::Target: EntropySource,
206-
MQ::Target: MessageQueue,
207206
{
208207
entropy_source: ES,
209-
pending_messages: MQ,
208+
pending_messages: Arc<MessageQueue>,
210209
pending_events: Arc<EventQueue>,
211210
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
212211
_config: LSPS2ClientConfig,
213212
}
214213

215-
impl<ES: Deref, MQ: Deref> LSPS2ClientHandler<ES, MQ>
214+
impl<ES: Deref> LSPS2ClientHandler<ES>
216215
where
217216
ES::Target: EntropySource,
218-
MQ::Target: MessageQueue,
219217
{
220218
/// Constructs an `LSPS2ClientHandler`.
221219
pub(crate) fn new(
222-
entropy_source: ES, pending_messages: MQ, pending_events: Arc<EventQueue>,
220+
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
223221
config: LSPS2ClientConfig,
224222
) -> Self {
225223
Self {
@@ -592,10 +590,9 @@ where
592590
}
593591
}
594592

595-
impl<ES: Deref, MQ: Deref> ProtocolMessageHandler for LSPS2ClientHandler<ES, MQ>
593+
impl<ES: Deref> ProtocolMessageHandler for LSPS2ClientHandler<ES>
596594
where
597595
ES::Target: EntropySource,
598-
MQ::Target: MessageQueue,
599596
{
600597
type ProtocolMessage = LSPS2Message;
601598
const PROTOCOL_NUMBER: Option<u16> = Some(2);

src/lsps2/service.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,27 +260,25 @@ impl PeerState {
260260
}
261261

262262
/// The main object allowing to send and receive LSPS2 messages.
263-
pub struct LSPS2ServiceHandler<CM: Deref + Clone, MQ: Deref>
263+
pub struct LSPS2ServiceHandler<CM: Deref + Clone>
264264
where
265265
CM::Target: AChannelManager,
266-
MQ::Target: MessageQueue,
267266
{
268267
channel_manager: CM,
269-
pending_messages: MQ,
268+
pending_messages: Arc<MessageQueue>,
270269
pending_events: Arc<EventQueue>,
271270
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
272271
peer_by_scid: RwLock<HashMap<u64, PublicKey>>,
273272
config: LSPS2ServiceConfig,
274273
}
275274

276-
impl<CM: Deref + Clone, MQ: Deref> LSPS2ServiceHandler<CM, MQ>
275+
impl<CM: Deref + Clone> LSPS2ServiceHandler<CM>
277276
where
278277
CM::Target: AChannelManager,
279-
MQ::Target: MessageQueue,
280278
{
281279
/// Constructs a `LSPS2ServiceHandler`.
282280
pub(crate) fn new(
283-
pending_messages: MQ, pending_events: Arc<EventQueue>, channel_manager: CM,
281+
pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>, channel_manager: CM,
284282
config: LSPS2ServiceConfig,
285283
) -> Self {
286284
Self {
@@ -742,10 +740,9 @@ where
742740
}
743741
}
744742

745-
impl<CM: Deref + Clone, MQ: Deref> ProtocolMessageHandler for LSPS2ServiceHandler<CM, MQ>
743+
impl<CM: Deref + Clone> ProtocolMessageHandler for LSPS2ServiceHandler<CM>
746744
where
747745
CM::Target: AChannelManager,
748-
MQ::Target: MessageQueue,
749746
{
750747
type ProtocolMessage = LSPS2Message;
751748
const PROTOCOL_NUMBER: Option<u16> = Some(2);

0 commit comments

Comments
 (0)