You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following up on the previous commit, where we added debug_asserts
within `build_closing_transaction` to ensure neither
`value_to_holder` nor `value_to_counterparty` underflow, we now also
force-close the channel in the (presumably impossible) event that it
did happen.
@@ -4369,11 +4369,17 @@ impl<SP: Deref> Channel<SP> where
4369
4369
}
4370
4370
4371
4371
debug_assert!(value_to_counterparty >= 0);
4372
+
if value_to_counterparty < 0 {
4373
+
return Err(ChannelError::close(format!("Value to counterparty below 0: {}", value_to_counterparty)))
4374
+
}
4372
4375
if skip_remote_output || value_to_counterparty as u64 <= self.context.holder_dust_limit_satoshis {
4373
4376
value_to_counterparty = 0;
4374
4377
}
4375
4378
4376
4379
debug_assert!(value_to_holder >= 0);
4380
+
if value_to_holder < 0 {
4381
+
return Err(ChannelError::close(format!("Value to holder below 0: {}", value_to_holder)))
4382
+
}
4377
4383
if value_to_holder as u64 <= self.context.holder_dust_limit_satoshis {
4378
4384
value_to_holder = 0;
4379
4385
}
@@ -4384,7 +4390,7 @@ impl<SP: Deref> Channel<SP> where
4384
4390
let funding_outpoint = self.funding_outpoint().into_bitcoin_outpoint();
4385
4391
4386
4392
let closing_transaction = ClosingTransaction::new(value_to_holder as u64, value_to_counterparty as u64, holder_shutdown_script, counterparty_shutdown_script, funding_outpoint);
4387
-
(closing_transaction, total_fee_satoshis)
4393
+
Ok((closing_transaction, total_fee_satoshis))
4388
4394
}
4389
4395
4390
4396
fn funding_outpoint(&self) -> OutPoint {
@@ -6138,19 +6144,27 @@ impl<SP: Deref> Channel<SP> where
6138
6144
if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
6139
6145
debug_assert!(holder_sig.is_none());
6140
6146
log_trace!(logger, "Attempting to generate pending closing_signed...");
6141
-
let (closing_tx, fee) = self.build_closing_transaction(fee, skip_remote_output);
6142
-
let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output,
let (closing_tx, total_fee_satoshis) = self.build_closing_transaction(our_min_fee, false);
6635
+
let (closing_tx, total_fee_satoshis) = self.build_closing_transaction(our_min_fee, false)?;
6622
6636
log_trace!(logger, "Proposing initial closing_signed for our counterparty with a fee range of {}-{} sat (with initial proposal {} sats)",
6623
6637
our_min_fee, our_max_fee, total_fee_satoshis);
6624
6638
@@ -6852,7 +6866,7 @@ impl<SP: Deref> Channel<SP> where
6852
6866
6853
6867
let funding_redeemscript = self.context.get_funding_redeemscript();
6854
6868
let mut skip_remote_output = false;
6855
-
let (mut closing_tx, used_total_fee) = self.build_closing_transaction(msg.fee_satoshis, skip_remote_output);
6869
+
let (mut closing_tx, used_total_fee) = self.build_closing_transaction(msg.fee_satoshis, skip_remote_output)?;
6856
6870
if used_total_fee != msg.fee_satoshis {
6857
6871
return Err(ChannelError::close(format!("Remote sent us a closing_signed with a fee other than the value they can claim. Fee in message: {}. Actual closing tx fee: {}", msg.fee_satoshis, used_total_fee)));
6858
6872
}
@@ -6864,7 +6878,7 @@ impl<SP: Deref> Channel<SP> where
6864
6878
// The remote end may have decided to revoke their output due to inconsistent dust
6865
6879
// limits, so check for that case by re-checking the signature here.
0 commit comments