1
- // This file is Copyright its original authors, visible in version contror
1
+ // This file is Copyright its original authors, visible in version control
2
2
// history.
3
3
//
4
4
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
@@ -35,8 +35,6 @@ use bitcoin::secp256k1::PublicKey;
35
35
36
36
use core:: ops:: Deref ;
37
37
38
- const SUPPORTED_SPEC_VERSIONS : [ u16 ; 1 ] = [ 1 ] ;
39
-
40
38
/// Client-side configuration options for LSPS1 channel requests.
41
39
#[ derive( Clone , Debug ) ]
42
40
pub struct LSPS1ClientConfig {
@@ -55,43 +53,30 @@ impl From<ChannelStateError> for LightningError {
55
53
#[ derive( PartialEq , Debug ) ]
56
54
enum InboundRequestState {
57
55
InfoRequested ,
58
- OptionsSupport { version : u16 , options_supported : OptionsSupported } ,
59
- OrderRequested { version : u16 , order : OrderParams } ,
56
+ OptionsSupport { options_supported : OptionsSupported } ,
57
+ OrderRequested { order : OrderParams } ,
60
58
PendingPayment { order_id : OrderId } ,
61
59
AwaitingConfirmation { id : u128 , order_id : OrderId } ,
62
60
}
63
61
64
62
impl InboundRequestState {
65
- fn info_received (
66
- & self , versions : Vec < u16 > , options : OptionsSupported ,
67
- ) -> Result < Self , ChannelStateError > {
68
- let max_shared_version = versions
69
- . iter ( )
70
- . filter ( |version| SUPPORTED_SPEC_VERSIONS . contains ( version) )
71
- . max ( )
72
- . cloned ( )
73
- . ok_or ( ChannelStateError ( format ! (
74
- "LSP does not support any of our specification versions. ours = {:?}. theirs = {:?}" ,
75
- SUPPORTED_SPEC_VERSIONS , versions
76
- ) ) ) ?;
77
-
63
+ fn info_received ( & self , options : OptionsSupported ) -> Result < Self , ChannelStateError > {
78
64
match self {
79
- InboundRequestState :: InfoRequested => Ok ( InboundRequestState :: OptionsSupport {
80
- version : max_shared_version,
81
- options_supported : options,
82
- } ) ,
65
+ InboundRequestState :: InfoRequested => {
66
+ Ok ( InboundRequestState :: OptionsSupport { options_supported : options } )
67
+ }
83
68
state => Err ( ChannelStateError ( format ! (
84
- "Received unexpected get_versions response. Channel was in state: {:?}" ,
69
+ "Received unexpected get_info response. Channel was in state: {:?}" ,
85
70
state
86
71
) ) ) ,
87
72
}
88
73
}
89
74
90
75
fn order_requested ( & self , order : OrderParams ) -> Result < Self , ChannelStateError > {
91
76
match self {
92
- InboundRequestState :: OptionsSupport { version , options_supported } => {
77
+ InboundRequestState :: OptionsSupport { options_supported } => {
93
78
if is_valid ( & order, options_supported) {
94
- Ok ( InboundRequestState :: OrderRequested { version : * version , order } )
79
+ Ok ( InboundRequestState :: OrderRequested { order } )
95
80
} else {
96
81
return Err ( ChannelStateError ( format ! (
97
82
"The order created does not match options supported by LSP. Options Supported by LSP are {:?}. The order created was {:?}" ,
@@ -110,7 +95,7 @@ impl InboundRequestState {
110
95
& self , response_order : & OrderParams , order_id : OrderId ,
111
96
) -> Result < Self , ChannelStateError > {
112
97
match self {
113
- InboundRequestState :: OrderRequested { version , order } => {
98
+ InboundRequestState :: OrderRequested { order } => {
114
99
if response_order == order {
115
100
Ok ( InboundRequestState :: PendingPayment { order_id } )
116
101
} else {
@@ -153,25 +138,23 @@ impl InboundCRChannel {
153
138
Self { id, state : InboundRequestState :: InfoRequested }
154
139
}
155
140
156
- fn info_received (
157
- & mut self , versions : Vec < u16 > , options : OptionsSupported ,
158
- ) -> Result < u16 , LightningError > {
159
- self . state = self . state . info_received ( versions, options) ?;
141
+ fn info_received ( & mut self , options : OptionsSupported ) -> Result < ( ) , LightningError > {
142
+ self . state = self . state . info_received ( options) ?;
160
143
161
144
match self . state {
162
- InboundRequestState :: OptionsSupport { version , .. } => Ok ( version ) ,
145
+ InboundRequestState :: OptionsSupport { .. } => Ok ( ( ) ) ,
163
146
_ => Err ( LightningError {
164
147
action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
165
148
err : "impossible state transition" . to_string ( ) ,
166
149
} ) ,
167
150
}
168
151
}
169
152
170
- fn order_requested ( & mut self , order : OrderParams ) -> Result < u16 , LightningError > {
153
+ fn order_requested ( & mut self , order : OrderParams ) -> Result < ( ) , LightningError > {
171
154
self . state = self . state . order_requested ( order) ?;
172
155
173
156
match self . state {
174
- InboundRequestState :: OrderRequested { version , .. } => Ok ( version ) ,
157
+ InboundRequestState :: OrderRequested { .. } => Ok ( ( ) ) ,
175
158
_ => {
176
159
return Err ( LightningError {
177
160
action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
@@ -301,10 +284,8 @@ where
301
284
action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
302
285
} ) ?;
303
286
304
- let version = match inbound_channel
305
- . info_received ( result. supported_versions , result. options . clone ( ) )
306
- {
307
- Ok ( version) => version,
287
+ match inbound_channel. info_received ( result. options . clone ( ) ) {
288
+ Ok ( ( ) ) => ( ) ,
308
289
Err ( e) => {
309
290
peer_state_lock. remove_inbound_channel ( channel_id) ;
310
291
return Err ( e) ;
@@ -315,7 +296,6 @@ where
315
296
id : channel_id,
316
297
request_id,
317
298
counterparty_node_id : * counterparty_node_id,
318
- version,
319
299
website : result. website ,
320
300
options_supported : result. options ,
321
301
} ) )
@@ -349,8 +329,8 @@ where
349
329
err : format ! ( "Channel with id {} not found" , channel_id) ,
350
330
} ) ?;
351
331
352
- let version = match inbound_channel. order_requested ( order. clone ( ) ) {
353
- Ok ( version ) => version ,
332
+ match inbound_channel. order_requested ( order. clone ( ) ) {
333
+ Ok ( ( ) ) => ( ) ,
354
334
Err ( e) => {
355
335
peer_state_lock. remove_inbound_channel ( channel_id) ;
356
336
return Err ( APIError :: APIMisuseError { err : e. err } ) ;
@@ -364,7 +344,7 @@ where
364
344
counterparty_node_id,
365
345
LSPS1Message :: Request (
366
346
request_id,
367
- LSPS1Request :: CreateOrder ( CreateOrderRequest { order, version } ) ,
347
+ LSPS1Request :: CreateOrder ( CreateOrderRequest { order } ) ,
368
348
)
369
349
. into ( ) ,
370
350
) ;
@@ -540,7 +520,7 @@ where
540
520
let channel_id =
541
521
peer_state_lock. request_to_cid . remove ( & request_id) . ok_or ( LightningError {
542
522
err : format ! (
543
- "Received get_versions response for an unknown request: {:?}" ,
523
+ "Received get_order response for an unknown request: {:?}" ,
544
524
request_id
545
525
) ,
546
526
action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
@@ -551,7 +531,7 @@ where
551
531
. get_mut ( & channel_id)
552
532
. ok_or ( LightningError {
553
533
err : format ! (
554
- "Received get_versions response for an unknown channel: {:?}" ,
534
+ "Received get_order response for an unknown channel: {:?}" ,
555
535
channel_id
556
536
) ,
557
537
action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
0 commit comments