cashubtc/cashu-ts

NUT-08 dynamic output count log(0)

callebtc opened this issue ยท 5 comments

If the fee reserve is 0 sat, the log will fail. Therefore

def calculate_number_of_blank_outputs(fee_reserve_sat: int):
    assert fee_reserve_sat >= 0, "Fee reserve can't be negative."
    if fee_reserve_sat == 0:
        return 0
    return max(math.ceil(math.log2(fee_reserve_sat)), 1)

The code in cashu-ts runs as per protocol, but it is not so straight forward to follow why. I think it would make sense to implement it in the way @callebtc proposed.

Right now:

0 -> -Infinity this works because -infinity will be smaller than 0 and we won't enter the loop. So 0 messages get created
1 -> 0 which equates to falsy and thus we return 1 and create one message

changing to the code proposed would make it easier to understand what's happening

A Test with 0 Fee

test('test payLnInvoice base case', async () => {

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... ๐Ÿ˜œ๐Ÿ˜…

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... ๐Ÿ˜œ๐Ÿ˜…

Never argue with JS! ๐Ÿซจ

changing to the code proposed would make it easier to understand what's happening

We have a test and its works soo.... ๐Ÿ˜œ๐Ÿ˜…

Never argue with JS! ๐Ÿซจ

Never argue with my tests