routing: create prob estimation func taking external node prob

This commit is contained in:
Joost Jager 2019-11-07 10:38:36 +01:00
parent 0fbcc3b2e9
commit 5a80c3459f
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -116,13 +116,27 @@ func (p *probabilityEstimator) getPairProbability(
now time.Time, results NodeResults, now time.Time, results NodeResults,
toNode route.Vertex, amt lnwire.MilliSatoshi) float64 { toNode route.Vertex, amt lnwire.MilliSatoshi) float64 {
nodeProbability := p.getNodeProbability(now, results, amt)
return p.calculateProbability(
now, results, nodeProbability, toNode, amt,
)
}
// calculateProbability estimates the probability of successfully traversing to
// toNode based on historical payment outcomes and a fall-back node probability.
func (p *probabilityEstimator) calculateProbability(
now time.Time, results NodeResults,
nodeProbability float64, toNode route.Vertex,
amt lnwire.MilliSatoshi) float64 {
// Retrieve the last pair outcome. // Retrieve the last pair outcome.
lastPairResult, ok := results[toNode] lastPairResult, ok := results[toNode]
// If there is no history for this pair, return the node probability // If there is no history for this pair, return the node probability
// that is a probability estimate for untried channel. // that is a probability estimate for untried channel.
if !ok { if !ok {
return p.getNodeProbability(now, results, amt) return nodeProbability
} }
// For successes, we have a fixed (high) probability. Those pairs // For successes, we have a fixed (high) probability. Those pairs
@ -131,8 +145,6 @@ func (p *probabilityEstimator) getPairProbability(
return p.prevSuccessProbability return p.prevSuccessProbability
} }
nodeProbability := p.getNodeProbability(now, results, amt)
// Take into account a minimum penalize amount. For balance errors, a // Take into account a minimum penalize amount. For balance errors, a
// failure may be reported with such a minimum to prevent too aggressive // failure may be reported with such a minimum to prevent too aggressive
// penalization. If the current amount is smaller than the amount that // penalization. If the current amount is smaller than the amount that