Skip to content

Commit 5afb0de

Browse files
committed
routing: forget info for contradictions
If we encounter invalid mission control data, we fall back to no knowledge about the node pair.
1 parent 5ba9619 commit 5afb0de

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

routing/probability_bimodal.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,18 @@ func (p *BimodalEstimator) probabilityFormula(capacityMsat, successAmountMsat,
488488
return 0.0, nil
489489
}
490490

491+
// The next statement is a safety check against an illogical condition.
492+
// We discard the knowledge for the channel in that case since we have
493+
// inconsistent data.
494+
if failAmount <= successAmount {
495+
log.Warnf("Fail amount (%s) is smaller than or equal to the "+
496+
"success amount (%s) for capacity (%s)",
497+
failAmountMsat, successAmountMsat, capacityMsat)
498+
499+
successAmount = 0
500+
failAmount = capacity
501+
}
502+
491503
// Mission control may have some outdated values, we correct them here.
492504
// TODO(bitromortac): there may be better decisions to make in these
493505
// cases, e.g., resetting failAmount=cap and successAmount=0.
@@ -508,18 +520,6 @@ func (p *BimodalEstimator) probabilityFormula(capacityMsat, successAmountMsat,
508520
successAmount = capacity
509521
}
510522

511-
// The next statement is a safety check against an illogical condition,
512-
// otherwise the renormalization integral would become zero. This may
513-
// happen if a large channel gets closed and smaller ones remain, but
514-
// it should recover with the time decay.
515-
if failAmount <= successAmount {
516-
log.Tracef("fail amount (%v) is smaller than or equal the "+
517-
"success amount (%v) for capacity (%v)",
518-
failAmountMsat, successAmountMsat, capacityMsat)
519-
520-
return 0.0, nil
521-
}
522-
523523
// We cannot send more than the fail amount.
524524
if amount >= failAmount {
525525
return 0.0, nil

routing/probability_bimodal_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,25 @@ func TestSuccessProbability(t *testing.T) {
192192
amount: largeAmount,
193193
expectedProbability: 0.0,
194194
},
195-
// Same success and failure amounts (illogical).
195+
// Same success and failure amounts (illogical), which gets
196+
// reset to no knowledge.
196197
{
197198
name: "previous f/s, same",
198199
capacity: capacity,
199200
failAmount: largeAmount,
200201
successAmount: largeAmount,
201202
amount: largeAmount,
202-
expectedProbability: 0.0,
203+
expectedProbability: 0.5,
203204
},
204-
// Higher success than failure amount (illogical).
205+
// Higher success than failure amount (illogical), which gets
206+
// reset to no knowledge.
205207
{
206-
name: "previous f/s, higher success",
208+
name: "previous f/s, illogical",
207209
capacity: capacity,
208210
failAmount: smallAmount,
209211
successAmount: largeAmount,
210-
expectedProbability: 0.0,
212+
amount: largeAmount,
213+
expectedProbability: 0.5,
211214
},
212215
}
213216

0 commit comments

Comments
 (0)