@@ -909,6 +909,7 @@ pub(super) struct SignerResumeUpdates {
909
909
pub order: RAACommitmentOrder,
910
910
pub closing_signed: Option<msgs::ClosingSigned>,
911
911
pub signed_closing_tx: Option<Transaction>,
912
+ pub shutdown_result: Option<ShutdownResult>,
912
913
}
913
914
914
915
/// The return value of `channel_reestablish`
@@ -5508,7 +5509,7 @@ impl<SP: Deref> Channel<SP> where
5508
5509
commitment_update = None;
5509
5510
}
5510
5511
5511
- let (closing_signed, signed_closing_tx) = if self.context.signer_pending_closing {
5512
+ let (closing_signed, signed_closing_tx, shutdown_result ) = if self.context.signer_pending_closing {
5512
5513
debug_assert!(self.context.last_sent_closing_fee.is_some());
5513
5514
if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
5514
5515
debug_assert!(holder_sig.is_none());
@@ -5524,19 +5525,21 @@ impl<SP: Deref> Channel<SP> where
5524
5525
&self.context.get_counterparty_pubkeys().funding_pubkey).is_ok());
5525
5526
Some(self.build_signed_closing_transaction(&closing_tx, &counterparty_sig, signature))
5526
5527
} else { None };
5527
- (closing_signed, signed_tx)
5528
- } else { (None, None) }
5529
- } else { (None, None) };
5528
+ let shutdown_result = signed_tx.as_ref().map(|_| self.shutdown_result_coop_close());
5529
+ (closing_signed, signed_tx, shutdown_result)
5530
+ } else { (None, None, None) }
5531
+ } else { (None, None, None) };
5530
5532
5531
5533
log_trace!(logger, "Signer unblocked with {} commitment_update, {} revoke_and_ack, with resend order {:?}, {} funding_signed, {} channel_ready,
5532
- {} closing_signed, and {} signed_closing_tx ",
5534
+ {} closing_signed, {} signed_closing_tx, and {} shutdown result ",
5533
5535
if commitment_update.is_some() { "a" } else { "no" },
5534
5536
if revoke_and_ack.is_some() { "a" } else { "no" },
5535
5537
self.context.resend_order,
5536
5538
if funding_signed.is_some() { "a" } else { "no" },
5537
5539
if channel_ready.is_some() { "a" } else { "no" },
5538
5540
if closing_signed.is_some() { "a" } else { "no" },
5539
- if signed_closing_tx.is_some() { "a" } else { "no" });
5541
+ if signed_closing_tx.is_some() { "a" } else { "no" },
5542
+ if shutdown_result.is_some() { "a" } else { "no" });
5540
5543
5541
5544
SignerResumeUpdates {
5542
5545
commitment_update,
@@ -5546,6 +5549,7 @@ impl<SP: Deref> Channel<SP> where
5546
5549
order: self.context.resend_order.clone(),
5547
5550
closing_signed,
5548
5551
signed_closing_tx,
5552
+ shutdown_result,
5549
5553
}
5550
5554
}
5551
5555
@@ -6170,6 +6174,27 @@ impl<SP: Deref> Channel<SP> where
6170
6174
})
6171
6175
}
6172
6176
6177
+ fn shutdown_result_coop_close(&self) -> ShutdownResult {
6178
+ let closure_reason = if self.initiated_shutdown() {
6179
+ ClosureReason::LocallyInitiatedCooperativeClosure
6180
+ } else {
6181
+ ClosureReason::CounterpartyInitiatedCooperativeClosure
6182
+ };
6183
+ ShutdownResult {
6184
+ closure_reason,
6185
+ monitor_update: None,
6186
+ dropped_outbound_htlcs: Vec::new(),
6187
+ unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
6188
+ channel_id: self.context.channel_id,
6189
+ user_channel_id: self.context.user_id,
6190
+ channel_capacity_satoshis: self.context.channel_value_satoshis,
6191
+ counterparty_node_id: self.context.counterparty_node_id,
6192
+ unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
6193
+ is_manual_broadcast: self.context.is_manual_broadcast,
6194
+ channel_funding_txo: self.context.get_funding_txo(),
6195
+ }
6196
+ }
6197
+
6173
6198
pub fn closing_signed<F: Deref, L: Deref>(
6174
6199
&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, msg: &msgs::ClosingSigned, logger: &L)
6175
6200
-> Result<(Option<msgs::ClosingSigned>, Option<Transaction>, Option<ShutdownResult>), ChannelError>
@@ -6226,28 +6251,10 @@ impl<SP: Deref> Channel<SP> where
6226
6251
}
6227
6252
}
6228
6253
6229
- let closure_reason = if self.initiated_shutdown() {
6230
- ClosureReason::LocallyInitiatedCooperativeClosure
6231
- } else {
6232
- ClosureReason::CounterpartyInitiatedCooperativeClosure
6233
- };
6234
-
6235
6254
assert!(self.context.shutdown_scriptpubkey.is_some());
6236
6255
if let Some((last_fee, _, _, Some(sig))) = self.context.last_sent_closing_fee {
6237
6256
if last_fee == msg.fee_satoshis {
6238
- let shutdown_result = ShutdownResult {
6239
- closure_reason,
6240
- monitor_update: None,
6241
- dropped_outbound_htlcs: Vec::new(),
6242
- unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
6243
- channel_id: self.context.channel_id,
6244
- user_channel_id: self.context.user_id,
6245
- channel_capacity_satoshis: self.context.channel_value_satoshis,
6246
- counterparty_node_id: self.context.counterparty_node_id,
6247
- unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
6248
- is_manual_broadcast: self.context.is_manual_broadcast,
6249
- channel_funding_txo: self.context.get_funding_txo(),
6250
- };
6257
+ let shutdown_result = self.shutdown_result_coop_close();
6251
6258
let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
6252
6259
self.context.channel_state = ChannelState::ShutdownComplete;
6253
6260
self.context.update_time_counter += 1;
@@ -6268,27 +6275,16 @@ impl<SP: Deref> Channel<SP> where
6268
6275
6269
6276
let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output, used_fee, our_min_fee, our_max_fee, logger);
6270
6277
let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis {
6271
- let shutdown_result = ShutdownResult {
6272
- closure_reason,
6273
- monitor_update: None,
6274
- dropped_outbound_htlcs: Vec::new(),
6275
- unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
6276
- channel_id: self.context.channel_id,
6277
- user_channel_id: self.context.user_id,
6278
- channel_capacity_satoshis: self.context.channel_value_satoshis,
6279
- counterparty_node_id: self.context.counterparty_node_id,
6280
- unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
6281
- is_manual_broadcast: self.context.is_manual_broadcast,
6282
- channel_funding_txo: self.context.get_funding_txo(),
6283
- };
6278
+ let shutdown_result = closing_signed.as_ref()
6279
+ .map(|_| self.shutdown_result_coop_close());
6284
6280
if closing_signed.is_some() {
6285
6281
self.context.channel_state = ChannelState::ShutdownComplete;
6286
6282
}
6287
6283
self.context.update_time_counter += 1;
6288
6284
self.context.last_received_closing_sig = Some(msg.signature.clone());
6289
6285
let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }|
6290
6286
self.build_signed_closing_transaction(&closing_tx, &msg.signature, signature));
6291
- (tx, Some( shutdown_result) )
6287
+ (tx, shutdown_result)
6292
6288
} else {
6293
6289
(None, None)
6294
6290
};
0 commit comments