Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote fees #8

Closed
hosiawak opened this issue Jun 9, 2021 · 4 comments
Closed

Remote fees #8

hosiawak opened this issue Jun 9, 2021 · 4 comments

Comments

@hosiawak
Copy link
Contributor

hosiawak commented Jun 9, 2021

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
Copy link
Contributor Author

hosiawak commented Jun 9, 2021

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
Copy link
Owner

prusnak commented Jun 9, 2021

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
Copy link
Contributor Author

hosiawak commented Jun 9, 2021

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
Copy link
Owner

prusnak commented Jun 9, 2021

Fixed in 8f07c6f

Thanks!

@prusnak prusnak closed this as completed Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants