From 2dbc4fe9734bd5865a879f1672ee4e0a35c72c0d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 27 Aug 2019 09:53:52 +0200 Subject: [PATCH] autopilot/agent: move expensive graph lookup after channel size check --- autopilot/agent.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/autopilot/agent.go b/autopilot/agent.go index 2fe123c9..452de41e 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -523,6 +523,17 @@ func (a *Agent) controller() { func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32, totalChans []Channel) error { + // As channel size we'll use the maximum channel size available. + chanSize := a.cfg.Constraints.MaxChanSize() + if availableFunds < chanSize { + chanSize = availableFunds + } + + if chanSize < a.cfg.Constraints.MinChanSize() { + return fmt.Errorf("not enough funds available to open a " + + "single channel") + } + // We're to attempt an attachment so we'll obtain the set of // nodes that we currently have channels with so we avoid // duplicate edges. @@ -571,17 +582,6 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32, return fmt.Errorf("unable to get graph nodes: %v", err) } - // As channel size we'll use the maximum channel size available. - chanSize := a.cfg.Constraints.MaxChanSize() - if availableFunds < chanSize { - chanSize = availableFunds - } - - if chanSize < a.cfg.Constraints.MinChanSize() { - return fmt.Errorf("not enough funds available to open a " + - "single channel") - } - // Use the heuristic to calculate a score for each node in the // graph. log.Debugf("Scoring %d nodes for chan_size=%v", len(nodes), chanSize)