2022-07-04 05:52:34 +02:00
|
|
|
#include "config.h"
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
#include <common/configdir.h>
|
2022-07-04 05:52:34 +02:00
|
|
|
#include <common/json_command.h>
|
|
|
|
#include <lightningd/chaintopology.h>
|
|
|
|
#include <lightningd/feerate.h>
|
|
|
|
#include <lightningd/jsonrpc.h>
|
|
|
|
#include <lightningd/lightningd.h>
|
|
|
|
|
|
|
|
const char *feerate_name(enum feerate feerate)
|
|
|
|
{
|
|
|
|
switch (feerate) {
|
|
|
|
case FEERATE_OPENING: return "opening";
|
|
|
|
case FEERATE_MUTUAL_CLOSE: return "mutual_close";
|
|
|
|
case FEERATE_UNILATERAL_CLOSE: return "unilateral_close";
|
|
|
|
case FEERATE_DELAYED_TO_US: return "delayed_to_us";
|
|
|
|
case FEERATE_HTLC_RESOLUTION: return "htlc_resolution";
|
|
|
|
case FEERATE_PENALTY: return "penalty";
|
|
|
|
case FEERATE_MIN: return "min_acceptable";
|
|
|
|
case FEERATE_MAX: return "max_acceptable";
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct command_result *param_feerate_style(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
enum feerate_style **style)
|
|
|
|
{
|
|
|
|
*style = tal(cmd, enum feerate_style);
|
|
|
|
if (json_tok_streq(buffer, tok,
|
|
|
|
feerate_style_name(FEERATE_PER_KSIPA))) {
|
|
|
|
**style = FEERATE_PER_KSIPA;
|
|
|
|
return NULL;
|
|
|
|
} else if (json_tok_streq(buffer, tok,
|
|
|
|
feerate_style_name(FEERATE_PER_KBYTE))) {
|
|
|
|
**style = FEERATE_PER_KBYTE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"'%s' should be '%s' or '%s', not '%.*s'",
|
|
|
|
name,
|
|
|
|
feerate_style_name(FEERATE_PER_KSIPA),
|
|
|
|
feerate_style_name(FEERATE_PER_KBYTE),
|
|
|
|
json_tok_full_len(tok), json_tok_full(buffer, tok));
|
|
|
|
}
|
|
|
|
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
/* This can set **feerate to 0, if it's unknown. */
|
|
|
|
static struct command_result *param_feerate_unchecked(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
u32 **feerate)
|
2022-07-04 05:52:34 +02:00
|
|
|
{
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
*feerate = tal(cmd, u32);
|
|
|
|
|
|
|
|
if (json_tok_streq(buffer, tok, "opening")) {
|
|
|
|
**feerate = opening_feerate(cmd->ld->topology);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (json_tok_streq(buffer, tok, "mutual_close")) {
|
|
|
|
**feerate = mutual_close_feerate(cmd->ld->topology);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (json_tok_streq(buffer, tok, "penalty")) {
|
|
|
|
**feerate = penalty_feerate(cmd->ld->topology);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (json_tok_streq(buffer, tok, "unilateral_close")) {
|
2023-06-26 01:10:21 +02:00
|
|
|
**feerate = unilateral_feerate(cmd->ld->topology, false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (json_tok_streq(buffer, tok, "unilateral_anchor_close")) {
|
|
|
|
**feerate = unilateral_feerate(cmd->ld->topology, true);
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-07-04 05:52:34 +02:00
|
|
|
/* We used SLOW, NORMAL, and URGENT as feerate targets previously,
|
|
|
|
* and many commands rely on this syntax now.
|
|
|
|
* It's also really more natural for an user interface. */
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
if (json_tok_streq(buffer, tok, "slow")) {
|
|
|
|
**feerate = feerate_for_deadline(cmd->ld->topology, 100);
|
|
|
|
return NULL;
|
|
|
|
} else if (json_tok_streq(buffer, tok, "normal")) {
|
|
|
|
**feerate = feerate_for_deadline(cmd->ld->topology, 12);
|
|
|
|
return NULL;
|
|
|
|
} else if (json_tok_streq(buffer, tok, "urgent")) {
|
|
|
|
**feerate = feerate_for_deadline(cmd->ld->topology, 6);
|
|
|
|
return NULL;
|
2023-04-07 06:43:45 +02:00
|
|
|
} else if (json_tok_streq(buffer, tok, "minimum")) {
|
|
|
|
**feerate = get_feerate_floor(cmd->ld->topology);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can specify number of blocks as a target */
|
|
|
|
if (json_tok_endswith(buffer, tok, "blocks")) {
|
|
|
|
jsmntok_t base = *tok;
|
|
|
|
base.end -= strlen("blocks");
|
|
|
|
u32 numblocks;
|
|
|
|
|
|
|
|
if (!json_to_number(buffer, &base, &numblocks)) {
|
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"'%s' should be an integer not '%.*s'",
|
|
|
|
name, base.end - base.start,
|
|
|
|
buffer + base.start);
|
|
|
|
}
|
|
|
|
**feerate = feerate_for_deadline(cmd->ld->topology, numblocks);
|
|
|
|
return NULL;
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
}
|
2022-07-04 05:52:34 +02:00
|
|
|
|
|
|
|
/* It's a number... */
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
tal_free(*feerate);
|
2022-07-04 05:52:34 +02:00
|
|
|
return param_feerate_val(cmd, name, buffer, tok, feerate);
|
|
|
|
}
|
|
|
|
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
struct command_result *param_feerate(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
u32 **feerate)
|
2022-07-04 05:52:34 +02:00
|
|
|
{
|
lightningd: clean up feerate handling, deprecate old terms.
Drop try_get_feerate() in favor of explicit feerate_for_deadline() and
smoothed_feerate_for_deadline().
This shows us everywhere we deal with old-style feerates by names.
`delayed_to_us` and `htlc_resolution` will be moving to dynamic fees,
so deprecate those.
Note that "penalty" is still used for generating penalty txs for
watchtowers, and "unilateral_close" still used until we get zero-fee
anchors.
Changelog-Added: JSON-RPC: `feerates` `estimates` array shows fee estimates by blockcount from underlying plugin (usually *bcli*).
Changelog-Changed: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) value *slow* is now 100 block-estimate, not half of 100-block estimate.
Changelog-Deprecated: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` `feerate` (`feerange` for `close`) expressed as, "delayed_to_us", "htlc_resolution", "max_acceptable" or "min_acceptable". Use explicit block counts or *slow*/*normal*/*urgent*/*minimum*.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-07 06:43:39 +02:00
|
|
|
struct command_result *ret;
|
|
|
|
|
|
|
|
ret = param_feerate_unchecked(cmd, name, buffer, tok, feerate);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (**feerate == 0)
|
|
|
|
return command_fail(cmd, BCLI_NO_FEE_ESTIMATES,
|
|
|
|
"Cannot estimate fees (yet)");
|
2022-07-04 05:52:34 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct command_result *param_feerate_val(struct command *cmd,
|
|
|
|
const char *name, const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
u32 **feerate_per_kw)
|
|
|
|
{
|
|
|
|
jsmntok_t base = *tok;
|
|
|
|
enum feerate_style style;
|
|
|
|
unsigned int num;
|
|
|
|
|
|
|
|
if (json_tok_endswith(buffer, tok,
|
|
|
|
feerate_style_name(FEERATE_PER_KBYTE))) {
|
|
|
|
style = FEERATE_PER_KBYTE;
|
|
|
|
base.end -= strlen(feerate_style_name(FEERATE_PER_KBYTE));
|
|
|
|
} else if (json_tok_endswith(buffer, tok,
|
|
|
|
feerate_style_name(FEERATE_PER_KSIPA))) {
|
|
|
|
style = FEERATE_PER_KSIPA;
|
|
|
|
base.end -= strlen(feerate_style_name(FEERATE_PER_KSIPA));
|
|
|
|
} else
|
|
|
|
style = FEERATE_PER_KBYTE;
|
|
|
|
|
|
|
|
if (!json_to_number(buffer, &base, &num)) {
|
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"'%s' should be an integer with optional perkw/perkb, not '%.*s'",
|
|
|
|
name, base.end - base.start,
|
|
|
|
buffer + base.start);
|
|
|
|
}
|
|
|
|
|
|
|
|
*feerate_per_kw = tal(cmd, u32);
|
|
|
|
**feerate_per_kw = feerate_from_style(num, style);
|
|
|
|
if (**feerate_per_kw < FEERATE_FLOOR)
|
|
|
|
**feerate_per_kw = FEERATE_FLOOR;
|
|
|
|
return NULL;
|
|
|
|
}
|