diff --git a/routing/probability_bimodal.go b/routing/probability_bimodal.go index 5f6ff587b..a5a8ba342 100644 --- a/routing/probability_bimodal.go +++ b/routing/probability_bimodal.go @@ -488,6 +488,18 @@ func (p *BimodalEstimator) probabilityFormula(capacityMsat, successAmountMsat, return 0.0, nil } + // The next statement is a safety check against an illogical condition. + // We discard the knowledge for the channel in that case since we have + // inconsistent data. + if failAmount <= successAmount { + log.Warnf("Fail amount (%s) is smaller than or equal to the "+ + "success amount (%s) for capacity (%s)", + failAmountMsat, successAmountMsat, capacityMsat) + + successAmount = 0 + failAmount = capacity + } + // Mission control may have some outdated values, we correct them here. // TODO(bitromortac): there may be better decisions to make in these // cases, e.g., resetting failAmount=cap and successAmount=0. @@ -508,18 +520,6 @@ func (p *BimodalEstimator) probabilityFormula(capacityMsat, successAmountMsat, successAmount = capacity } - // The next statement is a safety check against an illogical condition, - // otherwise the renormalization integral would become zero. This may - // happen if a large channel gets closed and smaller ones remain, but - // it should recover with the time decay. - if failAmount <= successAmount { - log.Tracef("fail amount (%v) is smaller than or equal the "+ - "success amount (%v) for capacity (%v)", - failAmountMsat, successAmountMsat, capacityMsat) - - return 0.0, nil - } - // We cannot send more than the fail amount. if amount >= failAmount { return 0.0, nil diff --git a/routing/probability_bimodal_test.go b/routing/probability_bimodal_test.go index 0fab80669..d31332739 100644 --- a/routing/probability_bimodal_test.go +++ b/routing/probability_bimodal_test.go @@ -192,22 +192,25 @@ func TestSuccessProbability(t *testing.T) { amount: largeAmount, expectedProbability: 0.0, }, - // Same success and failure amounts (illogical). + // Same success and failure amounts (illogical), which gets + // reset to no knowledge. { name: "previous f/s, same", capacity: capacity, failAmount: largeAmount, successAmount: largeAmount, amount: largeAmount, - expectedProbability: 0.0, + expectedProbability: 0.5, }, - // Higher success than failure amount (illogical). + // Higher success than failure amount (illogical), which gets + // reset to no knowledge. { - name: "previous f/s, higher success", + name: "previous f/s, illogical", capacity: capacity, failAmount: smallAmount, successAmount: largeAmount, - expectedProbability: 0.0, + amount: largeAmount, + expectedProbability: 0.5, }, }