| 2533 | } |
| 2534 | |
| 2535 | static struct command_result * |
| 2536 | json_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) { |
nothing calls this directly
no test coverage detected