@@ -909,6 +909,7 @@ pub(super) struct SignerResumeUpdates {
909909 pub order: RAACommitmentOrder,
910910 pub closing_signed: Option<msgs::ClosingSigned>,
911911 pub signed_closing_tx: Option<Transaction>,
912+ pub shutdown_result: Option<ShutdownResult>,
912913}
913914
914915/// The return value of `channel_reestablish`
@@ -5508,7 +5509,7 @@ impl<SP: Deref> Channel<SP> where
55085509 commitment_update = None;
55095510 }
55105511
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 {
55125513 debug_assert!(self.context.last_sent_closing_fee.is_some());
55135514 if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
55145515 debug_assert!(holder_sig.is_none());
@@ -5524,19 +5525,21 @@ impl<SP: Deref> Channel<SP> where
55245525 &self.context.get_counterparty_pubkeys().funding_pubkey).is_ok());
55255526 Some(self.build_signed_closing_transaction(&closing_tx, &counterparty_sig, signature))
55265527 } 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) };
55305532
55315533 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 ",
55335535 if commitment_update.is_some() { "a" } else { "no" },
55345536 if revoke_and_ack.is_some() { "a" } else { "no" },
55355537 self.context.resend_order,
55365538 if funding_signed.is_some() { "a" } else { "no" },
55375539 if channel_ready.is_some() { "a" } else { "no" },
55385540 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" });
55405543
55415544 SignerResumeUpdates {
55425545 commitment_update,
@@ -5546,6 +5549,7 @@ impl<SP: Deref> Channel<SP> where
55465549 order: self.context.resend_order.clone(),
55475550 closing_signed,
55485551 signed_closing_tx,
5552+ shutdown_result,
55495553 }
55505554 }
55515555
@@ -6170,6 +6174,27 @@ impl<SP: Deref> Channel<SP> where
61706174 })
61716175 }
61726176
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+
61736198 pub fn closing_signed<F: Deref, L: Deref>(
61746199 &mut self, fee_estimator: &LowerBoundedFeeEstimator<F>, msg: &msgs::ClosingSigned, logger: &L)
61756200 -> Result<(Option<msgs::ClosingSigned>, Option<Transaction>, Option<ShutdownResult>), ChannelError>
@@ -6226,28 +6251,10 @@ impl<SP: Deref> Channel<SP> where
62266251 }
62276252 }
62286253
6229- let closure_reason = if self.initiated_shutdown() {
6230- ClosureReason::LocallyInitiatedCooperativeClosure
6231- } else {
6232- ClosureReason::CounterpartyInitiatedCooperativeClosure
6233- };
6234-
62356254 assert!(self.context.shutdown_scriptpubkey.is_some());
62366255 if let Some((last_fee, _, _, Some(sig))) = self.context.last_sent_closing_fee {
62376256 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();
62516258 let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
62526259 self.context.channel_state = ChannelState::ShutdownComplete;
62536260 self.context.update_time_counter += 1;
@@ -6268,27 +6275,16 @@ impl<SP: Deref> Channel<SP> where
62686275
62696276 let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output, used_fee, our_min_fee, our_max_fee, logger);
62706277 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());
62846280 if closing_signed.is_some() {
62856281 self.context.channel_state = ChannelState::ShutdownComplete;
62866282 }
62876283 self.context.update_time_counter += 1;
62886284 self.context.last_received_closing_sig = Some(msg.signature.clone());
62896285 let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }|
62906286 self.build_signed_closing_transaction(&closing_tx, &msg.signature, signature));
6291- (tx, Some( shutdown_result) )
6287+ (tx, shutdown_result)
62926288 } else {
62936289 (None, None)
62946290 };
0 commit comments