@@ -20,12 +20,10 @@ use crate::message_queue::MessageQueue;
20
20
21
21
use crate :: events:: { Event , EventQueue } ;
22
22
use crate :: lsps0:: ser:: { ProtocolMessageHandler , RequestId , ResponseError } ;
23
- use crate :: prelude:: { HashMap , String , ToString } ;
23
+ use crate :: prelude:: { HashMap , String } ;
24
24
use crate :: sync:: { Arc , Mutex , RwLock } ;
25
25
use crate :: utils;
26
26
27
- use lightning:: chain:: Filter ;
28
- use lightning:: ln:: channelmanager:: AChannelManager ;
29
27
use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
30
28
use lightning:: sign:: EntropySource ;
31
29
use lightning:: util:: errors:: APIError ;
@@ -39,8 +37,6 @@ use core::ops::Deref;
39
37
/// Server-side configuration options for LSPS1 channel requests.
40
38
#[ derive( Clone , Debug ) ]
41
39
pub struct LSPS1ServiceConfig {
42
- /// A token to be send with each channel request.
43
- pub token : Option < String > ,
44
40
/// The options supported by the LSP.
45
41
pub supported_options : Option < LSPS1Options > ,
46
42
}
@@ -49,15 +45,14 @@ struct ChannelStateError(String);
49
45
50
46
impl From < ChannelStateError > for LightningError {
51
47
fn from ( value : ChannelStateError ) -> Self {
52
- LightningError { err : value. 0 , action : ErrorAction :: IgnoreAndLog ( Level :: Info ) }
48
+ LightningError { err : value. 0 , action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) }
53
49
}
54
50
}
55
51
56
52
#[ derive( PartialEq , Debug ) ]
57
53
enum OutboundRequestState {
58
54
OrderCreated { order_id : OrderId } ,
59
55
WaitingPayment { order_id : OrderId } ,
60
- Ready ,
61
56
}
62
57
63
58
impl OutboundRequestState {
@@ -96,67 +91,38 @@ impl OutboundCRChannel {
96
91
self . state = self . state . awaiting_payment ( ) ?;
97
92
Ok ( ( ) )
98
93
}
99
-
100
- fn check_order_validity ( & self , supported_options : & LSPS1Options ) -> bool {
101
- let order = & self . config . order ;
102
-
103
- is_valid ( order, supported_options)
104
- }
105
94
}
106
95
107
96
#[ derive( Default ) ]
108
97
struct PeerState {
109
98
outbound_channels_by_order_id : HashMap < OrderId , OutboundCRChannel > ,
110
- request_to_cid : HashMap < RequestId , u128 > ,
111
99
pending_requests : HashMap < RequestId , LSPS1Request > ,
112
100
}
113
101
114
- impl PeerState {
115
- fn insert_outbound_channel ( & mut self , order_id : OrderId , channel : OutboundCRChannel ) {
116
- self . outbound_channels_by_order_id . insert ( order_id, channel) ;
117
- }
118
-
119
- fn insert_request ( & mut self , request_id : RequestId , channel_id : u128 ) {
120
- self . request_to_cid . insert ( request_id, channel_id) ;
121
- }
122
-
123
- fn remove_outbound_channel ( & mut self , order_id : OrderId ) {
124
- self . outbound_channels_by_order_id . remove ( & order_id) ;
125
- }
126
- }
127
-
128
102
/// The main object allowing to send and receive LSPS1 messages.
129
- pub struct LSPS1ServiceHandler < ES : Deref , CM : Deref + Clone , C : Deref >
103
+ pub struct LSPS1ServiceHandler < ES : Deref >
130
104
where
131
105
ES :: Target : EntropySource ,
132
- CM :: Target : AChannelManager ,
133
- C :: Target : Filter ,
134
106
{
135
107
entropy_source : ES ,
136
- channel_manager : CM ,
137
- chain_source : Option < C > ,
138
108
pending_messages : Arc < MessageQueue > ,
139
109
pending_events : Arc < EventQueue > ,
140
110
per_peer_state : RwLock < HashMap < PublicKey , Mutex < PeerState > > > ,
141
111
config : LSPS1ServiceConfig ,
142
112
}
143
113
144
- impl < ES : Deref , CM : Deref + Clone , C : Deref > LSPS1ServiceHandler < ES , CM , C >
114
+ impl < ES : Deref > LSPS1ServiceHandler < ES >
145
115
where
146
116
ES :: Target : EntropySource ,
147
- CM :: Target : AChannelManager ,
148
- C :: Target : Filter ,
149
117
ES :: Target : EntropySource ,
150
118
{
151
119
/// Constructs a `LSPS1ServiceHandler`.
152
120
pub ( crate ) fn new (
153
121
entropy_source : ES , pending_messages : Arc < MessageQueue > , pending_events : Arc < EventQueue > ,
154
- channel_manager : CM , chain_source : Option < C > , config : LSPS1ServiceConfig ,
122
+ config : LSPS1ServiceConfig ,
155
123
) -> Self {
156
124
Self {
157
125
entropy_source,
158
- channel_manager,
159
- chain_source,
160
126
pending_messages,
161
127
pending_events,
162
128
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
@@ -174,7 +140,7 @@ where
174
140
. clone ( )
175
141
. ok_or ( LightningError {
176
142
err : format ! ( "Configuration for LSP server not set." ) ,
177
- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
143
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
178
144
} )
179
145
. unwrap ( ) ,
180
146
} ) ;
@@ -203,7 +169,7 @@ where
203
169
"Client order does not match any supported options: {:?}" ,
204
170
params. order
205
171
) ,
206
- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
172
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
207
173
} ) ;
208
174
}
209
175
@@ -257,7 +223,9 @@ where
257
223
payment. clone ( ) ,
258
224
) ;
259
225
260
- peer_state_lock. insert_outbound_channel ( order_id. clone ( ) , channel) ;
226
+ peer_state_lock
227
+ . outbound_channels_by_order_id
228
+ . insert ( order_id. clone ( ) , channel) ;
261
229
262
230
let response = LSPS1Response :: CreateOrder ( CreateOrderResponse {
263
231
order : params. order ,
@@ -318,7 +286,7 @@ where
318
286
"Received get order request for unknown order id {:?}" ,
319
287
params. order_id
320
288
) ,
321
- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
289
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
322
290
} ) ?;
323
291
324
292
if let Err ( e) = outbound_channel. awaiting_payment ( ) {
@@ -345,8 +313,11 @@ where
345
313
} ,
346
314
None => {
347
315
return Err ( LightningError {
348
- err : format ! ( "Received error response for a create order request from an unknown counterparty ({:?})" , counterparty_node_id) ,
349
- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
316
+ err : format ! (
317
+ "Received error response for a create order request from an unknown counterparty ({:?})" ,
318
+ counterparty_node_id
319
+ ) ,
320
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
350
321
} ) ;
351
322
} ,
352
323
}
@@ -422,12 +393,9 @@ where
422
393
}
423
394
}
424
395
425
- impl < ES : Deref , CM : Deref + Clone , C : Deref > ProtocolMessageHandler
426
- for LSPS1ServiceHandler < ES , CM , C >
396
+ impl < ES : Deref > ProtocolMessageHandler for LSPS1ServiceHandler < ES >
427
397
where
428
398
ES :: Target : EntropySource ,
429
- CM :: Target : AChannelManager ,
430
- C :: Target : Filter ,
431
399
{
432
400
type ProtocolMessage = LSPS1Message ;
433
401
const PROTOCOL_NUMBER : Option < u16 > = Some ( 1 ) ;
@@ -452,7 +420,13 @@ where
452
420
false ,
453
421
"Service handler received LSPS1 response message. This should never happen."
454
422
) ;
455
- Err ( LightningError { err : format ! ( "Service handler received LSPS1 response message from node {:?}. This should never happen." , counterparty_node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Info ) } )
423
+ Err ( LightningError {
424
+ err : format ! (
425
+ "Service handler received LSPS1 response message from node {:?}. This should never happen." ,
426
+ counterparty_node_id
427
+ ) ,
428
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
429
+ } )
456
430
} ,
457
431
}
458
432
}
0 commit comments