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

Function trim_maximum_feerate

onchaind/onchaind.c:167–211  ·  view source on GitHub ↗

The feerate for the HTLC txs (which we grind) are the same as the * feerate for the main tx. However, there may be dust HTLCs which * were added to the fee, so we can only estimate a maximum feerate */

Source from the content-addressed store, hash-verified

165 * feerate for the main tx. However, there may be dust HTLCs which
166 * were added to the fee, so we can only estimate a maximum feerate */
167static void trim_maximum_feerate(struct amount_sat funding,
168 const struct tx_parts *commitment)
169{
170 size_t weight;
171 struct amount_sat fee = funding;
172
173 /* FIXME: This doesn't work for elements? */
174 if (chainparams->is_elements)
175 return;
176
177 weight = bitcoin_tx_core_weight(tal_count(commitment->inputs),
178 tal_count(commitment->outputs));
179
180 /* BOLT #3:
181 * ## Commitment Transaction
182 *...
183 * * `txin[0]` script bytes: 0
184 * * `txin[0]` witness: `0 <signature_for_pubkey1> <signature_for_pubkey2>`
185 */
186 /* Account for witness (1 empty + sig + sig) */
187 assert(tal_count(commitment->inputs) == 1);
188 weight += bitcoin_tx_input_weight(false, 1 + 2 * bitcoin_tx_input_sig_weight());
189
190 for (size_t i = 0; i < tal_count(commitment->outputs); i++) {
191 struct amount_asset amt;
192 weight += bitcoin_tx_output_weight(commitment->outputs[i]
193 ->script_len);
194
195 amt = wally_tx_output_get_amount(commitment->outputs[i]);
196 if (!amount_asset_is_main(&amt))
197 continue;
198 if (!amount_sat_sub(&fee, fee, amount_asset_to_sat(&amt))) {
199 status_failed(STATUS_FAIL_INTERNAL_ERROR,
200 "Unable to subtract fee");
201 }
202 }
203
204 status_debug("reducing max_possible_feerate from %u...",
205 max_possible_feerate);
206 /* This is naive, but simple. */
207 while (amount_sat_greater(amount_tx_fee(max_possible_feerate, weight),
208 fee))
209 max_possible_feerate--;
210 status_debug("... to %u", max_possible_feerate);
211}
212
213static void send_coin_mvt(struct chain_coin_mvt *mvt TAKES)
214{

Callers 1

mainFunction · 0.85

Calls 11

bitcoin_tx_core_weightFunction · 0.85
bitcoin_tx_input_weightFunction · 0.85
bitcoin_tx_output_weightFunction · 0.85
amount_sat_greaterFunction · 0.85
amount_asset_is_mainFunction · 0.50
amount_sat_subFunction · 0.50
amount_asset_to_satFunction · 0.50
status_failedFunction · 0.50
amount_tx_feeFunction · 0.50

Tested by

no test coverage detected