@@ -107,8 +107,17 @@ struct ForwardPaymentAction(ChannelId, FeePayment);
107107#[ derive( Debug , PartialEq ) ]
108108struct ForwardHTLCsAction ( ChannelId , Vec < InterceptedHTLC > ) ;
109109
110+ #[ derive( Debug , Copy , Clone , Eq , PartialEq , Ord , PartialOrd ) ]
111+ pub ( crate ) enum OutboundJITStage {
112+ PendingInitialPayment ,
113+ PendingChannelOpen ,
114+ PendingPaymentForward ,
115+ PendingPayment ,
116+ PaymentForwarded ,
117+ }
118+
110119/// The different states a requested JIT channel can be in.
111- #[ derive( Clone , Debug , PartialEq , Eq ) ]
120+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
112121pub ( crate ) enum OutboundJITChannelState {
113122 /// The JIT channel SCID was created after a buy request, and we are awaiting an initial payment
114123 /// of sufficient size to open the channel.
@@ -135,13 +144,19 @@ pub(crate) enum OutboundJITChannelState {
135144}
136145
137146impl OutboundJITChannelState {
138- fn ord_index ( & self ) -> u8 {
147+ pub ( crate ) fn stage ( & self ) -> OutboundJITStage {
139148 match self {
140- OutboundJITChannelState :: PendingInitialPayment { .. } => 0 ,
141- OutboundJITChannelState :: PendingChannelOpen { .. } => 1 ,
142- OutboundJITChannelState :: PendingPaymentForward { .. } => 2 ,
143- OutboundJITChannelState :: PendingPayment { .. } => 3 ,
144- OutboundJITChannelState :: PaymentForwarded { .. } => 4 ,
149+ OutboundJITChannelState :: PendingInitialPayment { .. } => {
150+ OutboundJITStage :: PendingInitialPayment
151+ } ,
152+ OutboundJITChannelState :: PendingChannelOpen { .. } => {
153+ OutboundJITStage :: PendingChannelOpen
154+ } ,
155+ OutboundJITChannelState :: PendingPaymentForward { .. } => {
156+ OutboundJITStage :: PendingPaymentForward
157+ } ,
158+ OutboundJITChannelState :: PendingPayment { .. } => OutboundJITStage :: PendingPayment ,
159+ OutboundJITChannelState :: PaymentForwarded { .. } => OutboundJITStage :: PaymentForwarded ,
145160 }
146161 }
147162}
@@ -154,7 +169,7 @@ impl PartialOrd for OutboundJITChannelState {
154169
155170impl Ord for OutboundJITChannelState {
156171 fn cmp ( & self , other : & Self ) -> core:: cmp:: Ordering {
157- self . ord_index ( ) . cmp ( & other. ord_index ( ) )
172+ self . stage ( ) . cmp ( & other. stage ( ) )
158173 }
159174}
160175
@@ -600,12 +615,10 @@ where
600615 & self , counterparty_node_id : & PublicKey ,
601616 ) -> Option < OutboundJITChannelState > {
602617 let outer_state_lock = self . per_peer_state . read ( ) . unwrap ( ) ;
603- if let Some ( inner_state_lock ) = outer_state_lock. get ( counterparty_node_id) {
604- let peer_state = inner_state_lock . lock ( ) . unwrap ( ) ;
618+ outer_state_lock. get ( counterparty_node_id) . and_then ( |inner| {
619+ let peer_state = inner . lock ( ) . unwrap ( ) ;
605620 peer_state. outbound_channels_by_intercept_scid . values ( ) . map ( |c| c. state . clone ( ) ) . max ( )
606- } else {
607- None
608- }
621+ } )
609622 }
610623
611624 /// Used by LSP to inform a client requesting a JIT Channel the token they used is invalid.
0 commit comments