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

Function json_openchannel_bump

lightningd/dual_open_control.c:2745–2919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2743}
2744
2745static struct command_result *
2746json_openchannel_bump(struct command *cmd,
2747 const char *buffer,
2748 const jsmntok_t *obj UNNEEDED,
2749 const jsmntok_t *params)
2750{
2751 struct openchannel_bump_info *info = tal(cmd, struct openchannel_bump_info);
2752 struct channel *channel;
2753 struct amount_sat psbt_val;
2754 u32 last_feerate_perkw, next_feerate_min;
2755 struct channel_inflight *inflight;
2756
2757 info->cmd = cmd;
2758 if (!param_check(cmd, buffer, params,
2759 p_req("channel_id", param_channel_id, &info->cid),
2760 p_req("amount", param_sat, &info->amount),
2761 p_req("initialpsbt", param_psbt, &info->psbt),
2762 p_opt("funding_feerate", param_feerate,
2763 &info->feerate_per_kw_funding),
2764 NULL))
2765 return command_param_failed();
2766
2767 psbt_val = AMOUNT_SAT(0);
2768 for (size_t i = 0; i < info->psbt->num_inputs; i++) {
2769 struct amount_sat in_amt = psbt_input_get_amount(info->psbt, i);
2770 if (!amount_sat_add(&psbt_val, psbt_val, in_amt))
2771 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2772 "Overflow in adding PSBT input"
2773 " values. %s",
2774 fmt_wally_psbt(tmpctx, info->psbt));
2775 }
2776
2777 /* If they don't pass in at least enough in the PSBT to cover
2778 * their amount, nope */
2779 if (!amount_sat_greater(psbt_val, *info->amount))
2780 return command_fail(cmd, FUND_CANNOT_AFFORD,
2781 "Provided PSBT cannot afford funding of "
2782 "amount %s. %s",
2783 fmt_amount_sat(tmpctx, *info->amount),
2784 fmt_wally_psbt(tmpctx, info->psbt));
2785
2786 /* Are we in a state where we can attempt an RBF? */
2787 channel = channel_by_cid(cmd->ld, info->cid);
2788 if (!channel)
2789 return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
2790 "Unknown channel %s",
2791 fmt_channel_id(tmpctx, info->cid));
2792
2793 /* BOLT #2:
2794 * The sender:
2795 * - MUST set `feerate` greater than or equal to 25/24 times the
2796 * `feerate` of the previously constructed transaction, rounded
2797 * down.
2798 */
2799 last_feerate_perkw = channel_last_funding_feerate(channel);
2800 /* Whatever is stored could be absurd, in which case there is no next
2801 * feerate to bump to. Fail the command rather than the daemon. */
2802 if (!next_funding_feerate(last_feerate_perkw, &next_feerate_min))

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
next_funding_feerateFunction · 0.85
our_feerate_maxFunction · 0.85
feature_negotiatedFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
channel_current_inflightFunction · 0.85
psbt_add_serialsFunction · 0.85
psbt_has_required_fieldsFunction · 0.85
topology_syncedFunction · 0.85

Tested by

no test coverage detected