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.
This commit is contained in:
carla 2021-01-19 10:57:12 +02:00
parent 97442da8f7
commit 7b24b586a0
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

View File

@ -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,