MCPcopy Create free account
hub / github.com/ElementsProject/lightning / closing_fee_is_acceptable

Function closing_fee_is_acceptable

lightningd/closing_control.c:197–240  ·  view source on GitHub ↗

Assess whether a proposed closing fee is acceptable. */

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 7

calc_tx_feeFunction · 0.85
bitcoin_tx_weightFunction · 0.85
feerate_minFunction · 0.85
amount_sat_lessFunction · 0.85
fmt_amount_satFunction · 0.50
amount_tx_feeFunction · 0.50

Tested by

no test coverage detected