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

Function try_anchor_psbt

lightningd/anchorspend.c:292–330  ·  view source on GitHub ↗

Get UTXOs, create a PSBT to spend this */

Source from the content-addressed store, hash-verified

290
291/* Get UTXOs, create a PSBT to spend this */
292static struct wally_psbt *try_anchor_psbt(const tal_t *ctx,
293 struct channel *channel,
294 const struct one_anchor *anch,
295 u32 feerate_target,
296 size_t base_weight,
297 size_t *total_weight,
298 struct amount_sat *fee_spent,
299 u32 *feerate,
300 struct utxo ***utxos)
301{
302 struct lightningd *ld = channel->peer->ld;
303 struct wally_psbt *psbt;
304 struct amount_sat fee;
305 bool insufficient_funds;
306
307 /* Ask for some UTXOs which could meet this feerate, and since
308 * we need one output, meet the minumum output requirement */
309 *total_weight = base_weight;
310 *utxos = wallet_utxo_boost(ctx,
311 ld->wallet,
312 get_block_height(ld->topology),
313 anch->info.commitment_fee,
314 chainparams->dust_limit,
315 feerate_target,
316 total_weight, &insufficient_funds);
317
318 /* Create a new candidate PSBT */
319 psbt = anchor_psbt(ctx, channel, anch, *utxos, feerate_target,
320 *total_weight, insufficient_funds);
321 *fee_spent = psbt_compute_fee(psbt);
322
323 /* Add in base commitment fee to calculate *overall* package feerate */
324 if (!amount_sat_add(&fee, *fee_spent, anch->info.commitment_fee))
325 abort();
326 if (!amount_feerate(feerate, fee, *total_weight))
327 abort();
328
329 return psbt;
330}
331
332/* If it's possible and worth it, return signed tx. Otherwise NULL. */
333static struct bitcoin_tx *spend_anchor(const tal_t *ctx,

Callers 1

spend_anchorFunction · 0.85

Calls 7

wallet_utxo_boostFunction · 0.85
anchor_psbtFunction · 0.85
psbt_compute_feeFunction · 0.85
abortFunction · 0.85
get_block_heightFunction · 0.70
amount_sat_addFunction · 0.50
amount_feerateFunction · 0.50

Tested by

no test coverage detected