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

Fix rebalance plugin #501

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Community curated plugins for Core-Lightning.
| [poncho][poncho] | Turns CLN into a [hosted channels][blip12] provider |
| [pruning][pruning] | This plugin manages pruning of bitcoind such that it can always sync |
| [python-teos][python-teos] | The Eye of Satoshi - Lightning Watchtower |
| [rebalance][rebalance] | Keeps your channels balanced |
| [reckless][reckless] | An **experimental** plugin manager (search/install plugins) |
| [sauron][sauron] | A Bitcoin backend relying on [Esplora][esplora]'s API |
| [sitzprobe][sitzprobe] | A Lightning Network payment rehearsal utility |
Expand Down Expand Up @@ -62,7 +63,6 @@ If you like a plugin from that list, feel free to update and fix it, so we can u
| [paytest][paytest] | A plugin to benchmark the performance of the ~pay~ plugin |
| [probe][probe] | Regularly probes the network for stability |
| [prometheus][prometheus] | Lightning node exporter for the prometheus timeseries server |
| [rebalance][rebalance] | Keeps your channels balanced |
| [summary][summary] | Print a nice summary of the node status |

## Installation
Expand Down Expand Up @@ -242,7 +242,7 @@ Python plugins developers must ensure their plugin to work with all Python versi
[python-api]: https://github.com/ElementsProject/lightning/tree/master/contrib/pylightning
[python-api-pypi]: https://pypi.org/project/pylightning/
[python-teos]: https://github.com/talaia-labs/python-teos
[rebalance]: https://github.com/lightningd/plugins/tree/master/archived/rebalance
[rebalance]: https://github.com/lightningd/plugins/tree/master/rebalance
[reckless]: https://github.com/darosior/reckless
[reporter]: https://github.com/LNOpenMetrics/go-lnmetrics.reporter
[sauron]: https://github.com/lightningd/plugins/tree/master/sauron
Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 15 additions & 15 deletions archived/rebalance/rebalance.py → rebalance/rebalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,14 @@ def check_liquidity_threshold(channels: list, threshold: Millisatoshi):
total = sum(ch["total_msat"] for ch in channels)
required = Millisatoshi(0)
for ch in channels:
required += min(threshold, ch["total_msat"] / 2)
required += min(threshold, Millisatoshi(ch["total_msat"]) / 2)
return required < our and required < total - our


def get_enough_liquidity_threshold(channels: list):
low = Millisatoshi(0)
biggest_channel = max(channels, key=lambda ch: ch["total_msat"])
high = biggest_channel["total_msat"] / 2
high = Millisatoshi(biggest_channel["total_msat"]) / 2
while True:
mid = (low + high) / 2
if high - low < Millisatoshi("1sat"):
Expand All @@ -498,20 +498,20 @@ def get_ideal_ratio(channels: list, enough_liquidity: Millisatoshi):
# small channels should have a 50/50 liquidity ratio to be usable
# and big channels can store the remaining liquidity above the threshold
assert len(channels) > 0
our = sum(ch["to_us_msat"] for ch in channels)
total = sum(ch["total_msat"] for ch in channels)
our = sum(Millisatoshi(ch["to_us_msat"]) for ch in channels)
total = sum(Millisatoshi(ch["total_msat"]) for ch in channels)
chs = list(channels) # get a copy!
while len(chs) > 0:
ratio = int(our) / int(total)
smallest_channel = min(chs, key=lambda ch: ch["total_msat"])
if smallest_channel["total_msat"] * min(ratio, 1 - ratio) > enough_liquidity:
if Millisatoshi(smallest_channel["total_msat"]) * min(ratio, 1 - ratio) > enough_liquidity:
break
min_liquidity = min(smallest_channel["total_msat"] / 2, enough_liquidity)
diff = smallest_channel["total_msat"] * ratio
min_liquidity = min(Millisatoshi(smallest_channel["total_msat"]) / 2, enough_liquidity)
diff = Millisatoshi(smallest_channel["total_msat"]) * ratio
diff = max(diff, min_liquidity)
diff = min(diff, smallest_channel["total_msat"] - min_liquidity)
diff = min(diff, Millisatoshi(smallest_channel["total_msat"]) - min_liquidity)
our -= diff
total -= smallest_channel["total_msat"]
total -= Millisatoshi(smallest_channel["total_msat"])
chs.remove(smallest_channel)
assert 0 <= ratio and ratio <= 1
return ratio
Expand Down Expand Up @@ -552,14 +552,14 @@ def get_chan(scid: str):

def liquidity_info(channel, enough_liquidity: Millisatoshi, ideal_ratio: float):
liquidity = {
"our": channel["to_us_msat"],
"their": channel["total_msat"] - channel["to_us_msat"],
"min": min(enough_liquidity, channel["total_msat"] / 2),
"max": max(a_minus_b(channel["total_msat"], enough_liquidity), channel["total_msat"] / 2),
"our": Millisatoshi(channel["to_us_msat"]),
"their": Millisatoshi(channel["total_msat"] - channel["to_us_msat"]),
"min": min(enough_liquidity, Millisatoshi(channel["total_msat"]) / 2),
"max": max(a_minus_b(Millisatoshi(channel["total_msat"]), enough_liquidity), Millisatoshi(channel["total_msat"]) / 2),
"ideal": {}
}
liquidity["ideal"]["our"] = min(max(channel["total_msat"] * ideal_ratio, liquidity["min"]), liquidity["max"])
liquidity["ideal"]["their"] = min(max(channel["total_msat"] * (1 - ideal_ratio), liquidity["min"]), liquidity["max"])
liquidity["ideal"]["our"] = min(max(Millisatoshi(channel["total_msat"]) * ideal_ratio, liquidity["min"]), liquidity["max"])
liquidity["ideal"]["their"] = min(max(Millisatoshi(channel["total_msat"]) * (1 - ideal_ratio), liquidity["min"]), liquidity["max"])
return liquidity


Expand Down
File renamed without changes.
File renamed without changes.
Loading