Assess whether a proposed closing fee is acceptable. */
| 196 | |
| 197 | /* Assess whether a proposed closing fee is acceptable. */ |
| 198 | static bool closing_fee_is_acceptable(struct lightningd *ld, |
| 199 | struct channel *channel, |
| 200 | const struct bitcoin_tx *tx) |
| 201 | { |
| 202 | struct amount_sat fee, last_fee, min_fee; |
| 203 | u64 weight; |
| 204 | u32 min_feerate; |
| 205 | bool feerate_unknown; |
| 206 | |
| 207 | /* Calculate actual fee (adds in eliminated outputs) */ |
| 208 | fee = calc_tx_fee(channel->funding_sats, tx); |
| 209 | last_fee = calc_tx_fee(channel->funding_sats, channel->last_tx); |
| 210 | |
| 211 | /* Weight once we add in sigs. */ |
| 212 | assert(!tx->wtx->inputs[0].witness |
| 213 | || tx->wtx->inputs[0].witness->num_items == 0); |
| 214 | weight = bitcoin_tx_weight(tx) + bitcoin_tx_2of2_input_witness_weight(); |
| 215 | |
| 216 | log_debug(channel->log, "Their actual closing tx fee is %s" |
| 217 | " vs previous %s: weight is %"PRIu64, |
| 218 | type_to_string(tmpctx, struct amount_sat, &fee), |
| 219 | type_to_string(tmpctx, struct amount_sat, &last_fee), |
| 220 | weight); |
| 221 | |
| 222 | /* If we don't have a feerate estimate, this gives feerate_floor */ |
| 223 | min_feerate = feerate_min(ld, &feerate_unknown); |
| 224 | |
| 225 | min_fee = amount_tx_fee(min_feerate, weight); |
| 226 | if (amount_sat_less(fee, min_fee)) { |
| 227 | log_debug(channel->log, "... That's below our min %s" |
| 228 | " for weight %"PRIu64" at feerate %u", |
| 229 | type_to_string(tmpctx, struct amount_sat, &min_fee), |
| 230 | weight, min_feerate); |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | /* Prefer new over old: this covers the preference |
| 235 | * for a mutual close over a unilateral one. */ |
| 236 | |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | static void peer_received_closing_signature(struct channel *channel, |
| 241 | const u8 *msg) |
no test coverage detected