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

Function trim_maximum_feerate

onchaind/onchaind.c:164–208  ·  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

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

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