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

Function wallet_utxo_boost

wallet/wallet.c:642–711  ·  view source on GitHub ↗

Gather enough utxos to meet feerate, otherwise all we can. */

Source from the content-addressed store, hash-verified

640
641/* Gather enough utxos to meet feerate, otherwise all we can. */
642struct utxo **wallet_utxo_boost(const tal_t *ctx,
643 struct wallet *w,
644 u32 blockheight,
645 struct amount_sat excess_sats,
646 struct amount_sat output_sats_required,
647 u32 feerate_target,
648 size_t *weight,
649 bool *insufficient)
650{
651 struct utxo **all_utxos = wallet_get_unspent_utxos(tmpctx, w);
652 struct utxo **utxos = tal_arr(ctx, struct utxo *, 0);
653 u32 feerate;
654
655 /* Select in random order */
656 tal_arr_randomize(all_utxos, struct utxo *);
657
658 feerate = calc_feerate(excess_sats, output_sats_required, *weight);
659
660 for (size_t i = 0; i < tal_count(all_utxos); i++) {
661 u32 new_feerate;
662 size_t new_weight;
663 struct amount_sat new_excess_sats;
664 /* Convenience var */
665 struct utxo *utxo = all_utxos[i];
666
667 /* Are we already happy? */
668 if (feerate >= feerate_target) {
669 log_debug(w->log, "wallet_utxo_boost: got %zu UTXOs, excess %s (needed %s), weight %zu, feerate %u >= %u",
670 tal_count(utxos),
671 fmt_amount_sat(tmpctx, excess_sats),
672 fmt_amount_sat(tmpctx, output_sats_required),
673 *weight, feerate, feerate_target);
674 if (insufficient)
675 *insufficient = false;
676 return utxos;
677 }
678
679 /* Don't add reserved ones */
680 if (utxo_is_reserved(utxo, blockheight))
681 continue;
682
683 /* Don't add csv-locked ones */
684 if (utxo_is_csv_locked(utxo, blockheight))
685 continue;
686
687 /* UTXOs must be sane amounts */
688 if (!amount_sat_add(&new_excess_sats,
689 excess_sats, utxo->amount))
690 abort();
691
692 new_weight = *weight + utxo_spend_weight(utxo, 0);
693 new_feerate = calc_feerate(new_excess_sats, output_sats_required,
694 new_weight);
695
696 /* Don't add uneconomic ones! */
697 if (new_feerate < feerate)
698 continue;
699

Callers 2

try_anchor_psbtFunction · 0.85

Calls 8

wallet_get_unspent_utxosFunction · 0.85
calc_feerateFunction · 0.85
utxo_is_reservedFunction · 0.85
utxo_is_csv_lockedFunction · 0.85
abortFunction · 0.85
utxo_spend_weightFunction · 0.85
fmt_amount_satFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected