mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
feerate: include rough estimates of actual tx costs.
We could refine this later (based on existing wallet, for example), but this gives some estimate. [ Rename onchain_estimates -> onchain_fee_estimates Suggested-by: @SimonVrouwe ] [ Factor of 1000 fix Reported-by: @SimonVrouwe ] Suggested-by: @molxyz Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
14294642d2
commit
a4b952ebc7
7 changed files with 43 additions and 4 deletions
|
@ -22,7 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
- Sending lightningd a SIGHUP will make it reopen its `log-file`, if any.
|
||||
- Protocol: `option_data_loss_protect` now supported to protect peers
|
||||
against being out-of-date.
|
||||
- JSON API: `feerates` command to inject fee estimates manually.
|
||||
- JSON API: `feerates` command to inject fee estimates manually, and retrieve
|
||||
current estimates.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -407,6 +407,21 @@ static void start_fee_estimate(struct chain_topology *topo)
|
|||
update_feerates, topo);
|
||||
}
|
||||
|
||||
u32 mutual_close_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_NORMAL);
|
||||
}
|
||||
|
||||
u32 opening_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_NORMAL);
|
||||
}
|
||||
|
||||
u32 unilateral_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_URGENT);
|
||||
}
|
||||
|
||||
static void json_feerates(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
|
@ -478,6 +493,20 @@ static void json_feerates(struct command *cmd,
|
|||
if (missing)
|
||||
json_add_string(response, "warning",
|
||||
"Some fee estimates unavailable: bitcoind startup?");
|
||||
else {
|
||||
json_object_start(response, "onchain_fee_estimates");
|
||||
/* eg 020000000001016f51de645a47baa49a636b8ec974c28bdff0ac9151c0f4eda2dbe3b41dbe711d000000001716001401fad90abcd66697e2592164722de4a95ebee165ffffffff0240420f00000000002200205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cdb73f890000000000160014c2ccab171c2a5be9dab52ec41b825863024c54660248304502210088f65e054dbc2d8f679de3e40150069854863efa4a45103b2bb63d060322f94702200d3ae8923924a458cffb0b7360179790830027bb6b29715ba03e12fc22365de1012103d745445c9362665f22e0d96e9e766f273f3260dea39c8a76bfa05dd2684ddccf00000000 == weight 702 */
|
||||
json_add_num(response, "opening_channel_satoshis",
|
||||
opening_feerate(cmd->ld->topology) * 702 / 1000);
|
||||
/* eg. 02000000000101afcfac637d44d4e0df52031dba55b18d3f1bd79ad4b7ebbee964f124c5163dc30100000000ffffffff02400d03000000000016001427213e2217b4f56bd19b6c8393dc9f61be691233ca1f0c0000000000160014071c49cad2f420f3c805f9f6b98a57269cb1415004004830450221009a12b4d5ae1d41781f79bedecfa3e65542b1799a46c272287ba41f009d2e27ff0220382630c899207487eba28062f3989c4b656c697c23a8c89c1d115c98d82ff261014730440220191ddf13834aa08ea06dca8191422e85d217b065462d1b405b665eefa0684ed70220252409bf033eeab3aae89ae27596d7e0491bcc7ae759c5644bced71ef3cccef30147522102324266de8403b3ab157a09f1f784d587af61831c998c151bcc21bb74c2b2314b2102e3bd38009866c9da8ec4aa99cc4ea9c6c0dd46df15c61ef0ce1f271291714e5752ae00000000 == weight 673 */
|
||||
json_add_u64(response, "mutual_close_satoshis",
|
||||
mutual_close_feerate(cmd->ld->topology) * 673 / 1000);
|
||||
/* eg. 02000000000101c4fecaae1ea940c15ec502de732c4c386d51f981317605bbe5ad2c59165690ab00000000009db0e280010a2d0f00000000002200208d290003cedb0dd00cd5004c2d565d55fc70227bf5711186f4fa9392f8f32b4a0400483045022100952fcf8c730c91cf66bcb742cd52f046c0db3694dc461e7599be330a22466d790220740738a6f9d9e1ae5c86452fa07b0d8dddc90f8bee4ded24a88fe4b7400089eb01483045022100db3002a93390fc15c193da57d6ce1020e82705e760a3aa935ebe864bd66dd8e8022062ee9c6aa7b88ff4580e2671900a339754116371d8f40eba15b798136a76cd150147522102324266de8403b3ab157a09f1f784d587af61831c998c151bcc21bb74c2b2314b2102e3bd38009866c9da8ec4aa99cc4ea9c6c0dd46df15c61ef0ce1f271291714e5752ae9a3ed620 == weight 598 */
|
||||
json_add_u64(response, "unilateral_close_satoshis",
|
||||
unilateral_feerate(cmd->ld->topology) * 598 / 1000);
|
||||
json_object_end(response);
|
||||
}
|
||||
|
||||
json_object_end(response);
|
||||
|
||||
command_success(cmd, response);
|
||||
|
|
|
@ -140,6 +140,10 @@ u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate);
|
|||
u32 feerate_min(struct lightningd *ld, bool *unknown);
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown);
|
||||
|
||||
u32 mutual_close_feerate(struct chain_topology *topo);
|
||||
u32 opening_feerate(struct chain_topology *topo);
|
||||
u32 unilateral_feerate(struct chain_topology *topo);
|
||||
|
||||
/* Broadcast a single tx, and rebroadcast as reqd (copies tx).
|
||||
* If failed is non-NULL, call that and don't rebroadcast. */
|
||||
void broadcast_tx(struct chain_topology *topo,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
static void update_feerates(struct lightningd *ld, struct channel *channel)
|
||||
{
|
||||
u8 *msg;
|
||||
u32 feerate = try_get_feerate(ld->topology, FEERATE_URGENT);
|
||||
u32 feerate = unilateral_feerate(ld->topology);
|
||||
|
||||
/* Nothing to do if we don't know feerate. */
|
||||
if (!feerate)
|
||||
|
|
|
@ -191,7 +191,7 @@ void peer_start_closingd(struct channel *channel,
|
|||
minfee = commit_tx_base_fee(feerate_min(ld, NULL), 0);
|
||||
|
||||
/* If we can't determine feerate, start at half unilateral feerate. */
|
||||
feerate = try_get_feerate(ld->topology, FEERATE_NORMAL);
|
||||
feerate = mutual_close_feerate(ld->topology);
|
||||
if (!feerate) {
|
||||
feerate = channel->channel_info.feerate_per_kw[LOCAL] / 2;
|
||||
if (feerate < feerate_floor())
|
||||
|
|
|
@ -764,7 +764,7 @@ static void json_fund_channel(struct command *cmd,
|
|||
struct pubkey *id;
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
u32 feerate_per_kw = try_get_feerate(cmd->ld->topology, FEERATE_NORMAL);
|
||||
u32 feerate_per_kw = opening_feerate(cmd->ld->topology);
|
||||
u8 *msg;
|
||||
|
||||
fc->cmd = cmd;
|
||||
|
|
|
@ -931,6 +931,11 @@ def test_feerates(node_factory):
|
|||
assert feerates['sipa']['max_acceptable'] == 15000 * 10
|
||||
assert feerates['sipa']['min_acceptable'] == 5000 // 2
|
||||
|
||||
assert len(feerates['onchain_fee_estimates']) == 3
|
||||
assert feerates['onchain_fee_estimates']['opening_channel_satoshis'] == feerates['sipa']['normal'] * 702 // 1000
|
||||
assert feerates['onchain_fee_estimates']['mutual_close_satoshis'] == feerates['sipa']['normal'] * 673 // 1000
|
||||
assert feerates['onchain_fee_estimates']['unilateral_close_satoshis'] == feerates['sipa']['urgent'] * 598 // 1000
|
||||
|
||||
|
||||
def test_logging(node_factory):
|
||||
# Since we redirect, node.start() will fail: do manually.
|
||||
|
|
Loading…
Add table
Reference in a new issue