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

Function json_openchannel_bump

lightningd/dual_open_control.c:2535–2678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2533}
2534
2535static struct command_result *
2536json_openchannel_bump(struct command *cmd,
2537 const char *buffer,
2538 const jsmntok_t *obj UNNEEDED,
2539 const jsmntok_t *params)
2540{
2541 struct openchannel_bump_info *info = tal(cmd, struct openchannel_bump_info);
2542 struct channel *channel;
2543 struct amount_sat psbt_val;
2544 u32 last_feerate_perkw, next_feerate_min;
2545 struct channel_inflight *inflight;
2546
2547 info->cmd = cmd;
2548 if (!param_check(cmd, buffer, params,
2549 p_req("channel_id", param_channel_id, &info->cid),
2550 p_req("amount", param_sat, &info->amount),
2551 p_req("initialpsbt", param_psbt, &info->psbt),
2552 p_opt("funding_feerate", param_feerate,
2553 &info->feerate_per_kw_funding),
2554 NULL))
2555 return command_param_failed();
2556
2557 psbt_val = AMOUNT_SAT(0);
2558 for (size_t i = 0; i < info->psbt->num_inputs; i++) {
2559 struct amount_sat in_amt = psbt_input_get_amount(info->psbt, i);
2560 if (!amount_sat_add(&psbt_val, psbt_val, in_amt))
2561 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2562 "Overflow in adding PSBT input"
2563 " values. %s",
2564 fmt_wally_psbt(tmpctx, info->psbt));
2565 }
2566
2567 /* If they don't pass in at least enough in the PSBT to cover
2568 * their amount, nope */
2569 if (!amount_sat_greater(psbt_val, *info->amount))
2570 return command_fail(cmd, FUND_CANNOT_AFFORD,
2571 "Provided PSBT cannot afford funding of "
2572 "amount %s. %s",
2573 fmt_amount_sat(tmpctx, *info->amount),
2574 fmt_wally_psbt(tmpctx, info->psbt));
2575
2576 /* Are we in a state where we can attempt an RBF? */
2577 channel = channel_by_cid(cmd->ld, info->cid);
2578 if (!channel)
2579 return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
2580 "Unknown channel %s",
2581 fmt_channel_id(tmpctx, info->cid));
2582
2583 /* BOLT #2:
2584 * The sender:
2585 * - MUST set `feerate` greater than or equal to 25/24 times the
2586 * `feerate` of the previously constructed transaction, rounded
2587 * down.
2588 */
2589 last_feerate_perkw = channel_last_funding_feerate(channel);
2590 next_feerate_min = last_feerate_perkw * 25 / 24;
2591 assert(next_feerate_min > last_feerate_perkw);
2592 if (!info->feerate_per_kw_funding) {

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
psbt_input_get_amountFunction · 0.85
fmt_wally_psbtFunction · 0.85
amount_sat_greaterFunction · 0.85
feature_negotiatedFunction · 0.85
channel_current_inflightFunction · 0.85
psbt_add_serialsFunction · 0.85
psbt_has_required_fieldsFunction · 0.85
topology_syncedFunction · 0.85
openchannel_bumpFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70

Tested by

no test coverage detected