autopilot/agent: add OnNodeUpdates signal

Adds a new external signal alerting autopilot that
new nodes have been added to the channel graph or
an existing node has modified its channel
announcment. This allows autopilot to examine its
current state, and attempt to open channels if our
target state is not yet met.
This commit is contained in:
Conner Fromknecht 2018-08-23 18:52:49 -07:00
parent 8de84c4576
commit 602856750b
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

View File

@ -186,6 +186,10 @@ type balanceUpdate struct {
balanceDelta btcutil.Amount
}
// nodeUpdates is a type of external state update that reflects an addition or
// modification in channel graph node membership.
type nodeUpdates struct{}
// chanOpenUpdate is a type of external state update that indicates a new
// channel has been opened, either by the Agent itself (within the main
// controller loop), or by an external user to the system.
@ -222,6 +226,20 @@ func (a *Agent) OnBalanceChange(delta btcutil.Amount) {
}()
}
// OnNodeUpdates is a callback that should be executed each time our channel
// graph has new nodes or their node announcements are updated.
func (a *Agent) OnNodeUpdates() {
a.wg.Add(1)
go func() {
defer a.wg.Done()
select {
case a.stateUpdates <- &nodeUpdates{}:
case <-a.quit:
}
}()
}
// OnChannelOpen is a callback that should be executed each time a new channel
// is manually opened by the user or any system outside the autopilot agent.
func (a *Agent) OnChannelOpen(c Channel) {
@ -417,6 +435,14 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
}
updateBalance()
// New nodes have been added to the graph or their node
// announcements have been updated. We will consider
// opening channels to these nodes if we haven't
// stabilized.
case *nodeUpdates:
log.Infof("Node updates received, assessing " +
"need for more channels")
}
pendingMtx.Lock()