@@ -911,6 +911,8 @@ pub(super) struct SignerResumeUpdates {
911
911
pub funding_signed: Option<msgs::FundingSigned>,
912
912
pub channel_ready: Option<msgs::ChannelReady>,
913
913
pub order: RAACommitmentOrder,
914
+ pub closing_signed: Option<msgs::ClosingSigned>,
915
+ pub signed_closing_tx: Option<Transaction>,
914
916
}
915
917
916
918
/// The return value of `channel_reestablish`
@@ -1237,6 +1239,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1237
1239
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
1238
1240
/// outbound or inbound.
1239
1241
signer_pending_funding: bool,
1242
+ /// If we attempted to sign a cooperative close transaction but the signer wasn't ready, then this
1243
+ /// will be set to `true`.
1244
+ signer_pending_closing: bool,
1240
1245
1241
1246
// pending_update_fee is filled when sending and receiving update_fee.
1242
1247
//
@@ -1268,7 +1273,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1268
1273
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1269
1274
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1270
1275
1271
- last_sent_closing_fee: Option<(u64, Signature)>, // (fee, holder_sig)
1276
+ // (fee, skip_remote_output, fee_range, holder_sig)
1277
+ last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
1278
+ last_received_closing_sig: Option<Signature>,
1272
1279
target_closing_feerate_sats_per_kw: Option<u32>,
1273
1280
1274
1281
/// If our counterparty sent us a closing_signed while we were waiting for a `ChannelMonitor`
@@ -1697,6 +1704,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1697
1704
signer_pending_revoke_and_ack: false,
1698
1705
signer_pending_commitment_update: false,
1699
1706
signer_pending_funding: false,
1707
+ signer_pending_closing: false,
1700
1708
1701
1709
1702
1710
#[cfg(debug_assertions)]
@@ -1705,6 +1713,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1705
1713
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
1706
1714
1707
1715
last_sent_closing_fee: None,
1716
+ last_received_closing_sig: None,
1708
1717
pending_counterparty_closing_signed: None,
1709
1718
expecting_peer_commitment_signed: false,
1710
1719
closing_fee_limits: None,
@@ -1923,6 +1932,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1923
1932
signer_pending_revoke_and_ack: false,
1924
1933
signer_pending_commitment_update: false,
1925
1934
signer_pending_funding: false,
1935
+ signer_pending_closing: false,
1926
1936
1927
1937
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
1928
1938
// when we receive `accept_channel2`.
@@ -1932,6 +1942,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1932
1942
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
1933
1943
1934
1944
last_sent_closing_fee: None,
1945
+ last_received_closing_sig: None,
1935
1946
pending_counterparty_closing_signed: None,
1936
1947
expecting_peer_commitment_signed: false,
1937
1948
closing_fee_limits: None,
@@ -5424,19 +5435,40 @@ impl<SP: Deref> Channel<SP> where
5424
5435
commitment_update = None;
5425
5436
}
5426
5437
5427
- log_trace!(logger, "Signer unblocked with {} commitment_update, {} revoke_and_ack, {} funding_signed and {} channel_ready, with resend order {:?}",
5438
+ let (closing_signed, signed_closing_tx) = if self.context.signer_pending_closing {
5439
+ debug_assert!(self.context.last_sent_closing_fee.is_some());
5440
+ if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
5441
+ debug_assert!(holder_sig.is_none());
5442
+ log_trace!(logger, "Attempting to generate pending closing_signed...");
5443
+ let (closing_tx, fee) = self.build_closing_transaction(fee, skip_remote_output);
5444
+ let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output,
5445
+ fee, fee_range.min_fee_satoshis, fee_range.max_fee_satoshis, logger);
5446
+ let signed_tx = if let (Some(ClosingSigned { signature, .. }), Some(counterparty_sig)) =
5447
+ (closing_signed.as_ref(), self.context.last_received_closing_sig) {
5448
+ Some(self.build_signed_closing_transaction(&closing_tx, &counterparty_sig, signature))
5449
+ } else { None };
5450
+ (closing_signed, signed_tx)
5451
+ } else { (None, None) }
5452
+ } else { (None, None) };
5453
+
5454
+ log_trace!(logger, "Signer unblocked with {} commitment_update, {} revoke_and_ack, with resend order {:?}, {} funding_signed, {} channel_ready,
5455
+ {} closing_signed, and {} signed_closing_tx",
5428
5456
if commitment_update.is_some() { "a" } else { "no" },
5429
5457
if revoke_and_ack.is_some() { "a" } else { "no" },
5458
+ self.context.resend_order,
5430
5459
if funding_signed.is_some() { "a" } else { "no" },
5431
5460
if channel_ready.is_some() { "a" } else { "no" },
5432
- self.context.resend_order);
5461
+ if closing_signed.is_some() { "a" } else { "no" },
5462
+ if signed_closing_tx.is_some() { "a" } else { "no" });
5433
5463
5434
5464
SignerResumeUpdates {
5435
5465
commitment_update,
5436
5466
revoke_and_ack,
5437
5467
funding_signed,
5438
5468
channel_ready,
5439
5469
order: self.context.resend_order.clone(),
5470
+ closing_signed,
5471
+ signed_closing_tx,
5440
5472
}
5441
5473
}
5442
5474
@@ -5851,9 +5883,6 @@ impl<SP: Deref> Channel<SP> where
5851
5883
our_min_fee, our_max_fee, total_fee_satoshis);
5852
5884
5853
5885
let closing_signed = self.get_closing_signed_msg(&closing_tx, false, total_fee_satoshis, our_min_fee, our_max_fee, logger);
5854
- if closing_signed.is_none() {
5855
- return Err(ChannelError::close("Failed to get signature for closing transaction.".to_owned()));
5856
- }
5857
5886
Ok((closing_signed, None, None))
5858
5887
}
5859
5888
@@ -6007,26 +6036,26 @@ impl<SP: Deref> Channel<SP> where
6007
6036
) -> Option<msgs::ClosingSigned>
6008
6037
where L::Target: Logger
6009
6038
{
6010
- match &self.context.holder_signer {
6011
- ChannelSignerType::Ecdsa(ecdsa) => {
6012
- let fee_range = msgs::ClosingSignedFeeRange {
6013
- min_fee_satoshis,
6014
- max_fee_satoshis,
6015
- };
6016
- let sig = ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok()?;
6017
-
6018
- self.context.last_sent_closing_fee = Some((fee_satoshis, sig.clone()));
6019
- Some(msgs::ClosingSigned {
6020
- channel_id: self.context.channel_id,
6021
- fee_satoshis,
6022
- signature: sig,
6023
- fee_range: Some(fee_range),
6024
- })
6025
- },
6039
+ let sig = match &self.context.holder_signer {
6040
+ ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok(),
6026
6041
// TODO (taproot|arik)
6027
6042
#[cfg(taproot)]
6028
6043
_ => todo!()
6044
+ };
6045
+ if sig.is_none() {
6046
+ log_trace!(logger, "Closing transaction signature unavailable, waiting on signer");
6047
+ self.context.signer_pending_closing = true;
6048
+ } else {
6049
+ self.context.signer_pending_closing = false;
6029
6050
}
6051
+ let fee_range = msgs::ClosingSignedFeeRange { min_fee_satoshis, max_fee_satoshis };
6052
+ self.context.last_sent_closing_fee = Some((fee_satoshis, skip_remote_output, fee_range.clone(), sig.clone()));
6053
+ sig.map(|signature| msgs::ClosingSigned {
6054
+ channel_id: self.context.channel_id,
6055
+ fee_satoshis,
6056
+ signature,
6057
+ fee_range: Some(fee_range),
6058
+ })
6030
6059
}
6031
6060
6032
6061
pub fn closing_signed<F: Deref, L: Deref>(
@@ -6089,7 +6118,7 @@ impl<SP: Deref> Channel<SP> where
6089
6118
};
6090
6119
6091
6120
assert!(self.context.shutdown_scriptpubkey.is_some());
6092
- if let Some((last_fee, sig)) = self.context.last_sent_closing_fee {
6121
+ if let Some((last_fee, _, _, Some( sig) )) = self.context.last_sent_closing_fee {
6093
6122
if last_fee == msg.fee_satoshis {
6094
6123
let shutdown_result = ShutdownResult {
6095
6124
closure_reason,
@@ -6122,9 +6151,6 @@ impl<SP: Deref> Channel<SP> where
6122
6151
};
6123
6152
6124
6153
let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output, used_fee, our_min_fee, our_max_fee, logger);
6125
- if closing_signed.is_none() {
6126
- return Err(ChannelError::close("Failed to get signature for closing transaction.".to_owned()));
6127
- }
6128
6154
let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis {
6129
6155
let shutdown_result = ShutdownResult {
6130
6156
closure_reason,
@@ -6140,6 +6166,7 @@ impl<SP: Deref> Channel<SP> where
6140
6166
};
6141
6167
self.context.channel_state = ChannelState::ShutdownComplete;
6142
6168
self.context.update_time_counter += 1;
6169
+ self.context.last_received_closing_sig = Some(msg.signature.clone());
6143
6170
let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }|
6144
6171
self.build_signed_closing_transaction(&closing_tx, &msg.signature, signature));
6145
6172
(tx, Some(shutdown_result))
@@ -6177,7 +6204,7 @@ impl<SP: Deref> Channel<SP> where
6177
6204
} else {
6178
6205
// Old fee style negotiation. We don't bother to enforce whether they are complying
6179
6206
// with the "making progress" requirements, we just comply and hope for the best.
6180
- if let Some((last_fee, _)) = self.context.last_sent_closing_fee {
6207
+ if let Some((last_fee, _, _, _ )) = self.context.last_sent_closing_fee {
6181
6208
if msg.fee_satoshis > last_fee {
6182
6209
if msg.fee_satoshis < our_max_fee {
6183
6210
propose_fee!(msg.fee_satoshis);
@@ -9333,6 +9360,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9333
9360
signer_pending_revoke_and_ack: false,
9334
9361
signer_pending_commitment_update: false,
9335
9362
signer_pending_funding: false,
9363
+ signer_pending_closing: false,
9336
9364
9337
9365
pending_update_fee,
9338
9366
holding_cell_update_fee,
@@ -9347,6 +9375,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9347
9375
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
9348
9376
9349
9377
last_sent_closing_fee: None,
9378
+ last_received_closing_sig: None,
9350
9379
pending_counterparty_closing_signed: None,
9351
9380
expecting_peer_commitment_signed: false,
9352
9381
closing_fee_limits: None,
0 commit comments