Browse Source

feerates: turn it into a simple query API, remove setting.

It's probably unnecessary to have this weird way of injecting results
now we have explicit feerate args.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
33c6285787
  1. 8
      CHANGELOG.md
  2. 23
      lightningd/chaintopology.c
  3. 33
      tests/test_misc.py

8
CHANGELOG.md

@ -20,8 +20,7 @@ This release named by ZmnSCPxj.
- JSON API: `listpeers` has new fields `global_features` and `local_features`. - JSON API: `listpeers` has new fields `global_features` and `local_features`.
- JSON API: `listnodes` has new field `global_features`. - JSON API: `listnodes` has new field `global_features`.
- JSON API: `ping` command to send a ping to a connected peer. - JSON API: `ping` command to send a ping to a connected peer.
- JSON API: `feerates` command to inject fee estimates manually, and retrieve - JSON API: `feerates` command to retrieve current fee estimates.
current estimates.
- JSON API: `withdraw` and `fundchannel` can be given manual feerate. - JSON API: `withdraw` and `fundchannel` can be given manual feerate.
- Config: `--conf` option to set config file. - Config: `--conf` option to set config file.
- Documentation: Added CHANGELOG.md - Documentation: Added CHANGELOG.md
@ -48,7 +47,7 @@ This release named by ZmnSCPxj.
the one given or the first one announced. the one given or the first one announced.
- Crash logs are now placed one-per file like `crash.log.20180822233752` - Crash logs are now placed one-per file like `crash.log.20180822233752`
- We will no longer allow withdrawing funds or funding channels if we - We will no longer allow withdrawing funds or funding channels if we
do not have a fee estimate (eg. bitcoind not synced). do not have a fee estimate (eg. bitcoind not synced); use new `feerate` arg.
### Deprecated ### Deprecated
@ -63,7 +62,8 @@ changes.
used to exist and set to `GOSSIPING` before we opened a channel). used to exist and set to `GOSSIPING` before we opened a channel).
`connected` will indicate if we're connected, and the `channels` `connected` will indicate if we're connected, and the `channels`
array indicates individual channel states (if any). array indicates individual channel states (if any).
- Config: `default-fee-rate` is no longer available; use `feerates`. - Config: `default-fee-rate` is no longer available; use explicit `feerate`
option if necessary.
- Removed all Deprecated options from 0.6. - Removed all Deprecated options from 0.6.
### Fixed ### Fixed

23
lightningd/chaintopology.c

