autopilot: Make autopilot aware of channel open failures
This commit is contained in:
1 parent
42014f5b7b
commit
a43d7d3532
2 files changed
+138
-1
No files matched your search
+23
-1
@@ -177,13 +177,17 @@ type chanOpenUpdate struct {
|
||||
newChan Channel
|
||||
}
|
||||
|
||||
// chanOpenFailureUpdate is a type of external state update that indicates
|
||||
// a previous channel open failed, and that it might be possible to try again.
|
||||
type chanOpenFailureUpdate struct{}
|
||||
|
||||
// chanCloseUpdate is a type of external state update that indicates that the
|
||||
// backing Lightning Node has closed a previously open channel.
|
||||
type chanCloseUpdate struct {
|
||||
closedChans []lnwire.ShortChannelID
|
||||
}
|
||||
|
||||
// OnBalanceChange is a callback that should be executed each the balance of
|
||||
// OnBalanceChange is a callback that should be executed each time the balance of
|
||||
// the backing wallet changes.
|
||||
func (a *Agent) OnBalanceChange(delta btcutil.Amount) {
|
||||
go func() {
|
||||
@@ -203,6 +207,15 @@ func (a *Agent) OnChannelOpen(c Channel) {
|
||||
}()
|
||||
}
|
||||
|
||||
// OnChannelOpenFailure is a callback that should be executed when the
|
||||
// autopilot has attempted to open a channel, but failed. In this case we can
|
||||
// retry channel creation with a different node.
|
||||
func (a *Agent) OnChannelOpenFailure() {
|
||||
go func() {
|
||||
a.stateUpdates <- &chanOpenFailureUpdate{}
|
||||
}()
|
||||
}
|
||||
|
||||
// OnChannelClose is a callback that should be executed each time a prior
|
||||
// channel has been closed for any reason. This includes regular
|
||||
// closes, force closes, and channel breaches.
|
||||
@@ -294,6 +307,11 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
|
||||
|
||||
a.totalBalance += update.balanceDelta
|
||||
|
||||
// The channel we tried to open previously failed for
|
||||
// whatever reason.
|
||||
case *chanOpenFailureUpdate:
|
||||
log.Debug("Retrying after previous channel open failure.")
|
||||
|
||||
// A new channel has been opened successfully. This was
|
||||
// either opened by the Agent, or an external system
|
||||
// that is able to drive the Lightning Node.
|
||||
@@ -412,6 +430,10 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
|
||||
delete(pendingOpens, nID)
|
||||
pendingMtx.Unlock()
|
||||
|
||||
// Trigger the autopilot controller to
|
||||
// re-evaluate everything and possibly
|
||||
// retry with a different node.
|
||||
a.OnChannelOpenFailure()
|
||||
}
|
||||
|
||||
}(chanCandidate)
|
||||
|
||||
Reference in new issue
Block a user