Skip to content

Commit

Permalink
feerates: add floor field for the current minimum feerate bitcoind …
Browse files Browse the repository at this point in the history
…will accept

Changelog-Added: JSON-RPC: `feerates`: added `floor` field for current minimum feerate bitcoind will accept
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Apr 9, 2023
1 parent 812a5a1 commit 3a3370f
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
"FeeratesPerkb": {
"Feerates.perkb.delayed_to_us": 6,
"Feerates.perkb.estimates[]": 9,
"Feerates.perkb.floor": 10,
"Feerates.perkb.htlc_resolution": 7,
"Feerates.perkb.max_acceptable": 2,
"Feerates.perkb.min_acceptable": 1,
Expand All @@ -374,6 +375,7 @@
"FeeratesPerkw": {
"Feerates.perkw.delayed_to_us": 6,
"Feerates.perkw.estimates[]": 9,
"Feerates.perkw.floor": 10,
"Feerates.perkw.htlc_resolution": 7,
"Feerates.perkw.max_acceptable": 2,
"Feerates.perkw.min_acceptable": 1,
Expand Down Expand Up @@ -1572,6 +1574,10 @@
"added": "v23.05",
"deprecated": false
},
"Feerates.perkb.floor": {
"added": "v23.05",
"deprecated": false
},
"Feerates.perkb.htlc_resolution": {
"added": "pre-v0.10.1",
"deprecated": "v23.05"
Expand Down Expand Up @@ -1624,6 +1630,10 @@
"added": "v23.05",
"deprecated": false
},
"Feerates.perkw.floor": {
"added": "v23.05",
"deprecated": false
},
"Feerates.perkw.htlc_resolution": {
"added": "pre-v0.10.1",
"deprecated": "v23.05"
Expand Down
2 changes: 2 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ def feerates_perkb2py(m):
return remove_default({
"min_acceptable": m.min_acceptable, # PrimitiveField in generate_composite
"max_acceptable": m.max_acceptable, # PrimitiveField in generate_composite
"floor": m.floor, # PrimitiveField in generate_composite
"estimates": [feerates_perkb_estimates2py(i) for i in m.estimates], # ArrayField[composite] in generate_composite
"opening": m.opening, # PrimitiveField in generate_composite
"mutual_close": m.mutual_close, # PrimitiveField in generate_composite
Expand All @@ -763,6 +764,7 @@ def feerates_perkw2py(m):
return remove_default({
"min_acceptable": m.min_acceptable, # PrimitiveField in generate_composite
"max_acceptable": m.max_acceptable, # PrimitiveField in generate_composite
"floor": m.floor, # PrimitiveField in generate_composite
"estimates": [feerates_perkw_estimates2py(i) for i in m.estimates], # ArrayField[composite] in generate_composite
"opening": m.opening, # PrimitiveField in generate_composite
"mutual_close": m.mutual_close, # PrimitiveField in generate_composite
Expand Down
4 changes: 3 additions & 1 deletion doc/lightning-feerates.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ On success, an object is returned, containing:
- **perkb** (object, optional): If *style* parameter was perkb:
- **min\_acceptable** (u32): The smallest feerate that we allow peers to specify: half the 100-block estimate
- **max\_acceptable** (u32): The largest feerate we will accept from remote negotiations. If a peer attempts to set the feerate higher than this we will unilaterally close the channel (or simply forget it if it's not open yet).
- **floor** (u32): The smallest feerate that our backend tells us it will accept (i.e. minrelayfee or mempoolminfee) *(added v23.05)*
- **estimates** (array of objects): Feerate estimates from plugin which we are using (usuallly bcli) *(added v23.05)*:
- **blockcount** (u32): The number of blocks the feerate is expected to get a transaction in *(added v23.05)*
- **feerate** (u32): The feerate for this estimate, in given *style* *(added v23.05)*
Expand All @@ -63,6 +64,7 @@ On success, an object is returned, containing:
- **perkw** (object, optional): If *style* parameter was perkw:
- **min\_acceptable** (u32): The smallest feerate that you can use, usually the minimum relayed feerate of the backend
- **max\_acceptable** (u32): The largest feerate we will accept from remote negotiations. If a peer attempts to set the feerate higher than this we will unilaterally close the channel (or simply forget it if it's not open yet).
- **floor** (u32): The smallest feerate that our backend tells us it will accept (i.e. minrelayfee or mempoolminfee) *(added v23.05)*
- **estimates** (array of objects): Feerate estimates from plugin which we are using (usuallly bcli) *(added v23.05)*:
- **blockcount** (u32): The number of blocks the feerate is expected to get a transaction in *(added v23.05)*
- **feerate** (u32): The feerate for this estimate, in given *style* *(added v23.05)*
Expand Down Expand Up @@ -136,4 +138,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:c21d903c29fd6195d5890962eaa3265a26a57885b95714696916bd32168b66bc)
[comment]: # ( SHA256STAMP:4921275aec48da8b9ddcba5d4237efa72f06b6e005008f2c3aa7029d3bd187fd)
12 changes: 12 additions & 0 deletions doc/schemas/feerates.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"required": [
"min_acceptable",
"max_acceptable",
"floor",
"estimates"
],
"properties": {
Expand All @@ -26,6 +27,11 @@
"type": "u32",
"description": "The largest feerate we will accept from remote negotiations. If a peer attempts to set the feerate higher than this we will unilaterally close the channel (or simply forget it if it's not open yet)."
},
"floor": {
"type": "u32",
"added": "v23.05",
"description": "The smallest feerate that our backend tells us it will accept (i.e. minrelayfee or mempoolminfee)"
},
"estimates": {
"type": "array",
"added": "v23.05",
Expand Down Expand Up @@ -92,6 +98,7 @@
"required": [
"min_acceptable",
"max_acceptable",
"floor",
"estimates"
],
"properties": {
Expand All @@ -103,6 +110,11 @@
"type": "u32",
"description": "The largest feerate we will accept from remote negotiations. If a peer attempts to set the feerate higher than this we will unilaterally close the channel (or simply forget it if it's not open yet)."
},
"floor": {
"type": "u32",
"added": "v23.05",
"description": "The smallest feerate that our backend tells us it will accept (i.e. minrelayfee or mempoolminfee)"
},
"estimates": {
"type": "array",
"added": "v23.05",
Expand Down
3 changes: 3 additions & 0 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ static struct command_result *json_feerates(struct command *cmd,
feerate_to_style(feerate_min(cmd->ld, NULL), *style));
json_add_u64(response, "max_acceptable",
feerate_to_style(feerate_max(cmd->ld, NULL), *style));
json_add_u64(response, "floor",
feerate_to_style(get_feerate_floor(cmd->ld->topology),
*style));

json_array_start(response, "estimates");
assert(tal_count(topo->smoothed_feerates) == tal_count(topo->feerates[0]));
Expand Down
17 changes: 13 additions & 4 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,13 +1532,14 @@ def test_feerates(node_factory):
feerate = l1.rpc.parsefeerate(t)

# Query feerates (shouldn't give any!)
wait_for(lambda: len(l1.rpc.feerates('perkw')['perkw']) == 3)
wait_for(lambda: len(l1.rpc.feerates('perkw')['perkw']) == 4)
feerates = l1.rpc.feerates('perkw')
assert feerates['warning_missing_feerates'] == 'Some fee estimates unavailable: bitcoind startup?'
assert 'perkb' not in feerates
assert feerates['perkw']['max_acceptable'] == 2**32 - 1
assert feerates['perkw']['min_acceptable'] == 253
assert feerates['perkw']['min_acceptable'] == 253
assert feerates['perkw']['floor'] == 253
assert feerates['perkw']['estimates'] == []
for t in types:
assert t not in feerates['perkw']
Expand All @@ -1548,6 +1549,8 @@ def test_feerates(node_factory):
assert 'perkw' not in feerates
assert feerates['perkb']['max_acceptable'] == (2**32 - 1)
assert feerates['perkb']['min_acceptable'] == 253 * 4
# Note: This is floored at the FEERATE_FLOOR constant (253)
assert feerates['perkb']['floor'] == 1012
assert feerates['perkb']['estimates'] == []
for t in types:
assert t not in feerates['perkb']
Expand Down Expand Up @@ -1955,6 +1958,7 @@ def test_bitcoind_feerate_floor(node_factory, bitcoind):
"penalty": 30000,
"min_acceptable": 7500,
"max_acceptable": 600000,
"floor": 1012,
"estimates": [{"blockcount": 2,
"feerate": 60000,
"smoothed_feerate": 60000},
Expand Down Expand Up @@ -1993,6 +1997,7 @@ def test_bitcoind_feerate_floor(node_factory, bitcoind):
# This has increased (rounded up)
"min_acceptable": 20004,
"max_acceptable": 600000,
"floor": 20004,
"estimates": [{"blockcount": 2,
"feerate": 60000,
"smoothed_feerate": 60000},
Expand Down Expand Up @@ -2034,6 +2039,7 @@ def test_bitcoind_feerate_floor(node_factory, bitcoind):
# This has increased (rounded up)
"min_acceptable": 30004,
"max_acceptable": 600000,
"floor": 30004,
"estimates": [{"blockcount": 2,
"feerate": 60000,
"smoothed_feerate": 60000},
Expand Down Expand Up @@ -2987,7 +2993,8 @@ def test_force_feerates(node_factory):
"penalty": 1111,
"min_acceptable": 1875,
"max_acceptable": 150000,
"estimates": estimates}
"estimates": estimates,
"floor": 253}

l1.stop()
l1.daemon.opts['force-feerates'] = '1111/2222'
Expand All @@ -3001,7 +3008,8 @@ def test_force_feerates(node_factory):
"penalty": 2222,
"min_acceptable": 1875,
"max_acceptable": 150000,
"estimates": estimates}
"estimates": estimates,
"floor": 253}

l1.stop()
l1.daemon.opts['force-feerates'] = '1111/2222/3333/4444/5555/6666'
Expand All @@ -3015,7 +3023,8 @@ def test_force_feerates(node_factory):
"penalty": 6666,
"min_acceptable": 1875,
"max_acceptable": 150000,
"estimates": estimates}
"estimates": estimates,
"floor": 253}


def test_datastore_escapeing(node_factory):
Expand Down

0 comments on commit 3a3370f

Please sign in to comment.