@@ -883,57 +883,46 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel,
883
883
/* Make a copy to play with */
884
884
newtx = clone_bitcoin_tx (tmpctx , info -> raw_htlc_tx );
885
885
weight = bitcoin_tx_weight (newtx );
886
- utxos = tal_arr (tmpctx , struct utxo * , 0 );
887
886
888
887
/* We'll need this to regenerate PSBT */
889
888
if (wally_psbt_get_locktime (newtx -> psbt , & locktime ) != WALLY_OK ) {
890
889
log_broken (channel -> log , "Cannot get psbt locktime?!" );
891
890
return true;
892
891
}
893
892
894
- /* Keep attaching input inputs until we get sufficient fees */
895
- while (tx_feerate (newtx ) < feerate ) {
896
- struct utxo * utxo ;
897
-
898
- /* Get fresh utxo */
899
- utxo = wallet_find_utxo (tmpctx , ld -> wallet ,
900
- get_block_height (ld -> topology ),
901
- NULL ,
902
- 0 , /* FIXME: unused! */
903
- 0 , false,
904
- cast_const2 (const struct utxo * * , utxos ));
905
- if (!utxo ) {
906
- /* Did we get nothing at all? */
907
- if (tal_count (utxos ) == 0 ) {
908
- log_unusual (channel -> log ,
909
- "We want to bump HTLC fee, but no funds!" );
910
- return true;
911
- }
912
- /* At least we got something, right? */
913
- break ;
914
- }
915
-
916
- /* Add to any UTXOs we have already */
917
- tal_arr_expand (& utxos , utxo );
918
- weight += bitcoin_tx_simple_input_weight (utxo -> is_p2sh );
919
- }
920
-
921
- /* We were happy with feerate already (can't happen with zero-fee
922
- * anchors!)? */
923
- if (tal_count (utxos ) == 0 )
924
- return true;
893
+ utxos = wallet_utxo_boost (tmpctx ,
894
+ ld -> wallet ,
895
+ get_block_height (ld -> topology ),
896
+ bitcoin_tx_compute_fee (newtx ),
897
+ feerate ,
898
+ & weight );
925
899
926
- /* PSBT knows how to spend utxos; append to existing. */
900
+ /* Add those to create a new PSBT */
927
901
psbt = psbt_using_utxos (tmpctx , ld -> wallet , utxos , locktime ,
928
902
BITCOIN_TX_RBF_SEQUENCE , newtx -> psbt );
929
903
930
904
/* Subtract how much we pay in fees for this tx, to calc excess. */
931
905
if (!amount_sat_sub (& excess ,
932
906
psbt_compute_fee (psbt ),
933
- amount_sat ((u64 )weight * feerate / 1000 ))) {
907
+ amount_tx_fee (feerate , weight ))) {
908
+ /* We didn't make the feerate. Did we get nothing at all? */
909
+ if (tal_count (utxos ) == 0 ) {
910
+ log_unusual (channel -> log ,
911
+ "We want to bump HTLC fee, but no funds!" );
912
+ return true;
913
+ }
914
+ /* At least we got something! */
915
+ log_unusual (channel -> log ,
916
+ "We want to bump HTLC fee more, but ran out of funds!" );
934
917
excess = AMOUNT_SAT (0 );
935
918
}
936
919
920
+ /* We were happy with feerate already (can't happen with zero-fee
921
+ * anchors!)? */
922
+ if (tal_count (utxos ) == 0 )
923
+ return true;
924
+
925
+ /* Maybe add change */
937
926
change = change_amount (excess , feerate , weight );
938
927
if (!amount_sat_eq (change , AMOUNT_SAT (0 ))) {
939
928
/* Append change output. */
0 commit comments