fix: curveThreshold function to handle zero length divisor case (#11953)
This commit is contained in:
parent
338431fe2a
commit
104826b0d5
@ -67,6 +67,11 @@ export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN)
|
||||
if (curve.isLinearDecreasing) {
|
||||
const { ceil, floor, length } = curve.asLinearDecreasing;
|
||||
|
||||
// if divisor is zero, we return the max
|
||||
if (length.isZero()) {
|
||||
return BN_BILLION;
|
||||
}
|
||||
|
||||
// *ceil - (x.min(*length).saturating_div(*length, Down) * (*ceil - *floor))
|
||||
// NOTE: We first multiply, then divide (since we work with fractions)
|
||||
return ceil.sub(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user