Skip to content

Commit

Permalink
chaintopology: Add the cost of HTLCs transactions to json_feerates
Browse files Browse the repository at this point in the history
Changelog-Changed: "htlc_timeout_satoshis" and "htlc_success_satoshis" fields have been added to the `feerates` command.
  • Loading branch information
darosior committed Mar 11, 2020
1 parent e3f12af commit 9e4102e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ static struct command_result *json_feerates(struct command *cmd,
/* eg. 02000000000101c4fecaae1ea940c15ec502de732c4c386d51f981317605bbe5ad2c59165690ab00000000009db0e280010a2d0f00000000002200208d290003cedb0dd00cd5004c2d565d55fc70227bf5711186f4fa9392f8f32b4a0400483045022100952fcf8c730c91cf66bcb742cd52f046c0db3694dc461e7599be330a22466d790220740738a6f9d9e1ae5c86452fa07b0d8dddc90f8bee4ded24a88fe4b7400089eb01483045022100db3002a93390fc15c193da57d6ce1020e82705e760a3aa935ebe864bd66dd8e8022062ee9c6aa7b88ff4580e2671900a339754116371d8f40eba15b798136a76cd150147522102324266de8403b3ab157a09f1f784d587af61831c998c151bcc21bb74c2b2314b2102e3bd38009866c9da8ec4aa99cc4ea9c6c0dd46df15c61ef0ce1f271291714e5752ae9a3ed620 == weight 598 */
json_add_u64(response, "unilateral_close_satoshis",
unilateral_feerate(cmd->ld->topology) * 598 / 1000);
/* From https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#expected-weight-of-htlc-timeout-and-htlc-success-transactions,
* htlc_timeout weight is 663, and htlc_success is 703. */
json_add_u64(response, "htlc_timeout_satoshis",
htlc_resolution_feerate(cmd->ld->topology) * 663 / 1000);
json_add_u64(response, "htlc_success_satoshis",
htlc_resolution_feerate(cmd->ld->topology) * 703 / 1000);
json_object_end(response);
}

Expand Down
7 changes: 6 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,10 +1414,15 @@ def test_feerates(node_factory):
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']) == 5
assert feerates['onchain_fee_estimates']['opening_channel_satoshis'] == feerates['perkw']['opening'] * 702 // 1000
assert feerates['onchain_fee_estimates']['mutual_close_satoshis'] == feerates['perkw']['mutual_close'] * 673 // 1000
assert feerates['onchain_fee_estimates']['unilateral_close_satoshis'] == feerates['perkw']['unilateral_close'] * 598 // 1000
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"]
assert htlc_timeout_cost == htlc_feerate * 663 // 1000
assert htlc_success_cost == htlc_feerate * 703 // 1000


def test_logging(node_factory):
Expand Down

0 comments on commit 9e4102e

Please sign in to comment.