From 28a828a11ee8661c4bdf26eff4539f5c88b25037 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 13 Aug 2024 18:26:54 +0200 Subject: [PATCH] routing: unexport MissionControl mutex Only the MissionControl instance should use this variable and it should not be accessible to users of MissionControl. --- routing/missioncontrol.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 6b3c1ab64..299e288f6 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -121,7 +121,7 @@ type MissionControl struct { // mission control state is updated. onConfigUpdate fn.Option[func(cfg *MissionControlConfig)] - sync.Mutex + mu sync.Mutex // TODO(roasbeef): further counters, if vertex continually unavailable, // add to another generation @@ -295,8 +295,8 @@ func (m *MissionControl) init() error { // with. All fields are copied by value, so we do not need to worry about // mutation. func (m *MissionControl) GetConfig() *MissionControlConfig { - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() return &MissionControlConfig{ Estimator: m.estimator, @@ -317,8 +317,8 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { return err } - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() log.Infof("Active mission control cfg: %v, estimator: %v", cfg, cfg.Estimator) @@ -338,8 +338,8 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { // ResetHistory resets the history of MissionControl returning it to a state as // if no payment attempts have been made. func (m *MissionControl) ResetHistory() error { - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() if err := m.store.clear(); err != nil { return err @@ -357,8 +357,8 @@ func (m *MissionControl) ResetHistory() error { func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex, amt lnwire.MilliSatoshi, capacity btcutil.Amount) float64 { - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() now := m.now() results, _ := m.state.getLastPairResult(fromNode) @@ -376,8 +376,8 @@ func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex, // GetHistorySnapshot takes a snapshot from the current mission control state // and actual probability estimates. func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot { - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() log.Debugf("Requesting history snapshot from mission control") @@ -394,8 +394,8 @@ func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, return errors.New("cannot import nil history") } - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() log.Infof("Importing history snapshot with %v pairs to mission control", len(history.Pairs)) @@ -411,8 +411,8 @@ func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, func (m *MissionControl) GetPairHistorySnapshot( fromNode, toNode route.Vertex) TimedPairResult { - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() results, ok := m.state.getLastPairResult(fromNode) if !ok { @@ -478,8 +478,8 @@ func (m *MissionControl) processPaymentResult(result *paymentResult) ( // Store complete result in database. m.store.AddResult(result) - m.Lock() - defer m.Unlock() + m.mu.Lock() + defer m.mu.Unlock() // Apply result to update mission control state. reason := m.applyPaymentResult(result)