prusnak / suez

Tool for pretty printing and optimizing Lightning Network channels.
GNU General Public License v3.0
78 stars 20 forks source link

Remote fees #8

Closed hosiawak closed 3 years ago

hosiawak commented 3 years ago

I think remote fees are not calculated correcty:

https://github.com/prusnak/suez/blob/master/lndclient.py#L75

self.channels[cin].remote_fees += fee

The fee on the incoming channel (the remote party fee) is their base fee + amount * fee_rate but here you're using our fee.

This should be:

`self.channels[cin].remote_fees += (self.channels[cin].remote_fee_base + forward_amount * self.channels[cin].remote_fee_base / 10000) / 1000

or something along these lines.

What do you think @prusnak ?

hosiawak commented 3 years ago

The above is just an estimate that assumes fixed remote fees for the given forwarding period. To get the exact number we'd have to track remote fee changes.

prusnak commented 3 years ago

I am thinking of dropping remote fees completely, because these are not accurate. Also I am not that sure whether these should be an important factor whether to keep/close/rebalance the channel.

hosiawak commented 3 years ago

I think they're better than nothing though (after my fix below). I was able to quickly identify which remote nodes made more sats by forwarding than my node. Unless people actively manage their fees they don't change often so I think it's a reasonable assumption to make these days.

The exact fix is below (you have to adapt it to LND, I'm running this on C-Lightning):

        for fe in fwd_events:
            cin = fe["in_channel"]
            cout = fe["out_channel"]
            ts = int(fe["resolved_time"])
            fee = int(fe["fee"] / 1000)
            amount_in = int(fe["in_msatoshi"] / 1000)
            if cin in self.channels:
                self.channels[cin].last_forward = max(
                    ts, self.channels[cin].last_forward
                )
                self.channels[cin].remote_fees += int((self.channels[cin].remote_base_fee + (self.channels[cin].remote_fee_rate * amount_in / 1000)) / 1000)
            if cout in self.channels:
                self.channels[cout].last_forward = max(
                    ts, self.channels[cout].last_forward
                )
                self.channels[cout].local_fees += fee
prusnak commented 3 years ago

Fixed in 8f07c6f7e9987c8107467f15856d4336e6907157

Thanks!