+ #[inline]
+ fn finish_force_close_channel(&self, shutdown_res: (Vec<Transaction>, Vec<[u8; 32]>)) {
+ let (local_txn, failed_htlcs) = shutdown_res;
+ for payment_hash in failed_htlcs {
+ // unknown_next_peer...I dunno who that is anymore....
+ self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), &payment_hash, HTLCFailReason::Reason { failure_code: 0x4000 | 10, data: Vec::new() });
+ }
+ for tx in local_txn {
+ self.tx_broadcaster.broadcast_transaction(&tx);
+ }
+ //TODO: We need to have a way where outbound HTLC claims can result in us claiming the
+ //now-on-chain HTLC output for ourselves (and, thereafter, passing the HTLC backwards).
+ //TODO: We need to handle monitoring of pending offered HTLCs which just hit the chain and
+ //may be claimed, resulting in us claiming the inbound HTLCs (and back-failing after
+ //timeouts are hit and our claims confirm).
+ }
+
+ /// Force closes a channel, immediately broadcasting the latest local commitment transaction to
+ /// the chain and rejecting new HTLCs on the given channel.
+ pub fn force_close_channel(&self, channel_id: &[u8; 32]) {
+ let mut chan = {
+ let mut channel_state_lock = self.channel_state.lock().unwrap();
+ let channel_state = channel_state_lock.borrow_parts();
+ if let Some(mut chan) = channel_state.by_id.remove(channel_id) {
+ if let Some(short_id) = chan.get_short_channel_id() {
+ channel_state.short_to_id.remove(&short_id);
+ }
+ chan
+ } else {
+ return;
+ }
+ };
+ self.finish_force_close_channel(chan.force_shutdown());
+ let mut events = self.pending_events.lock().unwrap();
+ if let Ok(update) = self.get_channel_update(&chan) {
+ events.push(events::Event::BroadcastChannelUpdate {
+ msg: update
+ });
+ }
+ }
+