bkpr: make sure there's always at least on difference in blockheights

We can't divide by zero, so make sure it's always 1 (with a small loss
of precision for other cases, ce la vie)
This commit is contained in:
niftynei 2022-07-19 17:04:39 +09:30 committed by Rusty Russell
parent 0c2b43b6b2
commit c1cef773ca
2 changed files with 12 additions and 2 deletions

View File

@ -342,8 +342,8 @@ void json_add_channel_apy(struct json_stream *res,
tal_fmt(apy, "%.4f%%", utilization * 100));
}
blocks_elapsed = apy->end_blockheight - apy->start_blockheight;
assert(blocks_elapsed > 0);
/* Can't divide by zero */
blocks_elapsed = apy->end_blockheight - apy->start_blockheight + 1;
/* APY (outbound) */
ok = calc_apy(apy->fees_out, apy->total_start_bal,

View File

@ -70,6 +70,16 @@ def test_pay(node_factory):
payments = l1.rpc.listsendpays(inv)['payments']
assert len(payments) == 1 and payments[0]['payment_preimage'] == preimage
# Check channels apy summary view of channel activity
apys_1 = l1.rpc.bkpr_channelsapy()['channels_apy']
apys_2 = l2.rpc.bkpr_channelsapy()['channels_apy']
assert apys_1[0]['channel_start_balance_msat'] == apys_2[0]['channel_start_balance_msat']
assert apys_1[0]['channel_start_balance_msat'] == apys_1[0]['our_start_balance_msat']
assert apys_2[0]['our_start_balance_msat'] == Millisatoshi(0)
assert apys_1[0]['routed_out_msat'] == apys_2[0]['routed_in_msat']
assert apys_1[0]['routed_in_msat'] == apys_2[0]['routed_out_msat']
@pytest.mark.developer("needs to deactivate shadow routing")
def test_pay_amounts(node_factory):