-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure evenly divisible thresholds are adjusted #6924
Conversation
A quick fix in #9419. Instead of using |
If you want to find a chain with even council seats, please try Phala (it has 8 members):
|
export function calcThreshold (members: unknown[], threshold: number): BN { | ||
const frac = members.length * threshold; | ||
const ceil = Math.ceil(frac); | ||
|
||
return new BN( | ||
Math.min( | ||
members.length, | ||
ceil + ( | ||
// for evenly divisible, adjust upwards | ||
Math.floor(frac) === ceil | ||
? 1 | ||
: 0 | ||
) | ||
) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is identical to:
function calcThreshold (members: unknown[], threshold: number): BN {
return new BN(
Math.min(
members.length,
Math.floor(members.length * threshold) + 1
)
);
}
Tested with:
for (let len = 0; len < 10; len++) {
for (let threshold = 0; threshold <= 1; threshold += 0.1) {
// assert left(members, threshold) == right(members, threshold)
}
}
Closing this PR as it appears to be outdated. If the problem persists, a new PR can be opened with updated details. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Closes #6828
Closes #4588
The correct solution is probably to carry the
>
and>=
but it certainly makes things a lot more complex. In this implementation we actually DRY things a lot. So could be re-visited possibly if really needed. (The hook in the linked PR could be interesting, instead ofuseMemo
everywhere.