+ // Fail a list of HTLCs that were just freed from the holding cell. The HTLCs need to be
+ // failed backwards or, if they were one of our outgoing HTLCs, then their failure needs to
+ // be surfaced to the user.
+ fn fail_holding_cell_htlcs(&self, mut htlcs_to_fail: Vec<(HTLCSource, PaymentHash)>, channel_id: [u8; 32]) {
+ for (htlc_src, payment_hash) in htlcs_to_fail.drain(..) {
+ match htlc_src {
+ HTLCSource::PreviousHopData(HTLCPreviousHopData { .. }) => {
+ let (failure_code, onion_failure_data) =
+ match self.channel_state.lock().unwrap().by_id.entry(channel_id) {
+ hash_map::Entry::Occupied(chan_entry) => {
+ if let Ok(upd) = self.get_channel_update(&chan_entry.get()) {
+ (0x1000|7, upd.encode_with_len())
+ } else {
+ (0x4000|10, Vec::new())
+ }
+ },
+ hash_map::Entry::Vacant(_) => (0x4000|10, Vec::new())
+ };
+ let channel_state = self.channel_state.lock().unwrap();
+ self.fail_htlc_backwards_internal(channel_state,
+ htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data});
+ },
+ HTLCSource::OutboundRoute { .. } => {
+ self.pending_events.lock().unwrap().push(
+ events::Event::PaymentFailed {
+ payment_hash,
+ rejected_by_dest: false,
+#[cfg(test)]
+ error_code: None,
+#[cfg(test)]
+ error_data: None,
+ }
+ )
+ },
+ };
+ }
+ }
+