lightningd: use wallet_utxo_boost for zero-fee htlc_tx.

The previous logic looked wrong anyway!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-10-30 16:16:19 +10:30
parent e0c9abc2b3
commit ebf6f2e344

View File

@ -884,7 +884,6 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel,
/* Make a copy to play with */ /* Make a copy to play with */
newtx = clone_bitcoin_tx(tmpctx, info->raw_htlc_tx); newtx = clone_bitcoin_tx(tmpctx, info->raw_htlc_tx);
weight = bitcoin_tx_weight(newtx); weight = bitcoin_tx_weight(newtx);
utxos = tal_arr(tmpctx, struct utxo *, 0);
/* We'll need this to regenerate PSBT */ /* We'll need this to regenerate PSBT */
if (wally_psbt_get_locktime(newtx->psbt, &locktime) != WALLY_OK) { if (wally_psbt_get_locktime(newtx->psbt, &locktime) != WALLY_OK) {
@ -892,31 +891,31 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel,
return true; return true;
} }
/* Keep attaching input inputs until we get sufficient fees */ utxos = wallet_utxo_boost(tmpctx,
while (tx_feerate(newtx) < feerate) { ld->wallet,
struct utxo *utxo; get_block_height(ld->topology),
bitcoin_tx_compute_fee(newtx),
feerate,
&weight);
/* Get fresh utxo */ /* Add those to create a new PSBT */
utxo = wallet_find_utxo(tmpctx, ld->wallet, psbt = psbt_using_utxos(tmpctx, ld->wallet, utxos, locktime,
get_block_height(ld->topology), BITCOIN_TX_RBF_SEQUENCE, newtx->psbt);
NULL,
0, /* FIXME: unused! */ /* Subtract how much we pay in fees for this tx, to calc excess. */
0, false, if (!amount_sat_sub(&excess,
cast_const2(const struct utxo **, utxos)); psbt_compute_fee(psbt),
if (!utxo) { amount_tx_fee(feerate, weight))) {
/* Did we get nothing at all? */ /* We didn't make the feerate. Did we get nothing at all? */
if (tal_count(utxos) == 0) { if (tal_count(utxos) == 0) {
log_unusual(channel->log, log_unusual(channel->log,
"We want to bump HTLC fee, but no funds!"); "We want to bump HTLC fee, but no funds!");
return true; return true;
}
/* At least we got something, right? */
break;
} }
/* At least we got something! */
/* Add to any UTXOs we have already */ log_unusual(channel->log,
tal_arr_expand(&utxos, utxo); "We want to bump HTLC fee more, but ran out of funds!");
weight += bitcoin_tx_simple_input_weight(utxo->is_p2sh); excess = AMOUNT_SAT(0);
} }
/* We were happy with feerate already (can't happen with zero-fee /* We were happy with feerate already (can't happen with zero-fee
@ -924,17 +923,7 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel,
if (tal_count(utxos) == 0) if (tal_count(utxos) == 0)
return true; return true;
/* PSBT knows how to spend utxos; append to existing. */ /* Maybe add change */
psbt = psbt_using_utxos(tmpctx, ld->wallet, utxos, locktime,
BITCOIN_TX_RBF_SEQUENCE, newtx->psbt);
/* Subtract how much we pay in fees for this tx, to calc excess. */
if (!amount_sat_sub(&excess,
psbt_compute_fee(psbt),
amount_sat((u64)weight * feerate / 1000))) {
excess = AMOUNT_SAT(0);
}
change = change_amount(excess, feerate, weight); change = change_amount(excess, feerate, weight);
if (!amount_sat_eq(change, AMOUNT_SAT(0))) { if (!amount_sat_eq(change, AMOUNT_SAT(0))) {
/* Append change output. */ /* Append change output. */