From 602856750b3b5b4eea1fd9d979c336a755e51806 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 23 Aug 2018 18:52:49 -0700 Subject: [PATCH] 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. --- autopilot/agent.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/autopilot/agent.go b/autopilot/agent.go index 6e521ba6..d7c14e23 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -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()