@@ -141,8 +141,7 @@ impl OutboundJITChannelState {
141141 ) -> Result < Option < HTLCInterceptedAction > , ChannelStateError > {
142142 let new_state;
143143 let res = match self {
144- OutboundJITChannelState :: PendingInitialPayment { payment_queue : old_payment_queue } => {
145- let mut payment_queue = core:: mem:: take ( old_payment_queue) ;
144+ OutboundJITChannelState :: PendingInitialPayment { payment_queue } => {
146145 let ( total_expected_outbound_amount_msat, num_htlcs) = payment_queue. add_htlc ( htlc) ;
147146
148147 let ( expected_payment_size_msat, mpp_mode) =
@@ -151,8 +150,6 @@ impl OutboundJITChannelState {
151150 } else {
152151 debug_assert_eq ! ( num_htlcs, 1 ) ;
153152 if num_htlcs != 1 {
154- // Revert the queue before error'ing
155- core:: mem:: swap ( old_payment_queue, & mut payment_queue) ;
156153 return Err ( ChannelStateError (
157154 "Paying via multiple HTLCs is disallowed in \" no-MPP+var-invoice\" mode." . to_string ( )
158155 ) ) ;
@@ -163,8 +160,6 @@ impl OutboundJITChannelState {
163160 if expected_payment_size_msat < opening_fee_params. min_payment_size_msat
164161 || expected_payment_size_msat > opening_fee_params. max_payment_size_msat
165162 {
166- // Revert the queue before error'ing
167- core:: mem:: swap ( old_payment_queue, & mut payment_queue) ;
168163 return Err ( ChannelStateError (
169164 format ! ( "Payment size violates our limits: expected_payment_size_msat = {}, min_payment_size_msat = {}, max_payment_size_msat = {}" ,
170165 expected_payment_size_msat,
@@ -180,8 +175,6 @@ impl OutboundJITChannelState {
180175 ) {
181176 opening_fee
182177 } else {
183- // Revert the queue before error'ing
184- core:: mem:: swap ( old_payment_queue, & mut payment_queue) ;
185178 return Err ( ChannelStateError (
186179 format ! ( "Could not compute valid opening fee with min_fee_msat = {}, proportional = {}, and expected_payment_size_msat = {}" ,
187180 opening_fee_params. min_fee_msat,
@@ -198,7 +191,7 @@ impl OutboundJITChannelState {
198191 && amt_to_forward_msat > 0
199192 {
200193 new_state = OutboundJITChannelState :: PendingChannelOpen {
201- payment_queue,
194+ payment_queue : core :: mem :: take ( payment_queue ) ,
202195 opening_fee_msat,
203196 } ;
204197 let open_channel = HTLCInterceptedAction :: OpenChannel ( OpenChannelParams {
@@ -208,12 +201,11 @@ impl OutboundJITChannelState {
208201 Ok ( Some ( open_channel) )
209202 } else {
210203 if mpp_mode {
211- new_state =
212- OutboundJITChannelState :: PendingInitialPayment { payment_queue } ;
204+ new_state = OutboundJITChannelState :: PendingInitialPayment {
205+ payment_queue : core:: mem:: take ( payment_queue) ,
206+ } ;
213207 Ok ( None )
214208 } else {
215- // Revert the queue before error'ing
216- core:: mem:: swap ( old_payment_queue, & mut payment_queue) ;
217209 return Err ( ChannelStateError (
218210 "Intercepted HTLC is too small to pay opening fee" . to_string ( ) ,
219211 ) ) ;
@@ -287,16 +279,12 @@ impl OutboundJITChannelState {
287279 ) -> Result < ForwardPaymentAction , ChannelStateError > {
288280 let new_state;
289281 let res = match self {
290- OutboundJITChannelState :: PendingChannelOpen {
291- payment_queue : old_payment_queue,
292- opening_fee_msat,
293- } => {
294- let mut payment_queue = core:: mem:: take ( old_payment_queue) ;
282+ OutboundJITChannelState :: PendingChannelOpen { payment_queue, opening_fee_msat } => {
295283 if let Some ( ( _payment_hash, htlcs) ) =
296284 payment_queue. pop_greater_than_msat ( * opening_fee_msat)
297285 {
298286 new_state = OutboundJITChannelState :: PendingPaymentForward {
299- payment_queue,
287+ payment_queue : core :: mem :: take ( payment_queue ) ,
300288 opening_fee_msat : * opening_fee_msat,
301289 channel_id,
302290 } ;
@@ -306,8 +294,6 @@ impl OutboundJITChannelState {
306294 ) ;
307295 Ok ( forward_payment)
308296 } else {
309- // Revert the queue before error'ing
310- core:: mem:: swap ( old_payment_queue, & mut payment_queue) ;
311297 return Err ( ChannelStateError (
312298 "No forwardable payment available when moving to channel ready."
313299 . to_string ( ) ,
@@ -333,12 +319,11 @@ impl OutboundJITChannelState {
333319 opening_fee_msat,
334320 channel_id,
335321 } => {
336- let mut payment_queue = core:: mem:: take ( payment_queue) ;
337322 if let Some ( ( _payment_hash, htlcs) ) =
338323 payment_queue. pop_greater_than_msat ( * opening_fee_msat)
339324 {
340325 new_state = OutboundJITChannelState :: PendingPaymentForward {
341- payment_queue : payment_queue . clone ( ) ,
326+ payment_queue : core :: mem :: take ( payment_queue ) ,
342327 opening_fee_msat : * opening_fee_msat,
343328 channel_id : * channel_id,
344329 } ;
@@ -349,7 +334,7 @@ impl OutboundJITChannelState {
349334 Ok ( Some ( forward_payment) )
350335 } else {
351336 new_state = OutboundJITChannelState :: PendingPayment {
352- payment_queue : payment_queue . clone ( ) ,
337+ payment_queue : core :: mem :: take ( payment_queue ) ,
353338 opening_fee_msat : * opening_fee_msat,
354339 channel_id : * channel_id,
355340 } ;
@@ -362,7 +347,7 @@ impl OutboundJITChannelState {
362347 channel_id,
363348 } => {
364349 new_state = OutboundJITChannelState :: PendingPayment {
365- payment_queue : payment_queue . clone ( ) ,
350+ payment_queue : core :: mem :: take ( payment_queue ) ,
366351 opening_fee_msat : * opening_fee_msat,
367352 channel_id : * channel_id,
368353 } ;
0 commit comments