@@ -41,6 +41,8 @@ use crate::jit_channel::msgs::{
41
41
LSPS2_BUY_REQUEST_INVALID_VERSION_ERROR_CODE ,
42
42
LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_LARGE_ERROR_CODE ,
43
43
LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_SMALL_ERROR_CODE ,
44
+ LSPS2_GET_INFO_REQUEST_INVALID_VERSION_ERROR_CODE ,
45
+ LSPS2_GET_INFO_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
44
46
} ;
45
47
46
48
const SUPPORTED_SPEC_VERSIONS : [ u16 ; 1 ] = [ 1 ] ;
@@ -516,6 +518,39 @@ where
516
518
}
517
519
}
518
520
521
+ pub fn invalid_token_provided (
522
+ & self , counterparty_node_id : PublicKey , request_id : RequestId ,
523
+ ) -> Result < ( ) , APIError > {
524
+ let outer_state_lock = self . per_peer_state . read ( ) . unwrap ( ) ;
525
+
526
+ match outer_state_lock. get ( & counterparty_node_id) {
527
+ Some ( inner_state_lock) => {
528
+ let mut peer_state = inner_state_lock. lock ( ) . unwrap ( ) ;
529
+
530
+ match peer_state. pending_requests . remove ( & request_id) {
531
+ Some ( LSPS2Request :: GetInfo ( _) ) => {
532
+ let response = LSPS2Response :: GetInfoError ( ResponseError {
533
+ code : LSPS2_GET_INFO_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
534
+ message : "an unrecognized or stale token was provided" . to_string ( ) ,
535
+ data : None ,
536
+ } ) ;
537
+ self . enqueue_response ( counterparty_node_id, request_id, response) ;
538
+ Ok ( ( ) )
539
+ }
540
+ _ => Err ( APIError :: APIMisuseError {
541
+ err : format ! (
542
+ "No pending get_info request for request_id: {:?}" ,
543
+ request_id
544
+ ) ,
545
+ } ) ,
546
+ }
547
+ }
548
+ None => Err ( APIError :: APIMisuseError {
549
+ err : format ! ( "No state for the counterparty exists: {:?}" , counterparty_node_id) ,
550
+ } ) ,
551
+ }
552
+ }
553
+
519
554
pub fn opening_fee_params_generated (
520
555
& self , counterparty_node_id : PublicKey , request_id : RequestId ,
521
556
opening_fee_params_menu : Vec < RawOpeningFeeParams > ,
@@ -875,6 +910,22 @@ where
875
910
fn handle_get_info_request (
876
911
& self , request_id : RequestId , counterparty_node_id : & PublicKey , params : GetInfoRequest ,
877
912
) -> Result < ( ) , LightningError > {
913
+ if !SUPPORTED_SPEC_VERSIONS . contains ( & params. version ) {
914
+ self . enqueue_response (
915
+ * counterparty_node_id,
916
+ request_id,
917
+ LSPS2Response :: GetInfoError ( ResponseError {
918
+ code : LSPS2_GET_INFO_REQUEST_INVALID_VERSION_ERROR_CODE ,
919
+ message : format ! ( "version {} is not supported" , params. version) ,
920
+ data : Some ( format ! ( "Supported versions are {:?}" , SUPPORTED_SPEC_VERSIONS ) ) ,
921
+ } ) ,
922
+ ) ;
923
+ return Err ( LightningError {
924
+ err : format ! ( "client requested unsupported version {}" , params. version) ,
925
+ action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
926
+ } ) ;
927
+ }
928
+
878
929
let mut outer_state_lock = self . per_peer_state . write ( ) . unwrap ( ) ;
879
930
let inner_state_lock: & mut Mutex < PeerState > = outer_state_lock
880
931
. entry ( * counterparty_node_id)
0 commit comments