mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
lightningd: allow "NNblocks" and "minimum" as feerates.
And consolidate descriptions into lightning-feerates(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `close`, `fundchannel`, `fundpsbt`, `multifundchannel`, `multiwithdraw`, `txprepare`, `upgradewallet`, `withdraw` now allow "minimum" and NN"blocks" as `feerate` (`feerange` for `close`).
This commit is contained in:
parent
64b1ddd761
commit
c46473e615
13 changed files with 69 additions and 81 deletions
|
@ -295,7 +295,7 @@ def _extra_validator(is_request: bool):
|
||||||
return True
|
return True
|
||||||
if not checker.is_type(instance, "string"):
|
if not checker.is_type(instance, "string"):
|
||||||
return False
|
return False
|
||||||
if instance in ("urgent", "normal", "slow"):
|
if instance in ("urgent", "normal", "slow", "minimum"):
|
||||||
return True
|
return True
|
||||||
if instance in ("opening", "mutual_close", "unilateral_close", "delayed_to_us", "htlc_resolution", "penalty", "min_acceptable", "max_acceptable"):
|
if instance in ("opening", "mutual_close", "unilateral_close", "delayed_to_us", "htlc_resolution", "penalty", "min_acceptable", "max_acceptable"):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -66,16 +66,7 @@ unless this flag is passed in. Defaults to false.
|
||||||
*feerange* is an optional array [ *min*, *max* ], indicating the
|
*feerange* is an optional array [ *min*, *max* ], indicating the
|
||||||
minimum and maximum feerates to offer: the peer will obey these if it
|
minimum and maximum feerates to offer: the peer will obey these if it
|
||||||
supports the quick-close protocol. *slow* and *unilateral\_close* are
|
supports the quick-close protocol. *slow* and *unilateral\_close* are
|
||||||
the defaults.
|
the defaults. See NOTES in lightning-feerates(7) for possible values.
|
||||||
|
|
||||||
Rates are one of the strings *urgent* (aim for next block), *normal*
|
|
||||||
(next 4 blocks or so) or *slow* (next 100 blocks or so) to use
|
|
||||||
lightningd's internal estimates, or one of the names from
|
|
||||||
lightning-feerates(7). Otherwise, they can be numbers with
|
|
||||||
an optional suffix: *perkw* means the number is interpreted as
|
|
||||||
satoshi-per-kilosipa (weight), and *perkb* means it is interpreted
|
|
||||||
bitcoind-style as satoshi-per-kilobyte. Omitting the suffix is
|
|
||||||
equivalent to *perkb*.
|
|
||||||
|
|
||||||
Note that the maximum fee will be capped at the final commitment
|
Note that the maximum fee will be capped at the final commitment
|
||||||
transaction fee (unless the experimental anchor-outputs option is
|
transaction fee (unless the experimental anchor-outputs option is
|
||||||
|
|
|
@ -96,13 +96,20 @@ if feerate estimates for that kind of transaction are unavailable.
|
||||||
NOTES
|
NOTES
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Many other commands have a *feerate* parameter, which can be the strings
|
Many other commands have a *feerate* parameter. This can be:
|
||||||
*urgent*, *normal*, or *slow*.
|
|
||||||
These are mapped to the **feerates** outputs as:
|
|
||||||
|
|
||||||
* *urgent* - equal to *unilateral\_close*
|
* One of the strings to use lightningd's internal estimates:
|
||||||
* *normal* - equal to *opening*
|
* *urgent* (aim for next block),
|
||||||
* *slow* - equal to *min\_acceptable*.
|
* *normal* (next 6 blocks or so)
|
||||||
|
* *slow* (next 100 blocks or so)
|
||||||
|
* *minimum* for the lowest value bitcoind will currently accept (added in v23.05)
|
||||||
|
|
||||||
|
* A number, with an optional suffix:
|
||||||
|
* *blocks* means aim for confirmation in that many blocks (added in v23.05)
|
||||||
|
* *perkw* means the number is interpreted as satoshi-per-kilosipa (weight)
|
||||||
|
* *perkb* means it is interpreted bitcoind-style as satoshi-per-kilobyte.
|
||||||
|
|
||||||
|
Omitting the suffix is equivalent to *perkb*.
|
||||||
|
|
||||||
TRIVIA
|
TRIVIA
|
||||||
------
|
------
|
||||||
|
|
|
@ -35,16 +35,9 @@ decimal places ending in *btc*. The value cannot be less than the dust
|
||||||
limit, currently set to 546, nor more than 16777215 satoshi (unless large
|
limit, currently set to 546, nor more than 16777215 satoshi (unless large
|
||||||
channels were negotiated with the peer).
|
channels were negotiated with the peer).
|
||||||
|
|
||||||
*feerate* is an optional feerate used for the opening transaction and as
|
*feerate* is an optional feerate used for the opening transaction and
|
||||||
initial feerate for commitment and HTLC transactions. It can be one of
|
as initial feerate for commitment and HTLC transactions (see NOTES in
|
||||||
the strings *urgent* (aim for next block), *normal* (next 4 blocks or
|
lightning-feerates(7)). The default is *normal*.
|
||||||
so) or *slow* (next 100 blocks or so) to use lightningd's internal
|
|
||||||
estimates: *normal* is the default.
|
|
||||||
|
|
||||||
Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
|
|
||||||
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
|
|
||||||
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
|
|
||||||
the suffix is equivalent to *perkb*.
|
|
||||||
|
|
||||||
*announce* is an optional flag that triggers whether to announce this
|
*announce* is an optional flag that triggers whether to announce this
|
||||||
channel or not. Defaults to `true`. An unannounced channel is considered
|
channel or not. Defaults to `true`. An unannounced channel is considered
|
||||||
|
|
|
@ -18,14 +18,8 @@ be a whole number, a whole number ending in *sat*, a whole number
|
||||||
ending in *000msat*, or a number with 1 to 8 decimal places ending in
|
ending in *000msat*, or a number with 1 to 8 decimal places ending in
|
||||||
*btc*.
|
*btc*.
|
||||||
|
|
||||||
*feerate* can be one of the feerates listed in lightning-feerates(7),
|
*feerate* is an optional feerate: see NOTES in lightning-feerates(7)
|
||||||
or one of the strings *urgent* (aim for next block), *normal* (next 4
|
for possible values. The default is *normal*.
|
||||||
blocks or so) or *slow* (next 100 blocks or so) to use lightningd's
|
|
||||||
internal estimates. It can also be a *feerate* is a number, with an
|
|
||||||
optional suffix: *perkw* means the number is interpreted as
|
|
||||||
satoshi-per-kilosipa (weight), and *perkb* means it is interpreted
|
|
||||||
bitcoind-style as satoshi-per-kilobyte. Omitting the suffix is
|
|
||||||
equivalent to *perkb*.
|
|
||||||
|
|
||||||
*startweight* is the weight of the transaction before *fundpsbt* has
|
*startweight* is the weight of the transaction before *fundpsbt* has
|
||||||
added any inputs.
|
added any inputs.
|
||||||
|
|
|
@ -65,17 +65,10 @@ Readiness is indicated by **listpeers** reporting a *state* of
|
||||||
There must be at least one entry in *destinations*;
|
There must be at least one entry in *destinations*;
|
||||||
it cannot be an empty array.
|
it cannot be an empty array.
|
||||||
|
|
||||||
*feerate* is an optional feerate used for the opening transaction and, if
|
*feerate* is an optional feerate used for the opening transaction, and
|
||||||
*commitment\_feerate* is not set, as the initial feerate for
|
if *commitment\_feerate* is not set, as initial feerate for commitment
|
||||||
commitment and HTLC transactions. It can be one of
|
and HTLC transactions. See NOTES in lightning-feerates(7) for possible
|
||||||
the strings *urgent* (aim for next block), *normal* (next 4 blocks or
|
values. The default is *normal*.
|
||||||
so) or *slow* (next 100 blocks or so) to use lightningd's internal
|
|
||||||
estimates: *normal* is the default.
|
|
||||||
|
|
||||||
Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
|
|
||||||
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
|
|
||||||
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
|
|
||||||
the suffix is equivalent to *perkb*.
|
|
||||||
|
|
||||||
*minconf* specifies the minimum number of confirmations that used
|
*minconf* specifies the minimum number of confirmations that used
|
||||||
outputs should have. Default is 1.
|
outputs should have. Default is 1.
|
||||||
|
|
|
@ -21,15 +21,8 @@ a whole number ending in *sat*,
|
||||||
a whole number ending in *000msat*,
|
a whole number ending in *000msat*,
|
||||||
or a number with 1 to 8 decimal places ending in *btc*.
|
or a number with 1 to 8 decimal places ending in *btc*.
|
||||||
|
|
||||||
*feerate* is an optional feerate to use. It can be one of the strings
|
*feerate* is an optional feerate: see NOTES in lightning-feerates(7)
|
||||||
*urgent* (aim for next block), *normal* (next 4 blocks or so) or *slow*
|
for possible values. The default is *normal*.
|
||||||
(next 100 blocks or so) to use lightningd's internal estimates: *normal*
|
|
||||||
is the default.
|
|
||||||
|
|
||||||
Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
|
|
||||||
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
|
|
||||||
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
|
|
||||||
the suffix is equivalent to *perkb*.
|
|
||||||
|
|
||||||
*minconf* specifies the minimum number of confirmations that used
|
*minconf* specifies the minimum number of confirmations that used
|
||||||
outputs should have. Default is 1.
|
outputs should have. Default is 1.
|
||||||
|
|
|
@ -29,15 +29,8 @@ all available funds. Otherwise, it is in amount precision; it can be a whole
|
||||||
number, a whole number ending in *sat*, a whole number ending in *000msat*,
|
number, a whole number ending in *sat*, a whole number ending in *000msat*,
|
||||||
or a number with 1 to 8 decimal places ending in *btc*.
|
or a number with 1 to 8 decimal places ending in *btc*.
|
||||||
|
|
||||||
*feerate* is an optional feerate to use. It can be one of the strings
|
*feerate* is an optional feerate to use: see NOTES in lightning-feerates(7)
|
||||||
*urgent* (aim for next block), *normal* (next 4 blocks or so) or *slow*
|
for possible values. The default is *normal*.
|
||||||
(next 100 blocks or so) to use lightningd's internal estimates: *normal*
|
|
||||||
is the default.
|
|
||||||
|
|
||||||
Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
|
|
||||||
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
|
|
||||||
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
|
|
||||||
the suffix is equivalent to *perkb*.
|
|
||||||
|
|
||||||
*minconf* specifies the minimum number of confirmations that used
|
*minconf* specifies the minimum number of confirmations that used
|
||||||
outputs should have. Default is 1.
|
outputs should have. Default is 1.
|
||||||
|
|
|
@ -12,14 +12,8 @@ DESCRIPTION
|
||||||
`upgradewallet` is a convenience RPC which will spend all p2sh-wrapped
|
`upgradewallet` is a convenience RPC which will spend all p2sh-wrapped
|
||||||
Segwit deposits in a wallet into a single Native Segwit P2WPKH address.
|
Segwit deposits in a wallet into a single Native Segwit P2WPKH address.
|
||||||
|
|
||||||
*feerate* can be one of the feerates listed in lightning-feerates(7),
|
*feerate* is an optional feerate: see NOTES in lightning-feerates(7)
|
||||||
or one of the strings *urgent* (aim for next block), *normal* (next 4
|
for possible values. The default is *opening*.
|
||||||
blocks or so) or *slow* (next 100 blocks or so) to use lightningd's
|
|
||||||
internal estimates. It can also be a *feerate* is a number, with an
|
|
||||||
optional suffix: *perkw* means the number is interpreted as
|
|
||||||
satoshi-per-kilosipa (weight), and *perkb* means it is interpreted
|
|
||||||
bitcoind-style as satoshi-per-kilobyte. Omitting the suffix is
|
|
||||||
equivalent to *perkb*.
|
|
||||||
|
|
||||||
*reservedok* tells the wallet to include all P2SH-wrapped inputs, including
|
*reservedok* tells the wallet to include all P2SH-wrapped inputs, including
|
||||||
reserved ones.
|
reserved ones.
|
||||||
|
|
|
@ -21,15 +21,8 @@ satoshi precision; it can be a whole number, a whole number ending in
|
||||||
*sat*, a whole number ending in *000msat*, or a number with 1 to 8
|
*sat*, a whole number ending in *000msat*, or a number with 1 to 8
|
||||||
decimal places ending in *btc*.
|
decimal places ending in *btc*.
|
||||||
|
|
||||||
*feerate* is an optional feerate to use. It can be one of the strings
|
*feerate* is an optional feerate: see NOTES in lightning-feerates(7)
|
||||||
*urgent* (aim for next block), *normal* (next 4 blocks or so) or *slow*
|
for possible values. The default is *normal*.
|
||||||
(next 100 blocks or so) to use lightningd's internal estimates: *normal*
|
|
||||||
is the default.
|
|
||||||
|
|
||||||
Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
|
|
||||||
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
|
|
||||||
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
|
|
||||||
the suffix is equivalent to *perkb*.
|
|
||||||
|
|
||||||
*minconf* specifies the minimum number of confirmations that used
|
*minconf* specifies the minimum number of confirmations that used
|
||||||
outputs should have. Default is 1.
|
outputs should have. Default is 1.
|
||||||
|
|
|
@ -120,6 +120,25 @@ static struct command_result *param_feerate_unchecked(struct command *cmd,
|
||||||
} else if (json_tok_streq(buffer, tok, "urgent")) {
|
} else if (json_tok_streq(buffer, tok, "urgent")) {
|
||||||
**feerate = feerate_for_deadline(cmd->ld->topology, 6);
|
**feerate = feerate_for_deadline(cmd->ld->topology, 6);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It's a number... */
|
/* It's a number... */
|
||||||
|
|
|
@ -40,6 +40,9 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||||
/* Generated stub for fromwire_node_id */
|
/* Generated stub for fromwire_node_id */
|
||||||
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
|
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
|
||||||
|
/* Generated stub for get_feerate_floor */
|
||||||
|
u32 get_feerate_floor(const struct chain_topology *topo UNNEEDED)
|
||||||
|
{ fprintf(stderr, "get_feerate_floor called!\n"); abort(); }
|
||||||
/* Generated stub for htlc_resolution_feerate */
|
/* Generated stub for htlc_resolution_feerate */
|
||||||
u32 htlc_resolution_feerate(struct chain_topology *topo UNNEEDED)
|
u32 htlc_resolution_feerate(struct chain_topology *topo UNNEEDED)
|
||||||
{ fprintf(stderr, "htlc_resolution_feerate called!\n"); abort(); }
|
{ fprintf(stderr, "htlc_resolution_feerate called!\n"); abort(); }
|
||||||
|
|
|
@ -3282,10 +3282,25 @@ def test_feerate_arg(node_factory):
|
||||||
fees["penalty"] = by_blocks[12]
|
fees["penalty"] = by_blocks[12]
|
||||||
fees["unilateral_close"] = by_blocks[6]
|
fees["unilateral_close"] = by_blocks[6]
|
||||||
|
|
||||||
|
fees["2blocks"] = by_blocks[2]
|
||||||
|
fees["6blocks"] = by_blocks[6]
|
||||||
|
fees["12blocks"] = by_blocks[12]
|
||||||
|
fees["100blocks"] = by_blocks[100]
|
||||||
|
|
||||||
|
# Simple interpolation
|
||||||
|
fees["9blocks"] = (by_blocks[6] + by_blocks[12]) // 2
|
||||||
|
|
||||||
for fee, expect in fees.items():
|
for fee, expect in fees.items():
|
||||||
# Put arg in assertion, so it gets printed on failure!
|
# Put arg in assertion, so it gets printed on failure!
|
||||||
assert (l1.rpc.parsefeerate(fee), fee) == ({'perkw': expect}, fee)
|
assert (l1.rpc.parsefeerate(fee), fee) == ({'perkw': expect}, fee)
|
||||||
|
|
||||||
|
# More thorough interpolation
|
||||||
|
for block in range(12, 100):
|
||||||
|
# y = y1 + (x-x1)(y2-y1)/(x2-x1)
|
||||||
|
fee = by_blocks[12] + (block - 12) * (by_blocks[100] - by_blocks[12]) // (100 - 12)
|
||||||
|
# Rounding error is a thing!
|
||||||
|
assert abs(l1.rpc.parsefeerate(f"{block}blocks")['perkw'] - fee) <= 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="Fails by intention for creating test gossip stores")
|
@pytest.mark.skip(reason="Fails by intention for creating test gossip stores")
|
||||||
def test_create_gossip_mesh(node_factory, bitcoind):
|
def test_create_gossip_mesh(node_factory, bitcoind):
|
||||||
|
|
Loading…
Add table
Reference in a new issue