autopilot: rename to Capacity to Balance, define ChannelInfo()

We rename the field Capacity on local channels to Balance, define a new
method ChannelInfo on the manager config that let us query the database
for our latest channels state. Using this we will use the current local
balance instead of the channel capacity when doing allocation
calculations.
This commit is contained in:
Johan T. Halseth
2020-10-02 14:49:02 +02:00
parent d40cf6b592
commit dbeafe8832
7 changed files with 70 additions and 48 deletions

View File

@ -5,6 +5,7 @@ import (
"sync"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing"
@ -25,6 +26,10 @@ type ManagerCfg struct {
// channels managed by this node.
ChannelState func() ([]LocalChannel, error)
// ChannelInfo is a function closure that returns the channel managed
// by the node given by the passed channel point.
ChannelInfo func(wire.OutPoint) (*LocalChannel, error)
// SubscribeTransactions is used to get a subscription for transactions
// relevant to this node's wallet.
SubscribeTransactions func() (lnwallet.TransactionSubscription, error)
@ -194,18 +199,16 @@ func (m *Manager) StartAgent() error {
// opened, then we'll convert it to the
// autopilot.Channel format, and notify
// the pilot of the new channel.
chanNode := NewNodeID(
edgeUpdate.ConnectingNode,
)
chanID := lnwire.NewShortChanIDFromInt(
edgeUpdate.ChanID,
)
edge := LocalChannel{
ChanID: chanID,
Capacity: edgeUpdate.Capacity,
Node: chanNode,
cp := edgeUpdate.ChanPoint
edge, err := m.cfg.ChannelInfo(cp)
if err != nil {
log.Errorf("Unable to fetch "+
"channel info for %v: "+
"%v", cp, err)
continue
}
pilot.OnChannelOpen(edge)
pilot.OnChannelOpen(*edge)
}
// For each closed channel, we'll obtain