From 5a80c3459ff4416fb1ad044671b8ad7d8b11d0f2 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 7 Nov 2019 10:38:36 +0100 Subject: [PATCH] routing: create prob estimation func taking external node prob --- routing/probability_estimator.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/routing/probability_estimator.go b/routing/probability_estimator.go index 991a7756..9d18067e 100644 --- a/routing/probability_estimator.go +++ b/routing/probability_estimator.go @@ -116,13 +116,27 @@ func (p *probabilityEstimator) getPairProbability( now time.Time, results NodeResults, 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. lastPairResult, ok := results[toNode] // If there is no history for this pair, return the node probability // that is a probability estimate for untried channel. if !ok { - return p.getNodeProbability(now, results, amt) + return nodeProbability } // For successes, we have a fixed (high) probability. Those pairs @@ -131,8 +145,6 @@ func (p *probabilityEstimator) getPairProbability( return p.prevSuccessProbability } - nodeProbability := p.getNodeProbability(now, results, amt) - // Take into account a minimum penalize amount. For balance errors, a // failure may be reported with such a minimum to prevent too aggressive // penalization. If the current amount is smaller than the amount that