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.
|
// time.
|
||||||
chanOpenFailures chan *chanOpenFailureUpdate
|
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
|
// totalBalance is the total number of satoshis the backing wallet is
|
||||||
// known to control at any given instance. This value will be updated
|
// known to control at any given instance. This value will be updated
|
||||||
// when the agent receives external balance update signals.
|
// 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),
|
balanceUpdates: make(chan *balanceUpdate, 1),
|
||||||
nodeUpdates: make(chan *nodeUpdates, 1),
|
nodeUpdates: make(chan *nodeUpdates, 1),
|
||||||
chanOpenFailures: make(chan *chanOpenFailureUpdate, 1),
|
chanOpenFailures: make(chan *chanOpenFailureUpdate, 1),
|
||||||
|
heuristicUpdates: make(chan *heuristicUpdate, 1),
|
||||||
pendingOpenUpdates: make(chan *chanPendingOpenUpdate, 1),
|
pendingOpenUpdates: make(chan *chanPendingOpenUpdate, 1),
|
||||||
failedNodes: make(map[NodeID]struct{}),
|
failedNodes: make(map[NodeID]struct{}),
|
||||||
pendingConns: 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.
|
// a previous channel open failed, and that it might be possible to try again.
|
||||||
type chanOpenFailureUpdate struct{}
|
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
|
// chanCloseUpdate is a type of external state update that indicates that the
|
||||||
// backing Lightning Node has closed a previously open channel.
|
// backing Lightning Node has closed a previously open channel.
|
||||||
type chanCloseUpdate struct {
|
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
|
// 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
|
// 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
|
// 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 " +
|
log.Debugf("Node updates received, assessing " +
|
||||||
"need for more channels")
|
"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
|
// The agent has been signalled to exit, so we'll bail out
|
||||||
// immediately.
|
// immediately.
|
||||||
case <-a.quit:
|
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
|
// SetNodeScores is used to set the scores of the given heuristic, if it is
|
||||||
// active, and ScoreSettable.
|
// active, and ScoreSettable.
|
||||||
func (m *Manager) SetNodeScores(name string, scores map[NodeID]float64) error {
|
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
|
// It must be ScoreSettable to be available for external
|
||||||
// scores.
|
// scores.
|
||||||
s, ok := m.cfg.PilotCfg.Heuristic.(ScoreSettable)
|
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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
2
pilot.go
2
pilot.go
@ -31,7 +31,7 @@ func validateAtplCfg(cfg *autoPilotConfig) ([]*autopilot.WeightedHeuristic,
|
|||||||
for _, a := range autopilot.AvailableHeuristics {
|
for _, a := range autopilot.AvailableHeuristics {
|
||||||
heuristicsStr += fmt.Sprintf(" '%v' ", a.Name())
|
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,
|
// We'll go through the config and make sure all the heuristics exists,
|
||||||
// and that the sum of their weights is 1.0.
|
// and that the sum of their weights is 1.0.
|
||||||
|
Loading…
Reference in New Issue
Block a user