autopilot: trigger agent channel open on new scores
This commit adds a new signal to the autopilot agent, meant to signal when any of the available heuristics has gotten an update. We currently use this to trigger a new channel opening after the external scores have been updated.
This commit is contained in:
parent
f0ba4be758
commit
7524265ab1
@ -141,6 +141,10 @@ type Agent struct {
|
||||
// time.
|
||||
chanOpenFailures chan *chanOpenFailureUpdate
|
||||
|
||||
// heuristicUpdates is a channel where updates from active heurstics
|
||||
// will be sent.
|
||||
heuristicUpdates chan *heuristicUpdate
|
||||
|
||||
// totalBalance is the total number of satoshis the backing wallet is
|
||||
// known to control at any given instance. This value will be updated
|
||||
// when the agent receives external balance update signals.
|
||||
@ -179,6 +183,7 @@ func New(cfg Config, initialState []Channel) (*Agent, error) {
|
||||
balanceUpdates: make(chan *balanceUpdate, 1),
|
||||
nodeUpdates: make(chan *nodeUpdates, 1),
|
||||
chanOpenFailures: make(chan *chanOpenFailureUpdate, 1),
|
||||
heuristicUpdates: make(chan *heuristicUpdate, 1),
|
||||
pendingOpenUpdates: make(chan *chanPendingOpenUpdate, 1),
|
||||
failedNodes: make(map[NodeID]struct{}),
|
||||
pendingConns: make(map[NodeID]struct{}),
|
||||
@ -256,6 +261,13 @@ type chanPendingOpenUpdate struct{}
|
||||
// a previous channel open failed, and that it might be possible to try again.
|
||||
type chanOpenFailureUpdate struct{}
|
||||
|
||||
// heuristicUpdate is an update sent when one of the autopilot heuristics has
|
||||
// changed, and prompts the agent to make a new attempt at opening more
|
||||
// channels.
|
||||
type heuristicUpdate struct {
|
||||
heuristic AttachmentHeuristic
|
||||
}
|
||||
|
||||
// chanCloseUpdate is a type of external state update that indicates that the
|
||||
// backing Lightning Node has closed a previously open channel.
|
||||
type chanCloseUpdate struct {
|
||||
@ -329,6 +341,17 @@ func (a *Agent) OnChannelClose(closedChans ...lnwire.ShortChannelID) {
|
||||
}()
|
||||
}
|
||||
|
||||
// OnHeuristicUpdate is a method called when a heuristic has been updated, to
|
||||
// trigger the agent to do a new state assessment.
|
||||
func (a *Agent) OnHeuristicUpdate(h AttachmentHeuristic) {
|
||||
select {
|
||||
case a.heuristicUpdates <- &heuristicUpdate{
|
||||
heuristic: h,
|
||||
}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// mergeNodeMaps merges the Agent's set of nodes that it already has active
|
||||
// channels open to, with the other sets of nodes that should be removed from
|
||||
// consideration during heuristic selection. This ensures that the Agent doesn't
|
||||
@ -470,6 +493,12 @@ func (a *Agent) controller() {
|
||||
log.Debugf("Node updates received, assessing " +
|
||||
"need for more channels")
|
||||
|
||||
// Any of the deployed heuristics has been updated, check
|
||||
// whether we have new channel candidates available.
|
||||
case upd := <-a.heuristicUpdates:
|
||||
log.Debugf("Heuristic %v updated, assessing need for "+
|
||||
"more channels", upd.heuristic.Name())
|
||||
|
||||
// The agent has been signalled to exit, so we'll bail out
|
||||
// immediately.
|
||||
case <-a.quit:
|
||||
|
@ -358,6 +358,9 @@ func (m *Manager) queryHeuristics(nodes map[NodeID]struct{}, localState bool) (
|
||||
// SetNodeScores is used to set the scores of the given heuristic, if it is
|
||||
// active, and ScoreSettable.
|
||||
func (m *Manager) SetNodeScores(name string, scores map[NodeID]float64) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
// It must be ScoreSettable to be available for external
|
||||
// scores.
|
||||
s, ok := m.cfg.PilotCfg.Heuristic.(ScoreSettable)
|
||||
@ -376,5 +379,11 @@ func (m *Manager) SetNodeScores(name string, scores map[NodeID]float64) error {
|
||||
return fmt.Errorf("heuristic with name %v not found", name)
|
||||
}
|
||||
|
||||
// If the autopilot agent is active, notify about the updated
|
||||
// heuristic.
|
||||
if m.pilot != nil {
|
||||
m.pilot.OnHeuristicUpdate(m.cfg.PilotCfg.Heuristic)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
2
pilot.go
2
pilot.go
@ -31,7 +31,7 @@ func validateAtplCfg(cfg *autoPilotConfig) ([]*autopilot.WeightedHeuristic,
|
||||
for _, a := range autopilot.AvailableHeuristics {
|
||||
heuristicsStr += fmt.Sprintf(" '%v' ", a.Name())
|
||||
}
|
||||
availStr := fmt.Sprintf("Avaiblable heuristcs are: [%v]", heuristicsStr)
|
||||
availStr := fmt.Sprintf("Available heuristics are: [%v]", heuristicsStr)
|
||||
|
||||
// We'll go through the config and make sure all the heuristics exists,
|
||||
// and that the sum of their weights is 1.0.
|
||||
|
Loading…
Reference in New Issue
Block a user