Open odeke-em opened 6 months ago
Agreed. I think you're proposing something like:
// RoundUpByMultipleOf rounds cursor up to the next multiple of v. If cursor is divisible
// by v, then it returns cursor.
func RoundUpByMultipleOf(cursor, v int) (int, error) {
if v == 0 {
return 0, fmt.Errorf("v cannot be 0")
}
if cursor%v == 0 {
return cursor, nil
}
return ((cursor / v) + 1) * v, nil
}
which is API breaking but IMO seems reasonable.
If we examine https://github.com/celestiaorg/go-square/blob/4e84d80f3e55ac3093005c8089186d68ee62541d/inclusion/blob_share_commitment_rules.go#L44-L47 we see that an outside modulus is being used. Let's bullet proof by firstly checking if the denominator is zero and about a runtime panic of divide by zero