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

@ -260,16 +260,35 @@ func initAutoPilot(svr *server, cfg *lncfg.AutoPilot,
chanState := make([]autopilot.LocalChannel,
len(activeChannels))
for i, channel := range activeChannels {
localCommit := channel.LocalCommitment
balance := localCommit.LocalBalance.ToSatoshis()
chanState[i] = autopilot.LocalChannel{
ChanID: channel.ShortChanID(),
Capacity: channel.Capacity,
ChanID: channel.ShortChanID(),
Balance: balance,
Node: autopilot.NewNodeID(
channel.IdentityPub),
channel.IdentityPub,
),
}
}
return chanState, nil
},
ChannelInfo: func(chanPoint wire.OutPoint) (
*autopilot.LocalChannel, error) {
channel, err := svr.remoteChanDB.FetchChannel(chanPoint)
if err != nil {
return nil, err
}
localCommit := channel.LocalCommitment
return &autopilot.LocalChannel{
ChanID: channel.ShortChanID(),
Balance: localCommit.LocalBalance.ToSatoshis(),
Node: autopilot.NewNodeID(channel.IdentityPub),
}, nil
},
SubscribeTransactions: svr.cc.wallet.SubscribeTransactions,
SubscribeTopology: svr.chanRouter.SubscribeTopology,
}, nil