From 00151033e9e735b06b3aa55aa0625cb51e980f3d Mon Sep 17 00:00:00 2001 From: rkfg Date: Sat, 14 Jan 2023 20:33:17 +0300 Subject: [PATCH] Get rid of global var --- channels.go | 2 +- main.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/channels.go b/channels.go index 242efec..a1d2311 100644 --- a/channels.go +++ b/channels.go @@ -64,7 +64,7 @@ func (r *regolancer) getChannelCandidates(fromPerc, toPerc, amount int64) error for _, c := range r.channels { - if params.ExcludeChannelAge != 0 && uint64(info.BlockHeight)-getChannelAge(c.ChanId) < params.ExcludeChannelAge { + if params.ExcludeChannelAge != 0 && uint64(r.blockHeight)-getChannelAge(c.ChanId) < params.ExcludeChannelAge { continue } diff --git a/main.go b/main.go index fb42822..3915301 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,6 @@ type configParams struct { } var params, cfgParams configParams -var info *lnrpc.GetInfoResponse type failedRoute struct { channelPair [2]*lnrpc.Channel @@ -85,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{} @@ -318,11 +318,12 @@ func main() { defer mainCtxCancel() infoCtx, infoCtxCancel := context.WithTimeout(mainCtx, time.Second*time.Duration(params.TimeoutInfo)) defer infoCtxCancel() - info, err = r.lnClient.GetInfo(infoCtx, &lnrpc.GetInfoRequest{}) + info, err := r.lnClient.GetInfo(infoCtx, &lnrpc.GetInfoRequest{}) if err != nil { 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)