diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index de93df0d..d4868ddd 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -125,7 +125,24 @@ type timedPairResult struct { // timestamp is the time when this result was obtained. timestamp time.Time - pairResult + // minPenalizeAmt is the minimum amount for which a penalty should be + // applied based on this result. Only applies to fail results. + minPenalizeAmt lnwire.MilliSatoshi + + // success indicates whether the payment attempt was successful through + // this pair. + success bool +} + +// newTimedPairResult wraps a pair result with a timestamp. +func newTimedPairResult(timestamp time.Time, + result pairResult) timedPairResult { + + return timedPairResult{ + timestamp: timestamp, + minPenalizeAmt: result.minPenalizeAmt, + success: result.success, + } } // MissionControlSnapshot contains a snapshot of the current state of mission @@ -278,10 +295,9 @@ func (m *MissionControl) setAllFail(fromNode route.Vertex, } for connection := range nodePairs { - nodePairs[connection] = timedPairResult{ - timestamp: timestamp, - pairResult: failPairResult(0), - } + nodePairs[connection] = newTimedPairResult( + timestamp, failPairResult(0), + ) } } @@ -468,10 +484,13 @@ func (m *MissionControl) applyPaymentResult( pair, pairResult.minPenalizeAmt) } - m.setLastPairResult(pair.From, pair.To, timedPairResult{ - timestamp: result.timeReply, - pairResult: pairResult, - }) + m.setLastPairResult( + pair.From, pair.To, + newTimedPairResult( + result.timeReply, + pairResult, + ), + ) } return i.finalFailureReason diff --git a/routing/probability_estimator_test.go b/routing/probability_estimator_test.go index c9604241..e178a0c3 100644 --- a/routing/probability_estimator_test.go +++ b/routing/probability_estimator_test.go @@ -84,10 +84,10 @@ func TestProbabilityEstimatorOneSuccess(t *testing.T) { ctx := newEstimatorTestContext(t) ctx.results = map[int]timedPairResult{ - node1: { - timestamp: testTime.Add(-time.Hour), - pairResult: successPairResult(), - }, + node1: newTimedPairResult( + testTime.Add(-time.Hour), + successPairResult(), + ), } // Because of the previous success, this channel keep reporting a high @@ -108,10 +108,10 @@ func TestProbabilityEstimatorOneFailure(t *testing.T) { ctx := newEstimatorTestContext(t) ctx.results = map[int]timedPairResult{ - node1: { - timestamp: testTime.Add(-time.Hour), - pairResult: failPairResult(0), - }, + node1: newTimedPairResult( + testTime.Add(-time.Hour), + failPairResult(0), + ), } // For an untried node, we expected the node probability. The weight for @@ -131,18 +131,18 @@ func TestProbabilityEstimatorMix(t *testing.T) { ctx := newEstimatorTestContext(t) ctx.results = map[int]timedPairResult{ - node1: { - timestamp: testTime.Add(-time.Hour), - pairResult: successPairResult(), - }, - node2: { - timestamp: testTime.Add(-2 * time.Hour), - pairResult: failPairResult(0), - }, - node3: { - timestamp: testTime.Add(-3 * time.Hour), - pairResult: failPairResult(0), - }, + node1: newTimedPairResult( + testTime.Add(-time.Hour), + successPairResult(), + ), + node2: newTimedPairResult( + testTime.Add(-2*time.Hour), + failPairResult(0), + ), + node3: newTimedPairResult( + testTime.Add(-3*time.Hour), + failPairResult(0), + ), } // We expect the probability for a previously successful channel to