htlcswitch/link: correct bias in fee update backoff
This commit corrects the distribution used to schedule a link's randomized backoff for fee updates. Currently, our algorithm biases the lowest value in the range, with probability equal to lower/upper, or the ratio of the lower bound to the upper. This distribution is skewed more heavily as lower approaches upper. The solution is to sample a random value in the range upper-lower, then add this to our lower bound. The effect is a uniformly distributed timeout in [lower, upper).
This commit is contained in:
parent
9205720bea
commit
5fa8124aa1
@ -995,12 +995,7 @@ out:
|
|||||||
func (l *channelLink) randomFeeUpdateTimeout() time.Duration {
|
func (l *channelLink) randomFeeUpdateTimeout() time.Duration {
|
||||||
lower := int64(l.cfg.MinFeeUpdateTimeout)
|
lower := int64(l.cfg.MinFeeUpdateTimeout)
|
||||||
upper := int64(l.cfg.MaxFeeUpdateTimeout)
|
upper := int64(l.cfg.MaxFeeUpdateTimeout)
|
||||||
rand := prand.Int63n(upper)
|
return time.Duration(prand.Int63n(upper-lower) + lower)
|
||||||
if rand < lower {
|
|
||||||
rand = lower
|
|
||||||
}
|
|
||||||
|
|
||||||
return time.Duration(rand)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDownStreamPkt processes an HTLC packet sent from the downstream HTLC
|
// handleDownStreamPkt processes an HTLC packet sent from the downstream HTLC
|
||||||
|
Loading…
Reference in New Issue
Block a user