autopilot: Exclude nodes that previously failed
This commit is contained in:
parent
a43d7d3532
commit
73468cf06e
@ -231,18 +231,21 @@ func (a *Agent) OnChannelClose(closedChans ...lnwire.ShortChannelID) {
|
|||||||
// channels open to, with the set of nodes that are pending new channels. This
|
// channels open to, with the set of nodes that are pending new channels. This
|
||||||
// ensures that the Agent doesn't attempt to open any "duplicate" channels to
|
// ensures that the Agent doesn't attempt to open any "duplicate" channels to
|
||||||
// the same node.
|
// the same node.
|
||||||
func mergeNodeMaps(a map[NodeID]struct{},
|
func mergeNodeMaps(a map[NodeID]struct{}, b map[NodeID]struct{},
|
||||||
b map[NodeID]Channel) map[NodeID]struct{} {
|
c map[NodeID]Channel) map[NodeID]struct{} {
|
||||||
|
|
||||||
c := make(map[NodeID]struct{}, len(a)+len(b))
|
res := make(map[NodeID]struct{}, len(a)+len(b)+len(c))
|
||||||
for nodeID := range a {
|
for nodeID := range a {
|
||||||
c[nodeID] = struct{}{}
|
res[nodeID] = struct{}{}
|
||||||
}
|
}
|
||||||
for nodeID := range b {
|
for nodeID := range b {
|
||||||
c[nodeID] = struct{}{}
|
res[nodeID] = struct{}{}
|
||||||
|
}
|
||||||
|
for nodeID := range c {
|
||||||
|
res[nodeID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeChanState merges the Agent's set of active channels, with the set of
|
// mergeChanState merges the Agent's set of active channels, with the set of
|
||||||
@ -280,6 +283,10 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
|
|||||||
// TODO(roasbeef): do we in fact need to maintain order?
|
// TODO(roasbeef): do we in fact need to maintain order?
|
||||||
// * use sync.Cond if so
|
// * use sync.Cond if so
|
||||||
|
|
||||||
|
// failedNodes lists nodes that we've previously attempted to initiate
|
||||||
|
// channels with, but didn't succeed.
|
||||||
|
failedNodes := make(map[NodeID]struct{})
|
||||||
|
|
||||||
// pendingOpens tracks the channels that we've requested to be
|
// pendingOpens tracks the channels that we've requested to be
|
||||||
// initiated, but haven't yet been confirmed as being fully opened.
|
// initiated, but haven't yet been confirmed as being fully opened.
|
||||||
// This state is required as otherwise, we may go over our allotted
|
// This state is required as otherwise, we may go over our allotted
|
||||||
@ -369,7 +376,7 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
|
|||||||
// we avoid duplicate edges.
|
// we avoid duplicate edges.
|
||||||
connectedNodes := a.chanState.ConnectedNodes()
|
connectedNodes := a.chanState.ConnectedNodes()
|
||||||
pendingMtx.Lock()
|
pendingMtx.Lock()
|
||||||
nodesToSkip := mergeNodeMaps(connectedNodes, pendingOpens)
|
nodesToSkip := mergeNodeMaps(connectedNodes, failedNodes, pendingOpens)
|
||||||
pendingMtx.Unlock()
|
pendingMtx.Unlock()
|
||||||
|
|
||||||
// If we reach this point, then according to our
|
// If we reach this point, then according to our
|
||||||
@ -428,6 +435,10 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
|
|||||||
pendingMtx.Lock()
|
pendingMtx.Lock()
|
||||||
nID := NewNodeID(directive.PeerKey)
|
nID := NewNodeID(directive.PeerKey)
|
||||||
delete(pendingOpens, nID)
|
delete(pendingOpens, nID)
|
||||||
|
|
||||||
|
// Mark this node as failed so we don't
|
||||||
|
// attempt it again.
|
||||||
|
failedNodes[nID] = struct{}{}
|
||||||
pendingMtx.Unlock()
|
pendingMtx.Unlock()
|
||||||
|
|
||||||
// Trigger the autopilot controller to
|
// Trigger the autopilot controller to
|
||||||
|
Loading…
Reference in New Issue
Block a user