routing: remove embedded struct from timedPairResult
This prepares for decoupling the result interpretation of a single payment attempt from the information stored in mission control memory on the history of a node pair. A planned follow-up where we store both the last success and last failure requires this decoupling.
This commit is contained in:
parent
8ed7583448
commit
912a8201f9
@ -125,7 +125,24 @@ type timedPairResult struct {
|
|||||||
// timestamp is the time when this result was obtained.
|
// timestamp is the time when this result was obtained.
|
||||||
timestamp time.Time
|
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
|
// 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 {
|
for connection := range nodePairs {
|
||||||
nodePairs[connection] = timedPairResult{
|
nodePairs[connection] = newTimedPairResult(
|
||||||
timestamp: timestamp,
|
timestamp, failPairResult(0),
|
||||||
pairResult: failPairResult(0),
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,10 +484,13 @@ func (m *MissionControl) applyPaymentResult(
|
|||||||
pair, pairResult.minPenalizeAmt)
|
pair, pairResult.minPenalizeAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.setLastPairResult(pair.From, pair.To, timedPairResult{
|
m.setLastPairResult(
|
||||||
timestamp: result.timeReply,
|
pair.From, pair.To,
|
||||||
pairResult: pairResult,
|
newTimedPairResult(
|
||||||
})
|
result.timeReply,
|
||||||
|
pairResult,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return i.finalFailureReason
|
return i.finalFailureReason
|
||||||
|
@ -84,10 +84,10 @@ func TestProbabilityEstimatorOneSuccess(t *testing.T) {
|
|||||||
ctx := newEstimatorTestContext(t)
|
ctx := newEstimatorTestContext(t)
|
||||||
|
|
||||||
ctx.results = map[int]timedPairResult{
|
ctx.results = map[int]timedPairResult{
|
||||||
node1: {
|
node1: newTimedPairResult(
|
||||||
timestamp: testTime.Add(-time.Hour),
|
testTime.Add(-time.Hour),
|
||||||
pairResult: successPairResult(),
|
successPairResult(),
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because of the previous success, this channel keep reporting a high
|
// Because of the previous success, this channel keep reporting a high
|
||||||
@ -108,10 +108,10 @@ func TestProbabilityEstimatorOneFailure(t *testing.T) {
|
|||||||
ctx := newEstimatorTestContext(t)
|
ctx := newEstimatorTestContext(t)
|
||||||
|
|
||||||
ctx.results = map[int]timedPairResult{
|
ctx.results = map[int]timedPairResult{
|
||||||
node1: {
|
node1: newTimedPairResult(
|
||||||
timestamp: testTime.Add(-time.Hour),
|
testTime.Add(-time.Hour),
|
||||||
pairResult: failPairResult(0),
|
failPairResult(0),
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// For an untried node, we expected the node probability. The weight for
|
// 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 := newEstimatorTestContext(t)
|
||||||
|
|
||||||
ctx.results = map[int]timedPairResult{
|
ctx.results = map[int]timedPairResult{
|
||||||
node1: {
|
node1: newTimedPairResult(
|
||||||
timestamp: testTime.Add(-time.Hour),
|
testTime.Add(-time.Hour),
|
||||||
pairResult: successPairResult(),
|
successPairResult(),
|
||||||
},
|
),
|
||||||
node2: {
|
node2: newTimedPairResult(
|
||||||
timestamp: testTime.Add(-2 * time.Hour),
|
testTime.Add(-2*time.Hour),
|
||||||
pairResult: failPairResult(0),
|
failPairResult(0),
|
||||||
},
|
),
|
||||||
node3: {
|
node3: newTimedPairResult(
|
||||||
timestamp: testTime.Add(-3 * time.Hour),
|
testTime.Add(-3*time.Hour),
|
||||||
pairResult: failPairResult(0),
|
failPairResult(0),
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We expect the probability for a previously successful channel to
|
// We expect the probability for a previously successful channel to
|
||||||
|
Loading…
Reference in New Issue
Block a user