Skip to content

Commit

Permalink
Merge pull request #52 from ziggie1984/channel-age
Browse files Browse the repository at this point in the history
  • Loading branch information
rkfg authored Jan 14, 2023
2 parents fe4caa2 + 0015103 commit 9a5116e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rebalance-lnd](https://github.com/accumulator/rebalance-lnd).
- timeouts can be customized
- JSON/TOML config file to set some defaults you prefer
- optional route probing using binary search to rebalance a smaller amount
- optional rapid rebalancing using the same route for further rebalances
- optional rapid rebalancing using the same route for further rebalances
unitl route is depleted in case a rebalance succeeds
- data caching to speed up alias resolution, quickly skip failing channel pairs
etc.
Expand Down Expand Up @@ -62,8 +62,8 @@ in `~/go/bin/linux_arm`.

```
Config:
-f, --config config file path
-f, --config config file path
Node Connection:
-c, --connect connect to lnd using host:port
-t, --tlscert path to tls.cert to connect
Expand All @@ -88,7 +88,7 @@ Common:
-e, --exclude-channel (DEPRECATED) don't use this channel at all (can be specified multiple times)
-d, --exclude-node (DEPRECATED) don't use this node for routing (can be specified multiple times)
--exclude don't use this node or your channel for routing (can be specified multiple times)
--to try only this channel or node as target (should satisfy other constraints too; can be specified multiple times)
--exclude-channel-age don't use channels opened less than this number of blocks ago --to try only this channel or node as target (should satisfy other constraints too; can be specified multiple times)
--from try only this channel or node as source (should satisfy other constraints too; can be specified multiple times)
--fail-tolerance a payment that differs from the prior attempt by this ppm will be cancelled
--allow-unbalance-from (DEPRECATED) let the source channel go below 50% local liquidity, use if you want to drain a channel; you should also set --pfrom to >50
Expand Down Expand Up @@ -198,9 +198,8 @@ continues.
# Docker Setup

In general its recommanded to run regolancer in a normal environment because it is
so easy to install as mentioned above. However if you want to run it in a docker
we also provide the Dockerfile and a docker-compose.yml so that you can easily
get started.
so easy to install as mentioned above. However if you want to run it in a docker
we also provide the Dockerfile so that you can easily get started.

Build the container or pull it:

Expand All @@ -224,7 +223,6 @@ alias regolancer="docker run --rm --network=umbrel_main_network -it -v /home/umb

For older versions of Umbrel please use `/home/umbrel/umbrel/lnd` instead of `/home/umbrel/umbrel/app-data/lightning/data/lnd`


# What's wrong with the other rebalancers

While I liked probing in `bos`, it has many downsides: gives up quickly on
Expand Down Expand Up @@ -288,6 +286,7 @@ during route construction. You can also disable them (it only happens on your
end so you'll be able to receive liquidity but not send it) but it hurts your
score on various sites so better not to do it. Increase fees or lower max_htlc and
you'll be good. You can set multiple brackets with multiple limits like:

- 20% local balance => set max_htlc to 0.1 of channel capacity (so it can
process ≈2 payments max or more smaller payments)
- 10% local balance => set max_htlc to 0.01 of channel capacity (small payments
Expand All @@ -306,6 +305,7 @@ accept contributions and suggestions though! For now I implemented almost
everything I needed, maybe except a couple of timeouts being configurable. But I
don't see much need for that as of now. The main goals and motivation for this
project were:

- make it reliable and robust so I don't have to babysit it (stop/restart if it
hangs, crashes or gives up early)
- make it fast and lightweight, don't stress `lnd` too much as it all should run
Expand All @@ -318,4 +318,4 @@ project were:
# Feedback and contact

We have a Matrix room to discuss this program and solve issues, feel free to
join [#regolancer:matrix.org](https://matrix.to/#/#regolancer:matrix.org)!
join [#regolancer:matrix.org](https://matrix.to/#/#regolancer:matrix.org)!
10 changes: 10 additions & 0 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (r *regolancer) getChannelCandidates(fromPerc, toPerc, amount int64) error

for _, c := range r.channels {

if params.ExcludeChannelAge != 0 && uint64(r.blockHeight)-getChannelAge(c.ChanId) < params.ExcludeChannelAge {
continue
}

if _, ok := r.excludeBoth[c.ChanId]; ok {
continue
}
Expand Down Expand Up @@ -200,6 +204,12 @@ func parseScid(chanId string) int64 {

}

func getChannelAge(chanId uint64) uint64 {
shortChanId := lnwire.NewShortChanIDFromInt(chanId)

return uint64(shortChanId.BlockHeight)
}

func (r *regolancer) getChannelForPeer(ctx context.Context, node []byte) []*lnrpc.Channel {

channels, err := r.lnClient.ListChannels(ctx, &lnrpc.ListChannelsRequest{ActiveOnly: true, PublicOnly: true, Peer: node})
Expand Down
3 changes: 3 additions & 0 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (r *regolancer) info(ctx context.Context) error {
}
}
fmt.Println()
if params.ExcludeChannelAge != 0 {
fmt.Printf("Channel age needs to be >= %s blocks\n", hiWhiteColor(params.ExcludeChannelAge))
}
fmt.Printf("Fail tolerance: %s ppm\n", formatAmt(int64(params.FailTolerance)))
printBooleanOption("Rapid rebalance", params.AllowRapidRebalance)
printBooleanOption("Lost profit accounting", params.LostProfit)
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type configParams struct {
ExcludeChannels []string `short:"e" long:"exclude-channel" description:"(DEPRECATED) don't use this channel at all (can be specified multiple times)" json:"exclude_channels" toml:"exclude_channels"`
ExcludeNodes []string `short:"d" long:"exclude-node" description:"(DEPRECATED) don't use this node for routing (can be specified multiple times)" json:"exclude_nodes" toml:"exclude_nodes"`
Exclude []string `long:"exclude" description:"don't use this node or your channel for routing (can be specified multiple times)" json:"exclude" toml:"exclude"`
ExcludeChannelAge uint64 `long:"exclude-channel-age" description:"don't use channels opened less than this number of blocks ago" json:"exclude_channel_age" toml:"exclude_channel_age"`
To []string `long:"to" description:"try only this channel or node as target (should satisfy other constraints too; can be specified multiple times)" json:"to" toml:"to"`
From []string `long:"from" description:"try only this channel or node as source (should satisfy other constraints too; can be specified multiple times)" json:"from" toml:"from"`
FailTolerance int64 `long:"fail-tolerance" description:"a payment that differs from the prior attempt by this ppm will be cancelled" json:"fail_tolerance" toml:"fail_tolerance"`
Expand Down Expand Up @@ -83,6 +84,7 @@ type regolancer struct {
lnClient lnrpc.LightningClient
routerClient routerrpc.RouterClient
myPK string
blockHeight uint32
channels []*lnrpc.Channel
fromChannels []*lnrpc.Channel
fromChannelId map[uint64]struct{}
Expand All @@ -104,7 +106,10 @@ type regolancer struct {
}

func loadConfig() {
flags.NewParser(&cfgParams, flags.None).Parse()
_, err := flags.NewParser(&cfgParams, flags.None).Parse()
if err != nil {
log.Fatalf("Error when parsing command line options: %s", err)
}

if cfgParams.Config == "" {
return
Expand Down Expand Up @@ -318,6 +323,7 @@ func main() {
log.Fatal(err)
}
r.myPK = info.IdentityPubkey
r.blockHeight = info.BlockHeight
err = r.getChannels(infoCtx)
if err != nil {
log.Fatal("Error listing own channels: ", err)
Expand Down

0 comments on commit 9a5116e

Please sign in to comment.