@@ -5338,73 +5338,8 @@ where
5338
5338
self.unbroadcasted_funding_txid(funding).filter(|_| self.is_batch_funding())
5339
5339
}
5340
5340
5341
- /// Shuts down this channel (no more calls into this Channel may be made afterwards except
5342
- /// those explicitly stated to be allowed after shutdown, e.g. some simple getters).
5343
- ///
5344
- /// Only allowed for channels which never been used (i.e. have never broadcasted their funding
5345
- /// transaction).
5346
- fn abandon_unfunded_chan(
5347
- &mut self, funding: &FundingScope, mut closure_reason: ClosureReason,
5348
- ) -> ShutdownResult {
5349
- assert!(!matches!(self.channel_state, ChannelState::ShutdownComplete));
5350
- assert!(!self.is_funding_broadcast());
5351
-
5352
- let unbroadcasted_batch_funding_txid = self.unbroadcasted_batch_funding_txid(funding);
5353
- let unbroadcasted_funding_tx = self.unbroadcasted_funding(funding);
5354
-
5355
- let monitor_update = if let Some(funding_txo) = funding.get_funding_txo() {
5356
- // If we haven't yet exchanged funding signatures (ie channel_state < AwaitingChannelReady),
5357
- // returning a channel monitor update here would imply a channel monitor update before
5358
- // we even registered the channel monitor to begin with, which is invalid.
5359
- // Thus, if we aren't actually at a point where we could conceivably broadcast the
5360
- // funding transaction, don't return a funding txo (which prevents providing the
5361
- // monitor update to the user, even if we return one).
5362
- // See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5363
- if !self.channel_state.is_pre_funded_state() {
5364
- self.latest_monitor_update_id += 1;
5365
- let update = ChannelMonitorUpdate {
5366
- update_id: self.latest_monitor_update_id,
5367
- updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed {
5368
- should_broadcast: false,
5369
- }],
5370
- channel_id: Some(self.channel_id()),
5371
- };
5372
- Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), update))
5373
- } else {
5374
- None
5375
- }
5376
- } else {
5377
- None
5378
- };
5379
-
5380
- if let ClosureReason::HolderForceClosed { ref mut broadcasted_latest_txn, .. } =
5381
- &mut closure_reason
5382
- {
5383
- *broadcasted_latest_txn = Some(false);
5384
- }
5385
-
5386
- self.channel_state = ChannelState::ShutdownComplete;
5387
- self.update_time_counter += 1;
5388
- ShutdownResult {
5389
- closure_reason,
5390
- monitor_update,
5391
- dropped_outbound_htlcs: Vec::new(),
5392
- unbroadcasted_batch_funding_txid,
5393
- channel_id: self.channel_id,
5394
- user_channel_id: self.user_id,
5395
- channel_capacity_satoshis: funding.get_value_satoshis(),
5396
- counterparty_node_id: self.counterparty_node_id,
5397
- unbroadcasted_funding_tx,
5398
- is_manual_broadcast: self.is_manual_broadcast,
5399
- channel_funding_txo: funding.get_funding_txo(),
5400
- last_local_balance_msat: funding.value_to_self_msat,
5401
- }
5402
- }
5403
-
5404
- /// Shuts down this Channel (no more calls into this Channel may be made afterwards except
5405
- /// those explicitly stated to be alowed after shutdown, e.g. some simple getters).
5406
- pub fn force_shutdown(
5407
- &mut self, funding: &FundingScope, mut closure_reason: ClosureReason,
5341
+ pub fn do_force_shutdown(
5342
+ &mut self, funding: &FundingScope, mut closure_reason: ClosureReason, broadcast: bool,
5408
5343
) -> ShutdownResult {
5409
5344
// Note that we MUST only generate a monitor update that indicates force-closure - we're
5410
5345
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
@@ -5413,7 +5348,7 @@ where
5413
5348
assert!(!matches!(self.channel_state, ChannelState::ShutdownComplete));
5414
5349
5415
5350
if !self.is_funding_broadcast() {
5416
- return self.abandon_unfunded_chan(funding, closure_reason );
5351
+ debug_assert!(!broadcast );
5417
5352
}
5418
5353
5419
5354
// We go ahead and "free" any holding cell HTLCs or HTLCs we haven't yet committed to and
@@ -5446,7 +5381,7 @@ where
5446
5381
let update = ChannelMonitorUpdate {
5447
5382
update_id: self.latest_monitor_update_id,
5448
5383
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed {
5449
- should_broadcast: true ,
5384
+ should_broadcast: broadcast ,
5450
5385
}],
5451
5386
channel_id: Some(self.channel_id()),
5452
5387
};
@@ -5463,7 +5398,7 @@ where
5463
5398
if let ClosureReason::HolderForceClosed { ref mut broadcasted_latest_txn, .. } =
5464
5399
&mut closure_reason
5465
5400
{
5466
- *broadcasted_latest_txn = Some(true );
5401
+ *broadcasted_latest_txn = Some(broadcast );
5467
5402
}
5468
5403
5469
5404
self.channel_state = ChannelState::ShutdownComplete;
@@ -5484,6 +5419,25 @@ where
5484
5419
}
5485
5420
}
5486
5421
5422
+ /// Shuts down this channel (no more calls into this Channel may be made afterwards except
5423
+ /// those explicitly stated to be allowed after shutdown, e.g. some simple getters).
5424
+ ///
5425
+ /// Only allowed for channels which never been used (i.e. have never broadcasted their funding
5426
+ /// transaction).
5427
+ fn abandon_unfunded_chan(
5428
+ &mut self, funding: &FundingScope, closure_reason: ClosureReason,
5429
+ ) -> ShutdownResult {
5430
+ self.do_force_shutdown(funding, closure_reason, false)
5431
+ }
5432
+
5433
+ /// Shuts down this Channel (no more calls into this Channel may be made afterwards except
5434
+ /// those explicitly stated to be alowed after shutdown, e.g. some simple getters).
5435
+ pub fn force_shutdown(
5436
+ &mut self, funding: &FundingScope, closure_reason: ClosureReason,
5437
+ ) -> ShutdownResult {
5438
+ self.do_force_shutdown(funding, closure_reason, self.is_funding_broadcast())
5439
+ }
5440
+
5487
5441
/// Only allowed after [`FundingScope::channel_transaction_parameters`] is set.
5488
5442
#[rustfmt::skip]
5489
5443
fn get_funding_signed_msg<L: Deref>(
0 commit comments