From 804edb8f02477583d41667f31d2fd6d7ff18dfd2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 Aug 2017 22:20:54 -0700 Subject: [PATCH] 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. --- autopilot/agent.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autopilot/agent.go b/autopilot/agent.go index 045ca998..f302f8d4 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -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 } } - }