@ -464,34 +464,15 @@ static void json_feerates(struct command *cmd,
{ {
struct chain_topology *topo = cmd->ld->topology; struct chain_topology *topo = cmd->ld->topology;
struct json_result *response; struct json_result *response;
u32 *urgent, *normal, *slow, feerates[NUM_FEERATES]; u32 feerates[NUM_FEERATES];
bool missing; bool missing;
enum feerate_style *style; enum feerate_style *style;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("style", json_tok_feerate_style, &style), p_req("style", json_tok_feerate_style, &style),
p_opt("urgent", json_tok_number, &urgent),
p_opt("normal", json_tok_number, &normal),
p_opt("slow", json_tok_number, &slow),
NULL)) NULL))
return; return;
/* update_feerates uses 0 as "don't know" */
feerates[FEERATE_URGENT] = urgent ? *urgent : 0;
feerates[FEERATE_NORMAL] = normal ? *normal : 0;
feerates[FEERATE_SLOW] = slow ? *slow : 0;
for (size_t i = 0; i < ARRAY_SIZE(feerates); i++)
feerates[i] = feerate_from_style(feerates[i], *style);
log_info(topo->log,
"feerates: inserting feerates in sipa/kb %u/%u/%u",
feerates[FEERATE_URGENT],
feerates[FEERATE_NORMAL],
feerates[FEERATE_SLOW]);
update_feerates(topo->bitcoind, feerates, topo);
missing = false; missing = false;
for (size_t i = 0; i < ARRAY_SIZE(feerates); i++) { for (size_t i = 0; i < ARRAY_SIZE(feerates); i++) {
feerates[i] = try_get_feerate(topo, i); feerates[i] = try_get_feerate(topo, i);
@ -539,7 +520,7 @@ static void json_feerates(struct command *cmd,
static const struct json_command feerates_command = { static const struct json_command feerates_command = {
"feerates", "feerates",
json_feerates, json_feerates,
"Add/query feerate estimates, either satoshi-per-kw ({style} sipa) or satoshi-per-kb ({style} bitcoind) for {urgent}, {normal} and {slow}." "Return feerate estimates, either satoshi-per-kw ({style} perkw) or satoshi-per-kb ({style} perkb)."
}; };
AUTODATA(json_command, &feerates_command); AUTODATA(json_command, &feerates_command);

33
tests/test_misc.py

@ -880,7 +880,8 @@ def test_feerates(node_factory):
assert feerates['perkb']['min_acceptable'] == 253 * 4 assert feerates['perkb']['min_acceptable'] == 253 * 4
# Now try setting them, one at a time. # Now try setting them, one at a time.
feerates = l1.rpc.feerates('perkw', 15000) l1.set_feerates((15000, 0, 0), True)
feerates = l1.rpc.feerates('perkw')
assert len(feerates['perkw']) == 3 assert len(feerates['perkw']) == 3
assert feerates['perkw']['urgent'] == 15000 assert feerates['perkw']['urgent'] == 15000
assert feerates['warning'] == 'Some fee estimates unavailable: bitcoind startup?' assert feerates['warning'] == 'Some fee estimates unavailable: bitcoind startup?'
@ -888,7 +889,8 @@ def test_feerates(node_factory):
assert feerates['perkw']['max_acceptable'] == 15000 * 10 assert feerates['perkw']['max_acceptable'] == 15000 * 10
assert feerates['perkw']['min_acceptable'] == 253 assert feerates['perkw']['min_acceptable'] == 253
feerates = l1.rpc.feerates('perkb', normal=25000) l1.set_feerates((15000, 6250, 0), True)
feerates = l1.rpc.feerates('perkb')
assert len(feerates['perkb']) == 4 assert len(feerates['perkb']) == 4
assert feerates['perkb']['urgent'] == 15000 * 4 assert feerates['perkb']['urgent'] == 15000 * 4
assert feerates['perkb']['normal'] == 25000 assert feerates['perkb']['normal'] == 25000
@ -897,7 +899,8 @@ def test_feerates(node_factory):
assert feerates['perkb']['max_acceptable'] == 15000 * 4 * 10 assert feerates['perkb']['max_acceptable'] == 15000 * 4 * 10
assert feerates['perkb']['min_acceptable'] == 253 * 4 assert feerates['perkb']['min_acceptable'] == 253 * 4
feerates = l1.rpc.feerates('perkw', None, None, 5000) l1.set_feerates((15000, 6250, 5000), True)
feerates = l1.rpc.feerates('perkw')
assert len(feerates['perkw']) == 5 assert len(feerates['perkw']) == 5
assert feerates['perkw']['urgent'] == 15000 assert feerates['perkw']['urgent'] == 15000
assert feerates['perkw']['normal'] == 25000 // 4 assert feerates['perkw']['normal'] == 25000 // 4
@ -907,30 +910,6 @@ def test_feerates(node_factory):
assert feerates['perkw']['max_acceptable'] == 15000 * 10 assert feerates['perkw']['max_acceptable'] == 15000 * 10
assert feerates['perkw']['min_acceptable'] == 5000 // 2 assert feerates['perkw']['min_acceptable'] == 5000 // 2
# Now, outliers effect min and max, not so much the smoothed avg.
feerates = l1.rpc.feerates('perkw', 30000, None, 600)
assert len(feerates['perkw']) == 5
assert feerates['perkw']['urgent'] > 15000
assert feerates['perkw']['urgent'] < 30000
assert feerates['perkw']['normal'] == 25000 // 4
assert feerates['perkw']['slow'] < 5000
assert feerates['perkw']['slow'] > 600
assert 'warning' not in feerates
assert 'perkb' not in feerates
assert feerates['perkw']['max_acceptable'] == 30000 * 10
assert feerates['perkw']['min_acceptable'] == 600 // 2
# Forgotten after 3 more values inserted.
feerates = l1.rpc.feerates('perkw', 15000, 25000 // 4, 5000)
assert feerates['perkw']['max_acceptable'] == 30000 * 10
assert feerates['perkw']['min_acceptable'] == 600 // 2
feerates = l1.rpc.feerates('perkw', 15000, 25000 // 4, 5000)
assert feerates['perkw']['max_acceptable'] == 30000 * 10
assert feerates['perkw']['min_acceptable'] == 600 // 2
feerates = l1.rpc.feerates('perkw', 15000, 25000 // 4, 5000)
assert feerates['perkw']['max_acceptable'] == 15000 * 10
assert feerates['perkw']['min_acceptable'] == 5000 // 2
assert len(feerates['onchain_fee_estimates']) == 3 assert len(feerates['onchain_fee_estimates']) == 3
assert feerates['onchain_fee_estimates']['opening_channel_satoshis'] == feerates['perkw']['normal'] * 702 // 1000 assert feerates['onchain_fee_estimates']['opening_channel_satoshis'] == feerates['perkw']['normal'] * 702 // 1000
assert feerates['onchain_fee_estimates']['mutual_close_satoshis'] == feerates['perkw']['normal'] * 673 // 1000 assert feerates['onchain_fee_estimates']['mutual_close_satoshis'] == feerates['perkw']['normal'] * 673 // 1000

Loading…
Cancel
Save