Skip to content

Commit 07f863a

Browse files
committed
routing: refine amount scaling
Mission control may have outdated success/failure amounts for node pairs that have channels with differing capacities. In that case we assume to still find the liquidity as before and rescale the amounts to the according range.
1 parent 5afb0de commit 07f863a

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

routing/probability_bimodal.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -500,24 +500,36 @@ func (p *BimodalEstimator) probabilityFormula(capacityMsat, successAmountMsat,
500500
failAmount = capacity
501501
}
502502

503-
// Mission control may have some outdated values, we correct them here.
504-
// TODO(bitromortac): there may be better decisions to make in these
505-
// cases, e.g., resetting failAmount=cap and successAmount=0.
506-
507-
// failAmount should be capacity at max.
508-
if failAmount > capacity {
509-
log.Debugf("Correcting failAmount %v to capacity %v",
510-
failAmount, capacity)
511-
503+
// Mission control may have some outdated values with regard to the
504+
// current channel capacity between a node pair. This can happen in case
505+
// a large parallel channel was closed or if a channel was downscaled
506+
// and can lead to success and/or failure amounts to be out of the range
507+
// [0, capacity]. We assume that the liquidity situation of the channel
508+
// is similar as before due to flow bias.
509+
510+
// In case we have a large success we need to correct it to be in the
511+
// valid range. We set the success amount close to the capacity, because
512+
// we assume to still be able to send. Any possible failure (that must
513+
// in this case be larger than the capacity) is corrected as well.
514+
if successAmount >= capacity {
515+
log.Debugf("Correcting success amount %s and failure amount "+
516+
"%s to capacity %s", successAmountMsat,
517+
failAmount, capacityMsat)
518+
519+
// We choose the success amount to be one less than the
520+
// capacity, to both fit success and failure amounts into the
521+
// capacity range in a consistent manner.
522+
successAmount = capacity - 1
512523
failAmount = capacity
513524
}
514525

515-
// successAmount should be capacity at max.
516-
if successAmount > capacity {
517-
log.Debugf("Correcting successAmount %v to capacity %v",
518-
successAmount, capacity)
526+
// Having no or only a small success, but a large failure only needs
527+
// adjustment of the failure amount.
528+
if failAmount > capacity {
529+
log.Debugf("Correcting failure amount %s to capacity %s",
530+
failAmountMsat, capacityMsat)
519531

520-
successAmount = capacity
532+
failAmount = capacity
521533
}
522534

523535
// We cannot send more than the fail amount.

routing/probability_bimodal_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ func TestSuccessProbability(t *testing.T) {
212212
amount: largeAmount,
213213
expectedProbability: 0.5,
214214
},
215+
// Larger success and larger failure than the old capacity are
216+
// rescaled to still give a very high success rate.
217+
{
218+
name: "smaller cap, large success/fail",
219+
capacity: capacity,
220+
failAmount: 2*capacity + 1,
221+
successAmount: 2 * capacity,
222+
amount: largeAmount,
223+
expectedProbability: 1.0,
224+
},
225+
// A lower success amount is not rescaled.
226+
{
227+
name: "smaller cap, large fail",
228+
capacity: capacity,
229+
successAmount: smallAmount / 2,
230+
failAmount: 2 * capacity,
231+
amount: smallAmount,
232+
// See "previous success, larger amount".
233+
expectedProbability: 0.851,
234+
},
215235
}
216236

217237
estimator := BimodalEstimator{

0 commit comments

Comments
 (0)