Add ignored channels

pull/1/head
rkfg 2 years ago
parent 652c186cf0
commit d626bd880c

@ -20,12 +20,19 @@ func (r *regolancer) getChannels() error {
return nil
}
func (r *regolancer) getChannelCandidates(fromPerc, toPerc, amount int64) error {
func (r *regolancer) getChannelCandidates(fromPerc, toPerc, amount int64, ignore []uint64) error {
ignoredSet := map[uint64]struct{}{}
for _, cid := range ignore {
ignoredSet[cid] = struct{}{}
}
for _, c := range r.channels {
if c.LocalBalance < c.Capacity*toPerc/100 && c.LocalBalance+amount < c.Capacity/2 {
r.toChannels = append(r.toChannels, c)
}
if c.RemoteBalance < c.Capacity*fromPerc/100 && c.RemoteBalance-amount < c.Capacity/2 {
if _, ok := ignoredSet[c.ChanId]; ok {
continue
}
r.fromChannels = append(r.fromChannels, c)
}
}

@ -19,17 +19,18 @@ var mainParams struct {
}
var params struct {
Connect string `short:"c" long:"connect" description:"connect to lnd using host:port" json:"connect"`
TLSCert string `short:"t" long:"tlscert" description:"path to tls.cert to connect" required:"false" json:"tlscert"`
MacaroonDir string `long:"macaroon.dir" description:"path to the macaroon directory" required:"false" json:"macaroon.dir"`
MacaroonFilename string `long:"macaroon.filename" description:"macaroon filename" json:"macaroon.filename"`
Network string `short:"n" long:"network" description:"bitcoin network to use" json:"network"`
FromPerc int64 `long:"pfrom" description:"channels with less than this inbound liquidity percentage will be considered as source channels" json:"pfrom"`
ToPerc int64 `long:"pto" description:"channels with less than this outbound liquidity percentage will be considered as target channels" json:"pto"`
Perc int64 `short:"p" long:"perc" description:"use this value as both pfrom and pto from above" json:"perc"`
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" json:"amount"`
EconRatio float64 `long:"econ-ratio" description:"economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)" json:"econ_ratio"`
ProbeSteps int `short:"b" long:"probe" description:"if the payment fails at the last hop try to probe lower amount using binary search" json:"probe_steps"`
Connect string `short:"c" long:"connect" description:"connect to lnd using host:port" json:"connect"`
TLSCert string `short:"t" long:"tlscert" description:"path to tls.cert to connect" required:"false" json:"tlscert"`
MacaroonDir string `long:"macaroon.dir" description:"path to the macaroon directory" required:"false" json:"macaroon.dir"`
MacaroonFilename string `long:"macaroon.filename" description:"macaroon filename" json:"macaroon.filename"`
Network string `short:"n" long:"network" description:"bitcoin network to use" json:"network"`
FromPerc int64 `long:"pfrom" description:"channels with less than this inbound liquidity percentage will be considered as source channels" json:"pfrom"`
ToPerc int64 `long:"pto" description:"channels with less than this outbound liquidity percentage will be considered as target channels" json:"pto"`
Perc int64 `short:"p" long:"perc" description:"use this value as both pfrom and pto from above" json:"perc"`
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" json:"amount"`
EconRatio float64 `long:"econ-ratio" description:"economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)" json:"econ_ratio"`
ProbeSteps int `short:"b" long:"probe" description:"if the payment fails at the last hop try to probe lower amount using binary search" json:"probe_steps"`
ExcludeChannels []uint64 `short:"e" long:"exclude-channel" description:"don't use this channel as outgoing (can be specified multiple times)" json:"exclude_channels"`
}
type regolancer struct {
@ -41,10 +42,11 @@ type regolancer struct {
toChannels []*lnrpc.Channel
nodeCache map[string]*lnrpc.NodeInfo
chanCache map[uint64]*lnrpc.ChannelEdge
ignoredPairs []*lnrpc.NodePair
}
func loadConfig() {
flags.Parse(&mainParams)
flags.NewParser(&mainParams, flags.Default|flags.IgnoreUnknown).Parse()
if mainParams.Config == "" {
return
}
@ -73,6 +75,9 @@ func main() {
if params.MacaroonFilename == "" {
params.MacaroonFilename = "admin.macaroon"
}
if params.Network == "" {
params.Network = "mainnet"
}
if params.FromPerc == 0 {
params.FromPerc = 50
}
@ -103,7 +108,7 @@ func main() {
if err != nil {
log.Fatal("Error listing own channels: ", err)
}
err = r.getChannelCandidates(params.FromPerc, params.ToPerc, params.Amount)
err = r.getChannelCandidates(params.FromPerc, params.ToPerc, params.Amount, params.ExcludeChannels)
if err != nil {
log.Fatal("Error choosing channels: ", err)
}

@ -28,6 +28,28 @@ func (r *regolancer) getChanInfo(ctx context.Context, chanId uint64) (*lnrpc.Cha
return c, nil
}
// currently unused
func (r *regolancer) buildIgnoredPairs(channels []uint64) error {
for _, chanId := range channels {
c, err := r.getChanInfo(context.Background(), chanId)
if err != nil {
return err
}
node1pk, err := hex.DecodeString(c.Node1Pub)
if err != nil {
return err
}
node2pk, err := hex.DecodeString(c.Node2Pub)
if err != nil {
return err
}
pair1 := lnrpc.NodePair{From: node1pk, To: node2pk}
pair2 := lnrpc.NodePair{From: node2pk, To: node1pk}
r.ignoredPairs = append(r.ignoredPairs, &pair1, &pair2)
}
return nil
}
func (r *regolancer) getRoutes(from, to uint64, amtMsat int64, ratio float64) ([]*lnrpc.Route, int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

Loading…
Cancel
Save