autopilot: ensure all access to pendingOpens is thread-safe

In this commit, we ensure that we grab the mutex for the pending open
channel state when we attempt to merge the pending state with the
committed state.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 22:20:54 -07:00
parent c87678e695
commit 804edb8f02
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -67,6 +67,11 @@ func (c channelState) ConnectedNodes() map[NodeID]struct{} {
for _, channels := range c {
nodes[channels.Node] = struct{}{}
}
// TODO(roasbeef): add outgoing, nodes, allow incoming and outgoing to
// per node
// * only add node is chan as funding amt set
return nodes
}
@ -316,11 +321,15 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
}
}
log.Debugf("Pending channels: %v", spew.Sdump(pendingOpens))
// With all the updates applied, we'll obtain a set of
// the current active channels (confirmed channels),
// and also factor in our set of unconfirmed channels.
confirmedChans := a.chanState
pendingMtx.Lock()
totalChans := mergeChanState(pendingOpens, confirmedChans)
pendingMtx.Unlock()
// Now that we've updated our internal state, we'll
// consult our channel attachment heuristic to
@ -413,5 +422,4 @@ func (a *Agent) controller(startingBalance btcutil.Amount) {
return
}
}
}