@@ -909,6 +909,8 @@ pub(super) struct SignerResumeUpdates {
909
909
pub commitment_update: Option<msgs::CommitmentUpdate>,
910
910
pub funding_signed: Option<msgs::FundingSigned>,
911
911
pub channel_ready: Option<msgs::ChannelReady>,
912
+ pub closing_signed: Option<msgs::ClosingSigned>,
913
+ pub signed_closing_tx: Option<Transaction>,
912
914
}
913
915
914
916
/// The return value of `channel_reestablish`
@@ -1227,6 +1229,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1227
1229
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
1228
1230
/// outbound or inbound.
1229
1231
signer_pending_funding: bool,
1232
+ /// If we attempted to sign a cooperative close transaction but the signer wasn't ready, then this
1233
+ /// will be set to `true`.
1234
+ signer_pending_closing: bool,
1230
1235
1231
1236
// pending_update_fee is filled when sending and receiving update_fee.
1232
1237
//
@@ -1258,7 +1263,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1258
1263
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
1259
1264
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
1260
1265
1261
- last_sent_closing_fee: Option<(u64, Signature)>, // (fee, holder_sig)
1266
+ // (fee, skip_remote_output, fee_range, holder_sig)
1267
+ last_sent_closing_fee: Option<(u64, bool, ClosingSignedFeeRange, Option<Signature>)>,
1268
+ last_received_closing_sig: Option<Signature>,
1262
1269
target_closing_feerate_sats_per_kw: Option<u32>,
1263
1270
1264
1271
/// If our counterparty sent us a closing_signed while we were waiting for a `ChannelMonitor`
@@ -1686,6 +1693,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1686
1693
1687
1694
signer_pending_commitment_update: false,
1688
1695
signer_pending_funding: false,
1696
+ signer_pending_closing: false,
1689
1697
1690
1698
1691
1699
#[cfg(debug_assertions)]
@@ -1694,6 +1702,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1694
1702
counterparty_max_commitment_tx_output: Mutex::new((value_to_self_msat, (channel_value_satoshis * 1000 - msg_push_msat).saturating_sub(value_to_self_msat))),
1695
1703
1696
1704
last_sent_closing_fee: None,
1705
+ last_received_closing_sig: None,
1697
1706
pending_counterparty_closing_signed: None,
1698
1707
expecting_peer_commitment_signed: false,
1699
1708
closing_fee_limits: None,
@@ -1911,6 +1920,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1911
1920
1912
1921
signer_pending_commitment_update: false,
1913
1922
signer_pending_funding: false,
1923
+ signer_pending_closing: false,
1914
1924
1915
1925
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
1916
1926
// when we receive `accept_channel2`.
@@ -1920,6 +1930,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1920
1930
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
1921
1931
1922
1932
last_sent_closing_fee: None,
1933
+ last_received_closing_sig: None,
1923
1934
pending_counterparty_closing_signed: None,
1924
1935
expecting_peer_commitment_signed: false,
1925
1936
closing_fee_limits: None,
@@ -5387,15 +5398,37 @@ impl<SP: Deref> Channel<SP> where
5387
5398
self.check_get_channel_ready(0, logger)
5388
5399
} else { None };
5389
5400
5390
- log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
5401
+ let (closing_signed, signed_closing_tx) = if self.context.signer_pending_closing {
5402
+ debug_assert!(self.context.last_sent_closing_fee.is_some());
5403
+ if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
5404
+ debug_assert!(holder_sig.is_none());
5405
+ log_trace!(logger, "Attempting to generate pending closing_signed...");
5406
+ self.context.signer_pending_closing = false;
5407
+
5408
+ let (closing_tx, fee) = self.build_closing_transaction(fee, skip_remote_output);
5409
+ let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output,
5410
+ fee, fee_range.min_fee_satoshis, fee_range.max_fee_satoshis, logger);
5411
+ let signed_tx = if let (Some(ClosingSigned { signature, .. }), Some(counterparty_sig)) =
5412
+ (closing_signed.as_ref(), self.context.last_received_closing_sig) {
5413
+ Some(self.build_signed_closing_transaction(&closing_tx, &counterparty_sig, signature))
5414
+ } else { None };
5415
+ (closing_signed, signed_tx)
5416
+ } else { (None, None) }
5417
+ } else { (None, None) };
5418
+
5419
+ log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed, {} channel_ready, {} closing_signed, and {} signed_closing_tx",
5391
5420
if commitment_update.is_some() { "a" } else { "no" },
5392
5421
if funding_signed.is_some() { "a" } else { "no" },
5393
- if channel_ready.is_some() { "a" } else { "no" });
5422
+ if channel_ready.is_some() { "a" } else { "no" },
5423
+ if closing_signed.is_some() { "a" } else { "no" },
5424
+ if signed_closing_tx.is_some() { "a" } else { "no" });
5394
5425
5395
5426
SignerResumeUpdates {
5396
5427
commitment_update,
5397
5428
funding_signed,
5398
5429
channel_ready,
5430
+ closing_signed,
5431
+ signed_closing_tx,
5399
5432
}
5400
5433
}
5401
5434
@@ -5801,9 +5834,6 @@ impl<SP: Deref> Channel<SP> where
5801
5834
our_min_fee, our_max_fee, total_fee_satoshis);
5802
5835
5803
5836
let closing_signed = self.get_closing_signed_msg(&closing_tx, false, total_fee_satoshis, our_min_fee, our_max_fee, logger);
5804
- if closing_signed.is_none() {
5805
- return Err(ChannelError::close("Failed to get signature for closing transaction.".to_owned()));
5806
- }
5807
5837
Ok((closing_signed, None, None))
5808
5838
}
5809
5839
@@ -5963,13 +5993,17 @@ impl<SP: Deref> Channel<SP> where
5963
5993
min_fee_satoshis,
5964
5994
max_fee_satoshis,
5965
5995
};
5966
- let sig = ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok()?;
5996
+ let sig = ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok();
5997
+ if sig.is_none() {
5998
+ log_trace!(logger, "Closing transaction signature unavailable, waiting on signer");
5999
+ self.context.signer_pending_closing = true;
6000
+ }
5967
6001
5968
- self.context.last_sent_closing_fee = Some((fee_satoshis, sig.clone()));
5969
- Some( msgs::ClosingSigned {
6002
+ self.context.last_sent_closing_fee = Some((fee_satoshis, skip_remote_output, fee_range.clone(), sig.clone()));
6003
+ sig.map(|signature| msgs::ClosingSigned {
5970
6004
channel_id: self.context.channel_id,
5971
6005
fee_satoshis,
5972
- signature: sig ,
6006
+ signature,
5973
6007
fee_range: Some(fee_range),
5974
6008
})
5975
6009
},
@@ -6039,7 +6073,7 @@ impl<SP: Deref> Channel<SP> where
6039
6073
};
6040
6074
6041
6075
assert!(self.context.shutdown_scriptpubkey.is_some());
6042
- if let Some((last_fee, sig)) = self.context.last_sent_closing_fee {
6076
+ if let Some((last_fee, _, _, Some( sig) )) = self.context.last_sent_closing_fee {
6043
6077
if last_fee == msg.fee_satoshis {
6044
6078
let shutdown_result = ShutdownResult {
6045
6079
closure_reason,
@@ -6072,9 +6106,6 @@ impl<SP: Deref> Channel<SP> where
6072
6106
};
6073
6107
6074
6108
let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output, used_fee, our_min_fee, our_max_fee, logger);
6075
- if closing_signed.is_none() {
6076
- return Err(ChannelError::close("Failed to get signature for closing transaction.".to_owned()));
6077
- }
6078
6109
let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis {
6079
6110
let shutdown_result = ShutdownResult {
6080
6111
closure_reason,
@@ -6090,6 +6121,7 @@ impl<SP: Deref> Channel<SP> where
6090
6121
};
6091
6122
self.context.channel_state = ChannelState::ShutdownComplete;
6092
6123
self.context.update_time_counter += 1;
6124
+ self.context.last_received_closing_sig = Some(msg.signature.clone());
6093
6125
let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }|
6094
6126
self.build_signed_closing_transaction(&closing_tx, &msg.signature, signature));
6095
6127
(tx, Some(shutdown_result))
@@ -6127,7 +6159,7 @@ impl<SP: Deref> Channel<SP> where
6127
6159
} else {
6128
6160
// Old fee style negotiation. We don't bother to enforce whether they are complying
6129
6161
// with the "making progress" requirements, we just comply and hope for the best.
6130
- if let Some((last_fee, _)) = self.context.last_sent_closing_fee {
6162
+ if let Some((last_fee, _, _, _ )) = self.context.last_sent_closing_fee {
6131
6163
if msg.fee_satoshis > last_fee {
6132
6164
if msg.fee_satoshis < our_max_fee {
6133
6165
propose_fee!(msg.fee_satoshis);
@@ -9282,6 +9314,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9282
9314
9283
9315
signer_pending_commitment_update: false,
9284
9316
signer_pending_funding: false,
9317
+ signer_pending_closing: false,
9285
9318
9286
9319
pending_update_fee,
9287
9320
holding_cell_update_fee,
@@ -9296,6 +9329,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9296
9329
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
9297
9330
9298
9331
last_sent_closing_fee: None,
9332
+ last_received_closing_sig: None,
9299
9333
pending_counterparty_closing_signed: None,
9300
9334
expecting_peer_commitment_signed: false,
9301
9335
closing_fee_limits: None,
0 commit comments