@@ -20,12 +20,10 @@ use crate::message_queue::MessageQueue;
2020
2121use crate :: events:: { Event , EventQueue } ;
2222use crate :: lsps0:: ser:: { ProtocolMessageHandler , RequestId , ResponseError } ;
23- use crate :: prelude:: { HashMap , String , ToString } ;
23+ use crate :: prelude:: { HashMap , String } ;
2424use crate :: sync:: { Arc , Mutex , RwLock } ;
2525use crate :: utils;
2626
27- use lightning:: chain:: Filter ;
28- use lightning:: ln:: channelmanager:: AChannelManager ;
2927use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
3028use lightning:: sign:: EntropySource ;
3129use lightning:: util:: errors:: APIError ;
@@ -39,8 +37,6 @@ use core::ops::Deref;
3937/// Server-side configuration options for LSPS1 channel requests.
4038#[ derive( Clone , Debug ) ]
4139pub struct LSPS1ServiceConfig {
42- /// A token to be send with each channel request.
43- pub token : Option < String > ,
4440 /// The options supported by the LSP.
4541 pub supported_options : Option < LSPS1Options > ,
4642}
@@ -49,15 +45,14 @@ struct ChannelStateError(String);
4945
5046impl From < ChannelStateError > for LightningError {
5147 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 ) }
5349 }
5450}
5551
5652#[ derive( PartialEq , Debug ) ]
5753enum OutboundRequestState {
5854 OrderCreated { order_id : OrderId } ,
5955 WaitingPayment { order_id : OrderId } ,
60- Ready ,
6156}
6257
6358impl OutboundRequestState {
@@ -96,67 +91,38 @@ impl OutboundCRChannel {
9691 self . state = self . state . awaiting_payment ( ) ?;
9792 Ok ( ( ) )
9893 }
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- }
10594}
10695
10796#[ derive( Default ) ]
10897struct PeerState {
10998 outbound_channels_by_order_id : HashMap < OrderId , OutboundCRChannel > ,
110- request_to_cid : HashMap < RequestId , u128 > ,
11199 pending_requests : HashMap < RequestId , LSPS1Request > ,
112100}
113101
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-
128102/// 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 >
130104where
131105 ES :: Target : EntropySource ,
132- CM :: Target : AChannelManager ,
133- C :: Target : Filter ,
134106{
135107 entropy_source : ES ,
136- channel_manager : CM ,
137- chain_source : Option < C > ,
138108 pending_messages : Arc < MessageQueue > ,
139109 pending_events : Arc < EventQueue > ,
140110 per_peer_state : RwLock < HashMap < PublicKey , Mutex < PeerState > > > ,
141111 config : LSPS1ServiceConfig ,
142112}
143113
144- impl < ES : Deref , CM : Deref + Clone , C : Deref > LSPS1ServiceHandler < ES , CM , C >
114+ impl < ES : Deref > LSPS1ServiceHandler < ES >
145115where
146116 ES :: Target : EntropySource ,
147- CM :: Target : AChannelManager ,
148- C :: Target : Filter ,
149117 ES :: Target : EntropySource ,
150118{
151119 /// Constructs a `LSPS1ServiceHandler`.
152120 pub ( crate ) fn new (
153121 entropy_source : ES , pending_messages : Arc < MessageQueue > , pending_events : Arc < EventQueue > ,
154- channel_manager : CM , chain_source : Option < C > , config : LSPS1ServiceConfig ,
122+ config : LSPS1ServiceConfig ,
155123 ) -> Self {
156124 Self {
157125 entropy_source,
158- channel_manager,
159- chain_source,
160126 pending_messages,
161127 pending_events,
162128 per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
@@ -174,7 +140,7 @@ where
174140 . clone ( )
175141 . ok_or ( LightningError {
176142 err : format ! ( "Configuration for LSP server not set." ) ,
177- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
143+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
178144 } )
179145 . unwrap ( ) ,
180146 } ) ;
@@ -203,7 +169,7 @@ where
203169 "Client order does not match any supported options: {:?}" ,
204170 params. order
205171 ) ,
206- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
172+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
207173 } ) ;
208174 }
209175
@@ -257,7 +223,9 @@ where
257223 payment. clone ( ) ,
258224 ) ;
259225
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) ;
261229
262230 let response = LSPS1Response :: CreateOrder ( CreateOrderResponse {
263231 order : params. order ,
@@ -318,7 +286,7 @@ where
318286 "Received get order request for unknown order id {:?}" ,
319287 params. order_id
320288 ) ,
321- action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
289+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
322290 } ) ?;
323291
324292 if let Err ( e) = outbound_channel. awaiting_payment ( ) {
@@ -345,8 +313,11 @@ where
345313 } ,
346314 None => {
347315 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 ) ,
350321 } ) ;
351322 } ,
352323 }
@@ -422,12 +393,9 @@ where
422393 }
423394}
424395
425- impl < ES : Deref , CM : Deref + Clone , C : Deref > ProtocolMessageHandler
426- for LSPS1ServiceHandler < ES , CM , C >
396+ impl < ES : Deref > ProtocolMessageHandler for LSPS1ServiceHandler < ES >
427397where
428398 ES :: Target : EntropySource ,
429- CM :: Target : AChannelManager ,
430- C :: Target : Filter ,
431399{
432400 type ProtocolMessage = LSPS1Message ;
433401 const PROTOCOL_NUMBER : Option < u16 > = Some ( 1 ) ;
@@ -452,7 +420,13 @@ where
452420 false ,
453421 "Service handler received LSPS1 response message. This should never happen."
454422 ) ;
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+ } )
456430 } ,
457431 }
458432 }
0 commit comments