@@ -2555,26 +2555,24 @@ impl FailHTLCContents for msgs::OnionErrorPacket {
2555
2555
HTLCUpdateAwaitingACK::FailHTLC { htlc_id, err_packet: self }
2556
2556
}
2557
2557
}
2558
- impl FailHTLCContents for (u16, [u8; 32]) {
2559
- type Message = msgs::UpdateFailMalformedHTLC; // (failure_code, sha256_of_onion)
2558
+ impl FailHTLCContents for ([u8; 32], u16 ) {
2559
+ type Message = msgs::UpdateFailMalformedHTLC;
2560
2560
fn to_message(self, htlc_id: u64, channel_id: ChannelId) -> Self::Message {
2561
2561
msgs::UpdateFailMalformedHTLC {
2562
2562
htlc_id,
2563
2563
channel_id,
2564
- failure_code : self.0,
2565
- sha256_of_onion : self.1
2564
+ sha256_of_onion : self.0,
2565
+ failure_code : self.1
2566
2566
}
2567
2567
}
2568
2568
fn to_inbound_htlc_state(self) -> InboundHTLCState {
2569
- InboundHTLCState::LocalRemoved(
2570
- InboundHTLCRemovalReason::FailMalformed((self.1, self.0))
2571
- )
2569
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(self))
2572
2570
}
2573
2571
fn to_htlc_update_awaiting_ack(self, htlc_id: u64) -> HTLCUpdateAwaitingACK {
2574
2572
HTLCUpdateAwaitingACK::FailMalformedHTLC {
2575
2573
htlc_id,
2576
- failure_code : self.0,
2577
- sha256_of_onion : self.1
2574
+ sha256_of_onion : self.0,
2575
+ failure_code : self.1
2578
2576
}
2579
2577
}
2580
2578
}
@@ -2901,7 +2899,7 @@ impl<SP: Deref> Channel<SP> where
2901
2899
pub fn queue_fail_malformed_htlc<L: Deref>(
2902
2900
&mut self, htlc_id_arg: u64, failure_code: u16, sha256_of_onion: [u8; 32], logger: &L
2903
2901
) -> Result<(), ChannelError> where L::Target: Logger {
2904
- self.fail_htlc(htlc_id_arg, (failure_code, sha256_of_onion ), true, logger)
2902
+ self.fail_htlc(htlc_id_arg, (sha256_of_onion, failure_code ), true, logger)
2905
2903
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
2906
2904
}
2907
2905
@@ -2914,7 +2912,7 @@ impl<SP: Deref> Channel<SP> where
2914
2912
/// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
2915
2913
/// [`ChannelError::Ignore`].
2916
2914
fn fail_htlc<L: Deref, E: FailHTLCContents + Clone>(
2917
- &mut self, htlc_id_arg: u64, err_packet : E, mut force_holding_cell: bool,
2915
+ &mut self, htlc_id_arg: u64, err_contents : E, mut force_holding_cell: bool,
2918
2916
logger: &L
2919
2917
) -> Result<Option<E::Message>, ChannelError> where L::Target: Logger {
2920
2918
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
@@ -2981,18 +2979,18 @@ impl<SP: Deref> Channel<SP> where
2981
2979
}
2982
2980
}
2983
2981
log_trace!(logger, "Placing failure for HTLC ID {} in holding cell in channel {}.", htlc_id_arg, &self.context.channel_id());
2984
- self.context.holding_cell_htlc_updates.push(err_packet .to_htlc_update_awaiting_ack(htlc_id_arg));
2982
+ self.context.holding_cell_htlc_updates.push(err_contents .to_htlc_update_awaiting_ack(htlc_id_arg));
2985
2983
return Ok(None);
2986
2984
}
2987
2985
2988
2986
log_trace!(logger, "Failing HTLC ID {} back with {} message in channel {}.", htlc_id_arg,
2989
2987
E::Message::name(), &self.context.channel_id());
2990
2988
{
2991
2989
let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
2992
- htlc.state = err_packet .clone().to_inbound_htlc_state();
2990
+ htlc.state = err_contents .clone().to_inbound_htlc_state();
2993
2991
}
2994
2992
2995
- Ok(Some(err_packet .to_message(htlc_id_arg, self.context.channel_id())))
2993
+ Ok(Some(err_contents .to_message(htlc_id_arg, self.context.channel_id())))
2996
2994
}
2997
2995
2998
2996
// Message handlers:
@@ -3605,7 +3603,7 @@ impl<SP: Deref> Channel<SP> where
3605
3603
// the limit. In case it's less rare than I anticipate, we may want to revisit
3606
3604
// handling this case better and maybe fulfilling some of the HTLCs while attempting
3607
3605
// to rebalance channels.
3608
- match &htlc_update {
3606
+ let fail_htlc_res = match &htlc_update {
3609
3607
&HTLCUpdateAwaitingACK::AddHTLC {
3610
3608
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
3611
3609
skimmed_fee_msat, blinding_point, ..
@@ -3633,6 +3631,7 @@ impl<SP: Deref> Channel<SP> where
3633
3631
}
3634
3632
}
3635
3633
}
3634
+ None
3636
3635
},
3637
3636
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
3638
3637
// If an HTLC claim was previously added to the holding cell (via
@@ -3646,40 +3645,33 @@ impl<SP: Deref> Channel<SP> where
3646
3645
{ monitor_update } else { unreachable!() };
3647
3646
update_fulfill_count += 1;
3648
3647
monitor_update.updates.append(&mut additional_monitor_update.updates);
3648
+ None
3649
3649
},
3650
3650
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, ref err_packet } => {
3651
- match self.fail_htlc(htlc_id, err_packet.clone(), false, logger) {
3652
- Ok(update_fail_msg_option) => {
3653
- // If an HTLC failure was previously added to the holding cell (via
3654
- // `queue_fail_htlc`) then generating the fail message itself must
3655
- // not fail - we should never end up in a state where we double-fail
3656
- // an HTLC or fail-then-claim an HTLC as it indicates we didn't wait
3657
- // for a full revocation before failing.
3658
- debug_assert!(update_fail_msg_option.is_some());
3659
- update_fail_count += 1;
3660
- },
3661
- Err(e) => {
3662
- if let ChannelError::Ignore(_) = e {}
3663
- else {
3664
- panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3665
- }
3666
- }
3667
- }
3651
+ Some(self.fail_htlc(htlc_id, err_packet.clone(), false, logger)
3652
+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())))
3668
3653
},
3669
3654
&HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
3670
- match self.fail_htlc(htlc_id, (failure_code, sha256_of_onion), false, logger) {
3671
- Ok(update_fail_malformed_opt) => {
3672
- debug_assert!(update_fail_malformed_opt.is_some()); // See above comment
3673
- update_fail_count += 1;
3674
- },
3675
- Err(e) => {
3676
- if let ChannelError::Ignore(_) = e {}
3677
- else {
3678
- panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3679
- }
3680
- }
3681
- }
3682
- },
3655
+ Some(self.fail_htlc(htlc_id, (sha256_of_onion, failure_code), false, logger)
3656
+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())))
3657
+ }
3658
+ };
3659
+ if let Some(res) = fail_htlc_res {
3660
+ match res {
3661
+ Ok(fail_msg_opt) => {
3662
+ // If an HTLC failure was previously added to the holding cell (via
3663
+ // `queue_fail_{malformed_}htlc`) then generating the fail message itself must
3664
+ // not fail - we should never end up in a state where we double-fail
3665
+ // an HTLC or fail-then-claim an HTLC as it indicates we didn't wait
3666
+ // for a full revocation before failing.
3667
+ debug_assert!(fail_msg_opt.is_some());
3668
+ update_fail_count += 1;
3669
+ },
3670
+ Err(ChannelError::Ignore(_)) => {},
3671
+ Err(_) => {
3672
+ panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3673
+ },
3674
+ }
3683
3675
}
3684
3676
}
3685
3677
if update_add_count == 0 && update_fulfill_count == 0 && update_fail_count == 0 && self.context.holding_cell_update_fee.is_none() {
0 commit comments