Skip to content

Commit

Permalink
Merge pull request #29 from rkfg/deprecate-allow-unbalance
Browse files Browse the repository at this point in the history
  • Loading branch information
rkfg authored Nov 7, 2022
2 parents bb98d08 + 779917d commit 19a61db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 4 additions & 13 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ func (r *regolancer) getChannelCandidates(fromPerc, toPerc, amount int64) error
}
if _, ok := r.excludeIn[c.ChanId]; !ok {
if _, ok := r.toChannelId[c.ChanId]; ok || len(r.toChannelId) == 0 {
if c.LocalBalance < c.Capacity*toPerc/100 && (params.AllowUnbalanceTo ||
c.LocalBalance+amount < c.Capacity/2) {
if c.LocalBalance < c.Capacity*toPerc/100 {
r.toChannels = append(r.toChannels, c)
}
}

}
if _, ok := r.excludeOut[c.ChanId]; !ok {
if _, ok := r.fromChannelId[c.ChanId]; ok || len(r.fromChannelId) == 0 {
if c.RemoteBalance < c.Capacity*fromPerc/100 &&
(params.AllowUnbalanceFrom ||
c.RemoteBalance+amount < c.Capacity/2) {
if c.RemoteBalance < c.Capacity*fromPerc/100 {
r.fromChannels = append(r.fromChannels, c)
}
}
Expand Down Expand Up @@ -136,17 +133,11 @@ func (r *regolancer) pickChannelPair(amount, minAmount int64,
}
fromChan = pair[0]
toChan = pair[1]
maxFrom := fromChan.Capacity/2 - fromChan.RemoteBalance
if params.AllowUnbalanceFrom {
maxFrom = fromChan.LocalBalance
}
maxFrom := fromChan.LocalBalance
if relFromAmount > 0 {
maxFrom = min(maxFrom, int64(float64(fromChan.Capacity)*relFromAmount)-fromChan.RemoteBalance)
}
maxTo := toChan.Capacity/2 - toChan.LocalBalance
if params.AllowUnbalanceTo {
maxTo = toChan.RemoteBalance
}
maxTo := toChan.RemoteBalance
if relToAmount > 0 {
maxTo = min(maxTo, int64(float64(toChan.Capacity)*relToAmount)-toChan.LocalBalance)
}
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ func preflightChecks(params *configParams) error {
(params.RelAmountFrom > 0 || params.RelAmountTo > 0) {
return fmt.Errorf("use either precise amount or relative amounts but not both")
}
if params.Amount == 0 && params.RelAmountFrom == 0 && params.RelAmountTo == 0 {
return fmt.Errorf("no amount specified, use either --amount, --rel-amount-from, or --rel-amount-to")
}
if params.FailTolerance == 0 {
params.FailTolerance = 1000
}
Expand All @@ -410,6 +413,10 @@ func preflightChecks(params *configParams) error {
}
}

if params.AllowUnbalanceFrom || params.AllowUnbalanceTo {
log.Print(infoColor("--allow-unbalance-from/to are deprecated and enabled by default, please remove them from your config or command line parameters"))
}

return nil

}
Expand Down

0 comments on commit 19a61db

Please sign in to comment.