@@ -1966,14 +1966,6 @@ macro_rules! handle_error {
1966
1966
msg: update
1967
1967
});
1968
1968
}
1969
- if let Some((channel_id, user_channel_id)) = chan_id {
1970
- $self.pending_events.lock().unwrap().push_back((events::Event::ChannelClosed {
1971
- channel_id, user_channel_id,
1972
- reason: ClosureReason::ProcessingError { err: err.err.clone() },
1973
- counterparty_node_id: Some($counterparty_node_id),
1974
- channel_capacity_sats: channel_capacity,
1975
- }, None));
1976
- }
1977
1969
}
1978
1970
1979
1971
let logger = WithContext::from(
@@ -2039,7 +2031,8 @@ macro_rules! convert_chan_phase_err {
2039
2031
let logger = WithChannelContext::from(&$self.logger, &$channel.context);
2040
2032
log_error!(logger, "Closing channel {} due to close-required error: {}", $channel_id, msg);
2041
2033
update_maps_on_chan_removal!($self, $channel.context);
2042
- let shutdown_res = $channel.context.force_shutdown(true);
2034
+ let reason = ClosureReason::ProcessingError { err: msg.clone() };
2035
+ let shutdown_res = $channel.context.force_shutdown(true, reason);
2043
2036
let user_id = $channel.context.get_user_id();
2044
2037
let channel_capacity_satoshis = $channel.context.get_value_satoshis();
2045
2038
@@ -2701,18 +2694,6 @@ where
2701
2694
.collect()
2702
2695
}
2703
2696
2704
- /// Helper function that issues the channel close events
2705
- fn issue_channel_close_events(&self, context: &ChannelContext<SP>, closure_reason: ClosureReason) {
2706
- let mut pending_events_lock = self.pending_events.lock().unwrap();
2707
- pending_events_lock.push_back((events::Event::ChannelClosed {
2708
- channel_id: context.channel_id(),
2709
- user_channel_id: context.get_user_id(),
2710
- reason: closure_reason,
2711
- counterparty_node_id: Some(context.get_counterparty_node_id()),
2712
- channel_capacity_sats: Some(context.get_value_satoshis()),
2713
- }, None));
2714
- }
2715
-
2716
2697
fn close_channel_internal(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, target_feerate_sats_per_1000_weight: Option<u32>, override_shutdown_script: Option<ShutdownScript>) -> Result<(), APIError> {
2717
2698
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
2718
2699
@@ -2754,9 +2735,8 @@ where
2754
2735
peer_state_lock, peer_state, per_peer_state, chan);
2755
2736
}
2756
2737
} else {
2757
- self.issue_channel_close_events(chan_phase_entry.get().context(), ClosureReason::HolderForceClosed);
2758
2738
let mut chan_phase = remove_channel_phase!(self, chan_phase_entry);
2759
- shutdown_result = Some(chan_phase.context_mut().force_shutdown(false));
2739
+ shutdown_result = Some(chan_phase.context_mut().force_shutdown(false, ClosureReason::HolderForceClosed ));
2760
2740
}
2761
2741
},
2762
2742
hash_map::Entry::Vacant(_) => {
@@ -2853,6 +2833,7 @@ where
2853
2833
let logger = WithContext::from(
2854
2834
&self.logger, Some(shutdown_res.counterparty_node_id), Some(shutdown_res.channel_id),
2855
2835
);
2836
+
2856
2837
log_debug!(logger, "Finishing closure of channel with {} HTLCs to fail", shutdown_res.dropped_outbound_htlcs.len());
2857
2838
for htlc_source in shutdown_res.dropped_outbound_htlcs.drain(..) {
2858
2839
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
@@ -2878,8 +2859,7 @@ where
2878
2859
let mut peer_state = peer_state_mutex.lock().unwrap();
2879
2860
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
2880
2861
update_maps_on_chan_removal!(self, &chan.context());
2881
- self.issue_channel_close_events(&chan.context(), ClosureReason::FundingBatchClosure);
2882
- shutdown_results.push(chan.context_mut().force_shutdown(false));
2862
+ shutdown_results.push(chan.context_mut().force_shutdown(false, ClosureReason::FundingBatchClosure));
2883
2863
}
2884
2864
}
2885
2865
has_uncompleted_channel = Some(has_uncompleted_channel.map_or(!state, |v| v || !state));
@@ -2892,6 +2872,14 @@ where
2892
2872
2893
2873
{
2894
2874
let mut pending_events = self.pending_events.lock().unwrap();
2875
+ pending_events.push_back((events::Event::ChannelClosed {
2876
+ channel_id: shutdown_res.channel_id,
2877
+ user_channel_id: shutdown_res.user_channel_id,
2878
+ reason: shutdown_res.closure_reason,
2879
+ counterparty_node_id: Some(shutdown_res.counterparty_node_id),
2880
+ channel_capacity_sats: Some(shutdown_res.channel_capacity_satoshis),
2881
+ }, None));
2882
+
2895
2883
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
2896
2884
pending_events.push_back((events::Event::DiscardFunding {
2897
2885
channel_id: shutdown_res.channel_id, transaction
@@ -2920,17 +2908,16 @@ where
2920
2908
let logger = WithContext::from(&self.logger, Some(*peer_node_id), Some(*channel_id));
2921
2909
if let hash_map::Entry::Occupied(chan_phase_entry) = peer_state.channel_by_id.entry(channel_id.clone()) {
2922
2910
log_error!(logger, "Force-closing channel {}", channel_id);
2923
- self.issue_channel_close_events(&chan_phase_entry.get().context(), closure_reason);
2924
2911
let mut chan_phase = remove_channel_phase!(self, chan_phase_entry);
2925
2912
mem::drop(peer_state);
2926
2913
mem::drop(per_peer_state);
2927
2914
match chan_phase {
2928
2915
ChannelPhase::Funded(mut chan) => {
2929
- self.finish_close_channel(chan.context.force_shutdown(broadcast));
2916
+ self.finish_close_channel(chan.context.force_shutdown(broadcast, closure_reason ));
2930
2917
(self.get_channel_update_for_broadcast(&chan).ok(), chan.context.get_counterparty_node_id())
2931
2918
},
2932
2919
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => {
2933
- self.finish_close_channel(chan_phase.context_mut().force_shutdown(false));
2920
+ self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason ));
2934
2921
// Unfunded channel has no update
2935
2922
(None, chan_phase.context().get_counterparty_node_id())
2936
2923
},
@@ -3760,7 +3747,8 @@ where
3760
3747
.map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
3761
3748
let channel_id = chan.context.channel_id();
3762
3749
let user_id = chan.context.get_user_id();
3763
- let shutdown_res = chan.context.force_shutdown(false);
3750
+ let reason = ClosureReason::ProcessingError { err: msg.clone() };
3751
+ let shutdown_res = chan.context.force_shutdown(false, reason);
3764
3752
let channel_capacity = chan.context.get_value_satoshis();
3765
3753
(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity))
3766
3754
} else { unreachable!(); });
@@ -3967,8 +3955,8 @@ where
3967
3955
.and_then(|mut peer_state| peer_state.channel_by_id.remove(&channel_id))
3968
3956
.map(|mut chan| {
3969
3957
update_maps_on_chan_removal!(self, &chan.context());
3970
- self.issue_channel_close_events(&chan.context(), ClosureReason::ProcessingError { err: e.clone() }) ;
3971
- shutdown_results.push(chan.context_mut().force_shutdown(false));
3958
+ let closure_reason = ClosureReason::ProcessingError { err: e.clone() };
3959
+ shutdown_results.push(chan.context_mut().force_shutdown(false, closure_reason ));
3972
3960
});
3973
3961
}
3974
3962
}
@@ -4890,8 +4878,7 @@ where
4890
4878
log_error!(logger,
4891
4879
"Force-closing pending channel with ID {} for not establishing in a timely manner", chan_id);
4892
4880
update_maps_on_chan_removal!(self, &context);
4893
- self.issue_channel_close_events(&context, ClosureReason::HolderForceClosed);
4894
- shutdown_channels.push(context.force_shutdown(false));
4881
+ shutdown_channels.push(context.force_shutdown(false, ClosureReason::HolderForceClosed));
4895
4882
pending_msg_events.push(MessageSendEvent::HandleError {
4896
4883
node_id: counterparty_node_id,
4897
4884
action: msgs::ErrorAction::SendErrorMessage {
@@ -6511,9 +6498,8 @@ where
6511
6498
let context = phase.context_mut();
6512
6499
let logger = WithChannelContext::from(&self.logger, context);
6513
6500
log_error!(logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6514
- self.issue_channel_close_events(&context, ClosureReason::CounterpartyCoopClosedUnfundedChannel);
6515
6501
let mut chan = remove_channel_phase!(self, chan_phase_entry);
6516
- finish_shutdown = Some(chan.context_mut().force_shutdown(false));
6502
+ finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel ));
6517
6503
},
6518
6504
}
6519
6505
} else {
@@ -6582,7 +6568,6 @@ where
6582
6568
msg: update
6583
6569
});
6584
6570
}
6585
- self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
6586
6571
}
6587
6572
mem::drop(per_peer_state);
6588
6573
if let Some(shutdown_result) = shutdown_result {
@@ -7234,13 +7219,12 @@ where
7234
7219
let pending_msg_events = &mut peer_state.pending_msg_events;
7235
7220
if let hash_map::Entry::Occupied(chan_phase_entry) = peer_state.channel_by_id.entry(funding_outpoint.to_channel_id()) {
7236
7221
if let ChannelPhase::Funded(mut chan) = remove_channel_phase!(self, chan_phase_entry) {
7237
- failed_channels.push(chan.context.force_shutdown(false));
7222
+ failed_channels.push(chan.context.force_shutdown(false, ClosureReason::HolderForceClosed ));
7238
7223
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
7239
7224
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
7240
7225
msg: update
7241
7226
});
7242
7227
}
7243
- self.issue_channel_close_events(&chan.context, ClosureReason::HolderForceClosed);
7244
7228
pending_msg_events.push(events::MessageSendEvent::HandleError {
7245
7229
node_id: chan.context.get_counterparty_node_id(),
7246
7230
action: msgs::ErrorAction::DisconnectPeer {
@@ -7427,8 +7411,6 @@ where
7427
7411
});
7428
7412
}
7429
7413
7430
- self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
7431
-
7432
7414
log_info!(logger, "Broadcasting {}", log_tx!(tx));
7433
7415
self.tx_broadcaster.broadcast_transactions(&[&tx]);
7434
7416
update_maps_on_chan_removal!(self, &chan.context);
@@ -8441,14 +8423,13 @@ where
8441
8423
update_maps_on_chan_removal!(self, &channel.context);
8442
8424
// It looks like our counterparty went on-chain or funding transaction was
8443
8425
// reorged out of the main chain. Close the channel.
8444
- failed_channels.push(channel.context.force_shutdown(true));
8426
+ let reason_message = format!("{}", reason);
8427
+ failed_channels.push(channel.context.force_shutdown(true, reason));
8445
8428
if let Ok(update) = self.get_channel_update_for_broadcast(&channel) {
8446
8429
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
8447
8430
msg: update
8448
8431
});
8449
8432
}
8450
- let reason_message = format!("{}", reason);
8451
- self.issue_channel_close_events(&channel.context, reason);
8452
8433
pending_msg_events.push(events::MessageSendEvent::HandleError {
8453
8434
node_id: channel.context.get_counterparty_node_id(),
8454
8435
action: msgs::ErrorAction::DisconnectPeer {
@@ -8846,8 +8827,7 @@ where
8846
8827
};
8847
8828
// Clean up for removal.
8848
8829
update_maps_on_chan_removal!(self, &context);
8849
- self.issue_channel_close_events(&context, ClosureReason::DisconnectedPeer);
8850
- failed_channels.push(context.force_shutdown(false));
8830
+ failed_channels.push(context.force_shutdown(false, ClosureReason::DisconnectedPeer));
8851
8831
false
8852
8832
});
8853
8833
// Note that we don't bother generating any events for pre-accept channels -
@@ -10287,7 +10267,7 @@ where
10287
10267
log_error!(logger, " The ChannelMonitor for channel {} is at counterparty commitment transaction number {} but the ChannelManager is at counterparty commitment transaction number {}.",
10288
10268
&channel.context.channel_id(), monitor.get_cur_counterparty_commitment_number(), channel.get_cur_counterparty_commitment_transaction_number());
10289
10269
}
10290
- let mut shutdown_result = channel.context.force_shutdown(true);
10270
+ let mut shutdown_result = channel.context.force_shutdown(true, ClosureReason::OutdatedChannelManager );
10291
10271
if shutdown_result.unbroadcasted_batch_funding_txid.is_some() {
10292
10272
return Err(DecodeError::InvalidValue);
10293
10273
}
@@ -10349,7 +10329,7 @@ where
10349
10329
// If we were persisted and shut down while the initial ChannelMonitor persistence
10350
10330
// was in-progress, we never broadcasted the funding transaction and can still
10351
10331
// safely discard the channel.
10352
- let _ = channel.context.force_shutdown(false);
10332
+ let _ = channel.context.force_shutdown(false, ClosureReason::DisconnectedPeer );
10353
10333
channel_closures.push_back((events::Event::ChannelClosed {
10354
10334
channel_id: channel.context.channel_id(),
10355
10335
user_channel_id: channel.context.get_user_id(),
0 commit comments