Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

jacogr
Copy link
Member

@jacogr jacogr commented Feb 4, 2022

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 of useMemo everywhere.

@h4x3rotab
Copy link
Contributor

A quick fix in #9419. Instead of using ceil, it should be floor() + 1.

@h4x3rotab
Copy link
Contributor

If you want to find a chain with even council seats, please try Phala (it has 8 members):

wss://phala.api.onfinality.io/public-ws

Comment on lines +58 to +73
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
)
)
);
}
Copy link
Contributor

@h4x3rotab h4x3rotab May 9, 2023

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)
  }
}

@ap211unitech
Copy link
Contributor

Closing this PR as it appears to be outdated. If the problem persists, a new PR can be opened with updated details.

@ap211unitech ap211unitech deleted the jg-thresholds-even branch February 14, 2025 07:16
@polkadot-js-bot
Copy link

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.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Feb 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid Threshold for 2 members Council for external proposal
4 participants