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

Function handle_fee_and_ppm

plugins/spender/splice.c:1386–1633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1384}
1385
1386static struct command_result *handle_fee_and_ppm(struct command *cmd,
1387 struct splice_cmd *splice_cmd)
1388{
1389 struct command_result *result;
1390 struct amount_sat onchain_fee;
1391 size_t weight;
1392 struct amount_sat extra_funds, missing_funds, non_wallet_demand, sat;
1393 struct splice_script_result *funding_wallet_action = NULL;
1394 size_t funding_wallet_index;
1395
1396 funding_wallet_action = input_wallet(splice_cmd, &funding_wallet_index);
1397
1398 /* We calculate the weight with simulated wallet */
1399 weight = calc_weight(splice_cmd, true);
1400 onchain_fee = amount_tx_fee(splice_cmd->feerate_per_kw, weight);
1401
1402 plugin_log(cmd->plugin, LOG_INFORM,
1403 "Splice fee is %s at %"PRIu32" perkw (%.02f sat/vB) "
1404 "on tx where our weight units are %zu",
1405 fmt_amount_sat(tmpctx, onchain_fee),
1406 splice_cmd->feerate_per_kw,
1407 4 * splice_cmd->feerate_per_kw / 1000.0f,
1408 weight);
1409
1410 /* If the wallet pays the fee, we need to add input(s) to cover
1411 * it. This can potentially need to be done mulitple times since
1412 * adding an input increases the needed fee. */
1413 if (funding_wallet_action && funding_wallet_action->pays_fee
1414 && !funding_wallet_action->out_ppm
1415 && splice_cmd->states[funding_wallet_index]->state != SPLICE_CMD_PENDING) {
1416
1417 result = calc_in_ppm_and_fee(cmd, splice_cmd,
1418 onchain_fee,
1419 false,
1420 &extra_funds,
1421 &missing_funds,
1422 &non_wallet_demand);
1423 if (result)
1424 return result;
1425
1426 if (!amount_sat_add(&splice_cmd->needed_funds,
1427 splice_cmd->needed_funds,
1428 onchain_fee))
1429 return do_fail(cmd, splice_cmd,
1430 JSONRPC2_INVALID_PARAMS,
1431 "Internal error; unable to add"
1432 " fee to needed_funds");
1433
1434 /* We need to add wallet funds (again?) */
1435 if (unresolved_wallet_inputs(splice_cmd)) {
1436 result = handle_wallet_fund(cmd, splice_cmd,
1437 onchain_fee);
1438 if (result)
1439 return result;
1440 }
1441 }
1442
1443 /* Now we're ready to calculate wallet funding in_ppm. This is

Callers 1

continue_spliceFunction · 0.85

Calls 15

input_walletFunction · 0.85
calc_in_ppm_and_feeFunction · 0.85
do_failFunction · 0.85
unresolved_wallet_inputsFunction · 0.85
handle_wallet_fundFunction · 0.85
amount_sat_mulFunction · 0.85
amount_sat_divFunction · 0.85
amount_sat_is_zeroFunction · 0.85
fee_actionFunction · 0.85
amount_sat_greaterFunction · 0.85
calc_weightFunction · 0.70
amount_tx_feeFunction · 0.50

Tested by

no test coverage detected