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
Clean up existing and add range-based closing_signed negotiation
This adds the new range-based closing_signed negotiation specified
in lightning/bolts#847 as
well as cleans up the existing closing_signed negotiation to unify
the new codepaths and the old ones.
Note that because the new range-based closing_signed negotiation
allows the channel fundee to ultimately select the fee out of a
range specified by the funder, which we, of course, always select
the highest allowed amount from. Thus, we've added an extra round
of closing_signed in the common case as we will not simply accept
the first fee we see, always preferring to make the funder pay as
much as they're willing to.
// Note that technically we could end up with a lower minimum fee if one sides' balance is
3149
+
// below our dust limit, causing the output to disappear. We don't bother handling this
3150
+
// case, however, as this should only happen if a channel is closed before any (material)
3151
+
// payments have been made on it. This may cause slight fee overpayment and/or failure to
3152
+
// come to consensus with our counterparty on appropriate fees, however it should be a
3153
+
// relatively rare case. We can revisit this later, though note that in order to determine
3154
+
// if the funders' output is dust we have to know the absolute fee we're going to use.
3155
+
let tx_weight = self.get_closing_transaction_weight(Some(&self.get_closing_scriptpubkey()),Some(self.counterparty_shutdown_scriptpubkey.as_ref().unwrap()));
3156
+
let proposed_total_fee_satoshis = proposed_feerate asu64* tx_weight / 1000;
3157
+
let proposed_max_total_fee_satoshis = ifself.is_outbound(){
let tx_weight = self.get_closing_transaction_weight(Some(&self.get_closing_scriptpubkey()),Some(self.counterparty_shutdown_scriptpubkey.as_ref().unwrap()));
3133
-
let proposed_total_fee_satoshis = proposed_feerate asu64* tx_weight / 1000;
3134
-
log_trace!(logger,"Proposing initial closing signed for our counterparty with a feerate of {} sat/kWeight (= {} sats)",
let tx_weight = self.get_closing_transaction_weight(Some(&self.get_closing_scriptpubkey()),Some(self.counterparty_shutdown_scriptpubkey.as_ref().unwrap()));
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote wanted something higher ({}) than our Normal feerate ({})", last_feerate, max_feerate)));
if msg.fee_satoshis < min_fee_satoshis || msg.fee_satoshis > max_fee_satoshis {
3375
+
returnErr(ChannelError::Close(format!("Peer sent a bogus closing_signed - suggested fee of {} sat was not in their desired range of {} sat - {} sat", msg.fee_satoshis, min_fee_satoshis, max_fee_satoshis)));
3376
+
}
3377
+
if max_fee_satoshis < our_min_fee {
3378
+
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote's max fee ({} sat) was smaller than our min fee ({} sat)", max_fee_satoshis, our_min_fee)));
3379
+
}
3380
+
if min_fee_satoshis > our_max_fee {
3381
+
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote's min fee ({} sat) was greater than our max fee ({} sat)", min_fee_satoshis, our_max_fee)));
3382
+
}
3383
+
3384
+
if !self.is_outbound(){
3385
+
// They have to pay, so pick the highest fee in the overlapping range.
3386
+
debug_assert_eq!(our_max_fee,u64::max_value());// Note that we always allow any fee
if msg.fee_satoshis < our_min_fee || msg.fee_satoshis > our_max_fee {
3390
+
returnErr(ChannelError::Close(format!("Peer sent a bogus closing_signed - suggested fee of {} sat was not in our desired range of {} sat - {} sat after we informed them of our range.",
3391
+
msg.fee_satoshis, our_min_fee, our_max_fee)));
3314
3392
}
3315
-
propose_new_feerate!(max_feerate);
3393
+
// The proposed fee is in our acceptable range, accept it and broadcast!
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote wanted something lower ({}) than our Background feerate ({}).", last_feerate, min_feerate)));
3397
+
// Old fee style negotiation. We don't bother to enforce whether they are complying
3398
+
// with the "making progress" requirements, we just comply and hope for the best.
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote wants something ({} sat) higher than our max fee ({} sat)", msg.fee_satoshis, our_max_fee)));
3407
+
}
3408
+
}else{
3409
+
if msg.fee_satoshis > our_min_fee {
3410
+
propose_new_fee!(msg.fee_satoshis);
3411
+
}elseif last_fee > our_min_fee {
3412
+
propose_new_fee!(our_min_fee);
3413
+
}else{
3414
+
returnErr(ChannelError::Close(format!("Unable to come to consensus about closing feerate, remote wants something ({} sat) lower than our min fee ({} sat)", msg.fee_satoshis, our_min_fee)));
0 commit comments