mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
chaintopology: new command 'parsefeerate'
Useful for parsing a passed in feerate before calling lightningd with it, e.g. when you need to know what the feerate is for a fundpsbt before calling fundpsbt Changelog-Added: JSON-RPC: new command `parsefeerate` which takes a feerate string and returns the calculated perkw/perkb
This commit is contained in:
parent
2532aa003a
commit
43ae30df21
@ -54,6 +54,7 @@ MANPAGES := doc/lightning-cli.1 \
|
||||
doc/lightning-openchannel_signed.7 \
|
||||
doc/lightning-openchannel_update.7 \
|
||||
doc/lightning-pay.7 \
|
||||
doc/lightning-parsefeerate.7 \
|
||||
doc/lightning-plugin.7 \
|
||||
doc/lightning-reserveinputs.7 \
|
||||
doc/lightning-sendinvoice.7 \
|
||||
|
@ -82,6 +82,7 @@ c-lightning Documentation
|
||||
lightning-openchannel_init <lightning-openchannel_init.7.md>
|
||||
lightning-openchannel_signed <lightning-openchannel_signed.7.md>
|
||||
lightning-openchannel_update <lightning-openchannel_update.7.md>
|
||||
lightning-parsefeerate <lightning-parsefeerate.7.md>
|
||||
lightning-pay <lightning-pay.7.md>
|
||||
lightning-ping <lightning-ping.7.md>
|
||||
lightning-plugin <lightning-plugin.7.md>
|
||||
|
11
doc/lightning-feerates.7
generated
11
doc/lightning-feerates.7
generated
@ -16,7 +16,6 @@ C-lightning will also smoothen feerate estimations from the backend\.
|
||||
|
||||
\fIstyle\fR is either of the two strings:
|
||||
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
\fIperkw\fR - provide feerate in units of satoshis per 1000 weight\.
|
||||
@ -27,7 +26,6 @@ C-lightning will also smoothen feerate estimations from the backend\.
|
||||
|
||||
Bitcoin transactions have non-witness and witness bytes:
|
||||
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
Non-witness bytes count as 4 weight, 1 virtual byte\.
|
||||
@ -58,7 +56,6 @@ which will override the recommended feerates returned by \fBfeerates\fR\.
|
||||
|
||||
On success, an object is returned, containing:
|
||||
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
\fBperkb\fR (object, optional): If \fIstyle\fR parameter was perkb:
|
||||
@ -125,7 +122,6 @@ On success, an object is returned, containing:
|
||||
|
||||
The following warnings may also be returned:
|
||||
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
\fBwarning_missing_feerates\fR: Some fee estimates are missing
|
||||
@ -143,7 +139,6 @@ Many other commands have a \fIfeerate\fR parameter, which can be the strings
|
||||
\fIurgent\fR, \fInormal\fR, or \fIslow\fR\.
|
||||
These are mapped to the \fBfeerates\fR outputs as:
|
||||
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
\fIurgent\fR - equal to \fIunilateral_close\fR
|
||||
@ -167,11 +162,11 @@ manpage\.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
\fBlightning-fundchannel\fR(7), \fBlightning-withdraw\fR(7), \fBlightning-txprepare\fR(7),
|
||||
\fBlightning-fundchannel_start\fR(7)\.
|
||||
\fBlightning-parsefeerate\fR(7), \fBlightning-fundchannel\fR(7), \fBlightning-withdraw\fR(7),
|
||||
\fBlightning-txprepare\fR(7), \fBlightning-fundchannel_start\fR(7)\.
|
||||
|
||||
.SH RESOURCES
|
||||
|
||||
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
|
||||
|
||||
\" SHA256STAMP:227e0f9f9b4d3c2b80d58466ed4fae768a5a2e7c2234e43105e21efc4a0b1861
|
||||
\" SHA256STAMP:3c68e2e2b47bc4107d71e263372b3ec3ac77434d7319c670f293d3be88703fe7
|
||||
|
@ -110,8 +110,8 @@ manpage.
|
||||
SEE ALSO
|
||||
--------
|
||||
|
||||
lightning-fundchannel(7), lightning-withdraw(7), lightning-txprepare(7),
|
||||
lightning-fundchannel_start(7).
|
||||
lightning-parsefeerate(7), lightning-fundchannel(7), lightning-withdraw(7),
|
||||
lightning-txprepare(7), lightning-fundchannel_start(7).
|
||||
|
||||
RESOURCES
|
||||
---------
|
||||
|
44
doc/lightning-parsefeerate.7
generated
Normal file
44
doc/lightning-parsefeerate.7
generated
Normal file
@ -0,0 +1,44 @@
|
||||
.TH "LIGHTNING-PARSEFEERATE" "7" "" "" "lightning-parsefeerate"
|
||||
.SH NAME
|
||||
lightning-parsefeerate - Command for parsing a feerate string to a feerate
|
||||
.SH SYNOPSIS
|
||||
|
||||
\fBparsefeerate\fR \fIfeerate_str\fR
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
The \fBparsefeerate\fR command returns the current feerate for any valid
|
||||
\fIfeerate_str\fR\. This is useful for finding the current feerate that a
|
||||
\fBfundpsbt\fR or \fButxopsbt\fR command might use\.
|
||||
|
||||
.SH RETURN VALUE
|
||||
|
||||
On success, an object is returned, containing:
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
\fBperkw\fR (u32, optional): Value of \fIfeerate_str\fR in kilosipa
|
||||
|
||||
.RE
|
||||
.SH ERRORS
|
||||
|
||||
The \fBparsefeerate\fR command will error if the \fIfeerate_str\fR format is
|
||||
not recognized\.
|
||||
|
||||
.RS
|
||||
.IP \[bu]
|
||||
-32602: If the given parameters are wrong\.
|
||||
|
||||
.RE
|
||||
.SH TRIVIA
|
||||
|
||||
In C-lightning we like to call the weight unit "sipa"
|
||||
in honor of Pieter Wuille,
|
||||
who uses the name "sipa" on IRC and elsewhere\.
|
||||
Internally we call the \fIperkw\fR style as "feerate per kilosipa"\.
|
||||
|
||||
.SH RESOURCES
|
||||
|
||||
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
|
||||
|
||||
\" SHA256STAMP:1395d3fe85f6eb1f09c3706c50a9660dd9ade04e71435bde3fe1f9660f7b2655
|
45
doc/lightning-parsefeerate.7.md
Normal file
45
doc/lightning-parsefeerate.7.md
Normal file
@ -0,0 +1,45 @@
|
||||
lightning-parsefeerate -- Command for parsing a feerate string to a feerate
|
||||
===========================================================================
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
|
||||
**parsefeerate** *feerate_str*
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
The **parsefeerate** command returns the current feerate for any valid
|
||||
*feerate_str*. This is useful for finding the current feerate that a
|
||||
**fundpsbt** or **utxopsbt** command might use.
|
||||
|
||||
RETURN VALUE
|
||||
------------
|
||||
|
||||
[comment]: # (GENERATE-FROM-SCHEMA-START)
|
||||
On success, an object is returned, containing:
|
||||
- **perkw** (u32, optional): Value of *feerate_str* in kilosipa
|
||||
[comment]: # (GENERATE-FROM-SCHEMA-END)
|
||||
|
||||
ERRORS
|
||||
------
|
||||
|
||||
The **parsefeerate** command will error if the *feerate_str* format is
|
||||
not recognized.
|
||||
|
||||
- -32602: If the given parameters are wrong.
|
||||
|
||||
TRIVIA
|
||||
------
|
||||
|
||||
In C-lightning we like to call the weight unit "sipa"
|
||||
in honor of Pieter Wuille,
|
||||
who uses the name "sipa" on IRC and elsewhere.
|
||||
Internally we call the *perkw* style as "feerate per kilosipa".
|
||||
|
||||
RESOURCES
|
||||
---------
|
||||
|
||||
Main web site: <https://github.com/ElementsProject/lightning>
|
||||
|
||||
[comment]: # ( SHA256STAMP:db3351466f8d2675cecf6f5909c1f3ff264b6ffa865b2d64eb02bf0b45a31a4d)
|
13
doc/schemas/parsefeerate.schema.json
Normal file
13
doc/schemas/parsefeerate.schema.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [ ],
|
||||
"properties": {
|
||||
"perkw": {
|
||||
"type": "u32",
|
||||
"description": "Value of *feerate_str* in kilosipa",
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
@ -553,6 +553,33 @@ static const struct json_command feerates_command = {
|
||||
};
|
||||
AUTODATA(json_command, &feerates_command);
|
||||
|
||||
static struct command_result *json_parse_feerate(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct json_stream *response;
|
||||
u32 *feerate;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("feerate", param_feerate, &feerate),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_add_num(response, feerate_style_name(FEERATE_PER_KSIPA),
|
||||
feerate_to_style(*feerate, FEERATE_PER_KSIPA));
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
static const struct json_command parse_feerate_command = {
|
||||
"parsefeerate",
|
||||
"bitcoin",
|
||||
json_parse_feerate,
|
||||
"Return current feerate in perkw + perkb for given feerate string."
|
||||
};
|
||||
AUTODATA(json_command, &parse_feerate_command);
|
||||
|
||||
static void next_updatefee_timer(struct chain_topology *topo)
|
||||
{
|
||||
/* This takes care of its own lifetime. */
|
||||
|
@ -1462,6 +1462,11 @@ def test_feerates(node_factory):
|
||||
types = ["opening", "mutual_close", "unilateral_close", "delayed_to_us",
|
||||
"htlc_resolution", "penalty"]
|
||||
|
||||
# Try parsing the feerates, won't work because can't estimate
|
||||
for t in types:
|
||||
with pytest.raises(RpcError, match=r'Cannot estimate fees'):
|
||||
feerate = l1.rpc.parsefeerate(t)
|
||||
|
||||
# Query feerates (shouldn't give any!)
|
||||
wait_for(lambda: len(l1.rpc.feerates('perkw')['perkw']) == 2)
|
||||
feerates = l1.rpc.feerates('perkw')
|
||||
@ -1539,6 +1544,13 @@ def test_feerates(node_factory):
|
||||
htlc_feerate = feerates["perkw"]["htlc_resolution"]
|
||||
htlc_timeout_cost = feerates["onchain_fee_estimates"]["htlc_timeout_satoshis"]
|
||||
htlc_success_cost = feerates["onchain_fee_estimates"]["htlc_success_satoshis"]
|
||||
|
||||
# Try parsing the feerates, won't work because can't estimate
|
||||
for t in types:
|
||||
feerate = l1.rpc.parsefeerate(t)
|
||||
assert feerate['perkw']
|
||||
assert 'perkb' not in feerate
|
||||
|
||||
if EXPERIMENTAL_FEATURES:
|
||||
# option_anchor_outputs
|
||||
assert htlc_timeout_cost == htlc_feerate * 666 // 1000
|
||||
|
Loading…
Reference in New Issue
Block a user