autopilot: add OnChannelPendingOpen state update

This commit is contained in:
Wilmer Paulino committed 2018-08-16 20:22:40 -07:00
1 parent 956acdfa14
commit aa7c2e6d47
2 files changed
+124 -1

No files matched your search

+30 -1
View File
@@ -186,13 +186,18 @@ type balanceUpdate struct {
balanceDelta btcutil.Amount
}
// chanOpenUpdate is a type of external state update the indicates a new
// 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.
type chanOpenUpdate struct {
newChan Channel
}
// chanPendingOpenUpdate is a type of external state update that indicates a new
// channel has been opened, either by the agent itself or an external subsystem,
// but is still pending.
type chanPendingOpenUpdate struct{}
// 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{}
@@ -231,6 +236,18 @@ func (a *Agent) OnChannelOpen(c Channel) {
}()
}
// OnChannelPendingOpen is a callback that should be executed each time a new
// channel is opened, either by the agent or an external subsystems, but is
// still pending.
func (a *Agent) OnChannelPendingOpen() {
go func() {
select {
case a.stateUpdates <- &chanPendingOpenUpdate{}:
case <-a.quit:
}
}()
}
// 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.
@@ -382,6 +399,12 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
updateBalance()
// A new channel has been opened by the agent or an
// external subsystem, but is still pending
// confirmation.
case *chanPendingOpenUpdate:
updateBalance()
// A channel has been closed, this may free up an
// available slot, triggering a new channel update.
case *chanCloseUpdate:
@@ -598,6 +621,12 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
err)
}
}
// Since the channel open was successful
// and is currently pending, we'll
// trigger the autopilot agent to query
// for more peers.
a.OnChannelPendingOpen()
}(chanCandidate)
}
pendingMtx.Unlock()