From 7b24b586a043fb75bc1696c3f0a38345f0cf1cfe Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 19 Jan 2021 10:57:12 +0200 Subject: [PATCH] routing: move locking for ReportPaymentSuccess and ReportPaymentFailure All of the other mission control exported functions acquire their locks immediately, and do not lock in the subsequent unexported functions. This commit moves the lock up for the report payment functions so that mission control's config values are covered by this lock, in preparation for allowing config to be updated at runtime. Moving this lock means that we will hold the lock for the additional time it takes to store a single result, AddResult, to the store. --- routing/missioncontrol.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 5d91e69c..2c1ca116 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -221,6 +221,9 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex, func (m *MissionControl) init() error { log.Debugf("Mission control state reconstruction started") + m.Lock() + defer m.Unlock() + start := time.Now() results, err := m.store.fetchAll() @@ -314,6 +317,9 @@ func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, failureSourceIdx *int, failure lnwire.FailureMessage) ( *channeldb.FailureReason, error) { + m.Lock() + defer m.Unlock() + timestamp := m.now() result := &paymentResult{ @@ -334,6 +340,9 @@ func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, func (m *MissionControl) ReportPaymentSuccess(paymentID uint64, rt *route.Route) error { + m.Lock() + defer m.Unlock() + timestamp := m.now() result := &paymentResult{ @@ -376,10 +385,6 @@ func (m *MissionControl) applyPaymentResult( result.failure, ) - // Update mission control state using the interpretation. - m.Lock() - defer m.Unlock() - if i.policyFailure != nil { if m.state.requestSecondChance( result.timeReply,