Lnd: Feature Request: Rebalance command

Created on 22 Jul 2018  路  20Comments  路  Source: lightningnetwork/lnd

It would be really nice to have a Rebalance command with 3 arguments: Outgoing channel ID(optional), Incoming channel ID(optional), and amount.

This would automatically find a route to the next to last hop (you're the last hop), then get all the info it needs for the incoming channel and adds the last route, creates a pay request, and uses sendtoroute to fulfill the request.

If outgoing or incoming channels are not specified, this could be populated a couple ways:
One: find an unbalanced channel(s) that's used the least amount
Two: Find the most unbalanced channel(s).

Steps:
Calls getchaninfo [Incoming ID] to get the [Node ID of next to last hop], [TimeLockDelta], [Chan_Capacity], [FeeBase], and [FeeRate]
Calls queryroutes [Node ID of next to last hop]
Creates payrequest [Amount] and passes [payHash] to SendToRoute
Calls SendToRoute, adding in the last hop, and making changes based on [TimeLockDeta], [FeeBase], and [FeeRate] from the next to last hop

This is quite tedious/difficult to do manually, but extremely simple to do in the code, as for the most part it's just calling existing functions. It'd just have to make some mods to what Queryroutes returns to add in the last hop and account for [TimeLockDeta], [FeeBase], and [FeeRate] from the next to last hop

Mods to queryroute returns would be:
Append
{
"chan_id": "[Incoming Channel ID]",
"chan_capacity": "[Incoming Chan_capacity]",
"amt_to_forward": "[Amount]",
"fee": "0",
"expiry": [expiry returned from Queryroutes] + [TimeLockDelta],
"amt_to_forward_msat": "[Amount] * 1000",
"fee_msat": "0"
}
What was "the last hop" that was returned from QueryRoutes is now the "next to last hop", so fees have to be calculated.
Change Fee_Msat from 0 to [Amount] * [FeeRate]/ 1,000,000 + [FeeBase]
Change fee from zero to [Fee_Msat]/1000

Total_time_Lock = Total_time_Lock + [TimeLockDeta] of Next to Last hop]
Total_fees = Total_fees + [fee of next to last hop]
Total_amount = [Amount] + [New total_fees value]

P4 advanced enhancement feature request

Most helpful comment

See https://github.com/C-Otto/rebalance-lnd for a python script

All 20 comments

This is quite tedious/difficult to do manually, but extremely simple to do in the code

Indeed, which is why it should likely be done by external programs. Several routing node operators already have scripts they use to rebalance their channels via the sendtoroute RPC call.

i've discovered it is a bit early to do this though.

it would be helpful with better error-reporting on sendtoroute with specified channels on failures etc.

also i would love addition of timestamp and flags from msg258 in describegraph to better guess which intermediate channels are more likely to be active. the success rate for each attempt is very low today.

also all the htlc:s that are sent during rebalancing easily clog up and triggers some nodes to close channels.

@Roasbeef you can use sendtoroute to move sat from one channel to other? I tried this and didn't work but was preparing routes manualy so if it can be done i had to screw something up. So can it be done?

It can be done. Double check your script.

@Roasbeef so how this route should looks like?
lets say we have nide A with channels:

A1 - X - B1

A2 - Y - B2

B1 - B2

If i want to sent from A1 to B2 should it looke like this?
A1, X, B1, B2, Y, A2?

@Roasbeef any chance for tool to find route between 2 given channels?

It wouldn't even be that hard. Just change the existing commands to "If Destination = source, allow to appear twice and only twice in route" Or something similar. It's not difficult to allow the existing commands find a route back to itself, without creating infinite loops.

Essentially:
If Source = Destination, delete source from Node Index OR don't add it in the first place. (But, by leaving first channel in channel index, it prevents it from going back in the outgoing channel.)
Add this in pathfind.go somewhere around line 287. A single line of code should fix this. And, if it's added outside of the loop, the line only executes once.

This would allow self routing, without any major changes.

Also, Func FindPaths would have to be modified:
If r.selfNode.PubKeyBytes = target
{
Then delete vertex from ignored vertexes (or don't add it)
}

Sorry, I don't know the exact syntax for GO.

Once self routing is allowed.
Then the rebalance command would just pick a exit and entrance channel. [And provide a warning of fees BEFORE submitting the transaction, and require "Accept".]
Since you're manually picking the next to last hop, they might have extremely high fees than one doesn't necessarily know about.

It wouldn't even be that hard.

I patiently await your PR!

@Roasbeef
Ya, apparently you don't prevent looping with yourself via ignorednodes, so not as trivial as I hoped.

I'm tinkering around with allowing routing with self...
First issue: Oh, I'm already at my target... don't bother searching any more -> resolved
Second issue: Shortest path is zero -> resolved
Third issue: Dang infinite loops... ^_^

It'd be much easier for someone familiar with GO and how this whole path thing works. ;)

Third issue: Infinite loops -> Resolved
Fourth issue: Tries to come in paths we know have zero balance on remote end. Need to flip Bandwidth hint

@halfik
https://github.com/lightningnetwork/lnd/pull/1751 gives the ability to find path back to self (use queryRoutes and pick the path you want)

https://github.com/lightningnetwork/lnd/pull/1759 adds rebalance command and adds "incoming" and "outgoing" arguments to queryroutes.

See https://github.com/C-Otto/rebalance-lnd for a python script

It does not seem that https://github.com/C-Otto/rebalance-lnd works anymore, sort of abandoned...

And they are dead set on not having it internally, no matter how much of a basic requirement it is.
They've closed out all my PRs.
When done in a script the entire pathfinding algorithm has to be re-written.

@MrManPew did you file a bug? I don't know of any issue.

@C-Otto thank you for fixing the problems. - https://github.com/C-Otto/rebalance-lnd/issues/69

Closed by #3736.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joaodealmeida picture joaodealmeida  路  3Comments

qubenix picture qubenix  路  3Comments

joostjager picture joostjager  路  3Comments

ealymbaev picture ealymbaev  路  3Comments

AnthonyRonning picture AnthonyRonning  路  3Comments