Skip to content

Commit b348d9c

Browse files
committed
Reduce our stated max closing-transaction fee to be the true value
When communicating the maximum fee we're willing to accept on a cooperative closing transaction to our peer, we currently tell them we'll accept `u64::max_value()` if they're the ones who have to pay it. Spec-wise this is fine - they aren't allowed to try to claim our balance, and we don't care how much of their own funds they want to spend on transaction fees. However, the Eclair folks prefer to check all values on the wire do not exceed 21 million BTC, which seems like generally good practice to avoid overflows and such issues. Thus, our close messages are rejected by Eclair. Here we simply relax our stated maximum to be the real value - our counterparty's current balance in satoshis. Fixes #1071
1 parent 4c4d99b commit b348d9c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lightning/src/ln/channel.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ pub(super) struct Channel<Signer: Sign> {
459459
/// closing_signed message and handling it in `maybe_propose_closing_signed`.
460460
pending_counterparty_closing_signed: Option<msgs::ClosingSigned>,
461461

462-
/// The minimum and maximum absolute fee we are willing to place on the closing transaction.
463-
/// These are set once we reach `closing_negotiation_ready`.
462+
/// The minimum and maximum absolute fee, in satoshis, we are willing to place on the closing
463+
/// transaction. These are set once we reach `closing_negotiation_ready`.
464464
#[cfg(test)]
465465
pub(crate) closing_fee_limits: Option<(u64, u64)>,
466466
#[cfg(not(test))]
@@ -3444,7 +3444,7 @@ impl<Signer: Sign> Channel<Signer> {
34443444
cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.force_close_avoidance_max_fee_satoshis,
34453445
proposed_max_feerate as u64 * tx_weight / 1000)
34463446
} else {
3447-
u64::max_value()
3447+
self.channel_value_satoshis - (self.value_to_self_msat + 999) / 1000
34483448
};
34493449

34503450
self.closing_fee_limits = Some((proposed_total_fee_satoshis, proposed_max_total_fee_satoshis));
@@ -3732,7 +3732,8 @@ impl<Signer: Sign> Channel<Signer> {
37323732

37333733
if !self.is_outbound() {
37343734
// They have to pay, so pick the highest fee in the overlapping range.
3735-
debug_assert_eq!(our_max_fee, u64::max_value()); // We should never set an upper bound
3735+
// We should never set an upper bound aside from their full balance
3736+
debug_assert_eq!(our_max_fee, self.channel_value_satoshis - (self.value_to_self_msat + 999) / 1000);
37363737
propose_fee!(cmp::min(max_fee_satoshis, our_max_fee));
37373738
} else {
37383739
if msg.fee_satoshis < our_min_fee || msg.fee_satoshis > our_max_fee {

0 commit comments

Comments
 (0)