mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
routing: add test for small scale
This test demonstrates that the current bimodal model leads to numerical inaccuracies in a certain regime of successes and failures.
This commit is contained in:
parent
c8b989a75c
commit
3984ed06a7
1 changed files with 33 additions and 0 deletions
|
@ -240,6 +240,39 @@ func TestSuccessProbability(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// TestSmallScale tests that the probability formula works with small scale
|
||||
// values.
|
||||
func TestSmallScale(t *testing.T) {
|
||||
var (
|
||||
// We use the smallest possible scale value together with a
|
||||
// large capacity. This is an extreme form of a bimodal
|
||||
// distribution.
|
||||
scale lnwire.MilliSatoshi = 1
|
||||
capacity lnwire.MilliSatoshi = 7e+09
|
||||
|
||||
// Success and failure amounts are chosen such that the expected
|
||||
// balance must be somewhere in the middle of the channel, a
|
||||
// value not expected when dealing with a bimodal distribution.
|
||||
// In this case, the bimodal model fails to give good forecasts
|
||||
// due to the numerics of the exponential functions, which get
|
||||
// evaluated to exact zero floats.
|
||||
successAmount lnwire.MilliSatoshi = 1.0e+09
|
||||
failAmount lnwire.MilliSatoshi = 4.0e+09
|
||||
)
|
||||
|
||||
estimator := BimodalEstimator{
|
||||
BimodalConfig: BimodalConfig{BimodalScaleMsat: scale},
|
||||
}
|
||||
|
||||
// An amount that's close to the success amount should have a very high
|
||||
// probability.
|
||||
amtCloseSuccess := successAmount + 1
|
||||
_, err := estimator.probabilityFormula(
|
||||
capacity, successAmount, failAmount, amtCloseSuccess,
|
||||
)
|
||||
require.ErrorContains(t, err, "normalization factor is zero")
|
||||
}
|
||||
|
||||
// TestIntegral tests certain limits of the probability distribution integral.
|
||||
func TestIntegral(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
Loading…
Add table
Reference in a new issue