@@ -107,8 +107,17 @@ struct ForwardPaymentAction(ChannelId, FeePayment);
107
107
#[ derive( Debug , PartialEq ) ]
108
108
struct ForwardHTLCsAction ( ChannelId , Vec < InterceptedHTLC > ) ;
109
109
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
+
110
119
/// The different states a requested JIT channel can be in.
111
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
120
+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
112
121
pub ( crate ) enum OutboundJITChannelState {
113
122
/// The JIT channel SCID was created after a buy request, and we are awaiting an initial payment
114
123
/// of sufficient size to open the channel.
@@ -135,13 +144,19 @@ pub(crate) enum OutboundJITChannelState {
135
144
}
136
145
137
146
impl OutboundJITChannelState {
138
- fn ord_index ( & self ) -> u8 {
147
+ pub ( crate ) fn stage ( & self ) -> OutboundJITStage {
139
148
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 ,
145
160
}
146
161
}
147
162
}
@@ -154,7 +169,7 @@ impl PartialOrd for OutboundJITChannelState {
154
169
155
170
impl Ord for OutboundJITChannelState {
156
171
fn cmp ( & self , other : & Self ) -> core:: cmp:: Ordering {
157
- self . ord_index ( ) . cmp ( & other. ord_index ( ) )
172
+ self . stage ( ) . cmp ( & other. stage ( ) )
158
173
}
159
174
}
160
175
@@ -600,12 +615,10 @@ where
600
615
& self , counterparty_node_id : & PublicKey ,
601
616
) -> Option < OutboundJITChannelState > {
602
617
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 ( ) ;
605
620
peer_state. outbound_channels_by_intercept_scid . values ( ) . map ( |c| c. state . clone ( ) ) . max ( )
606
- } else {
607
- None
608
- }
621
+ } )
609
622
}
610
623
611
624
/// Used by LSP to inform a client requesting a JIT Channel the token they used is invalid.
0 commit comments