Get UTXOs, create a PSBT to spend this */
| 290 | |
| 291 | /* Get UTXOs, create a PSBT to spend this */ |
| 292 | static 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. */ |
| 333 | static struct bitcoin_tx *spend_anchor(const tal_t *ctx, |
no test coverage detected