From bf7f392c11159852cd74cf0ee23e0ac8d9418122 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 11 Jul 2019 13:14:38 +0200 Subject: [PATCH] autopilot: use subtractFees when funding channel To make the autopilot able to account for fees, we let it use the subtractFees option when opening channels. This makes sure that each channel we attempt to open will eat at most Amt out of our budget. Previously fees would eat into our funds in addition, causing us to deplete our funds more than expected on each channel opening. --- autopilot/agent.go | 1 + autopilot/interface.go | 9 +++++---- pilot.go | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/autopilot/agent.go b/autopilot/agent.go index 8e625c148..2fe123c99 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -584,6 +584,7 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32, // 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) scores, err := a.cfg.Heuristic.NodeScores( a.cfg.Graph, totalChans, chanSize, nodes, ) diff --git a/autopilot/interface.go b/autopilot/interface.go index 34ef75978..b63661e31 100644 --- a/autopilot/interface.go +++ b/autopilot/interface.go @@ -188,10 +188,11 @@ func init() { // open a channel within the graph to a target peer, close targeted channels, // or add/remove funds from existing channels via a splice in/out mechanisms. type ChannelController interface { - // OpenChannel opens a channel to a target peer, with a capacity of the - // specified amount. This function should un-block immediately after - // the funding transaction that marks the channel open has been - // broadcast. + // OpenChannel opens a channel to a target peer, using at most amt + // funds. This means that the resulting channel capacity might be + // slightly less to account for fees. This function should un-block + // immediately after the funding transaction that marks the channel + // open has been broadcast. OpenChannel(target *btcec.PublicKey, amt btcutil.Amount) error // CloseChannel attempts to close out the target channel. diff --git a/pilot.go b/pilot.go index 5748cf974..9a0f402c0 100644 --- a/pilot.go +++ b/pilot.go @@ -100,6 +100,7 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey, req := &openChanReq{ targetPubkey: target, chainHash: *activeNetParams.GenesisHash, + subtractFees: true, localFundingAmt: amt, pushAmt: 0, minHtlc: minHtlc,