Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Additional zero bid logic for Society pallet #4604

Merged
merged 7 commits into from
Jan 13, 2020

Conversation

shawntabrizi
Copy link
Member

@shawntabrizi shawntabrizi commented Jan 11, 2020

This introduces some additional logic around users trying to join society with zero value bids.

  1. We will only select one zero value bid to be a candidate per rotation period. This zero bid will be the first of the zero bids that applied for entry into society. The rest of the selected candidates will comprise of users whose bids have some non-zero value.
  2. If the accepted candidate pool contains a user with bid value of zero, that user automatically becomes the Head no matter the number of approvals they recieved. Otherwise, a random candidate is selected as head, weighted by approvals (as it was before).

A new test verifies that these two points are handled, correctly, and all other existing tests/logic continue to work unaffected.

@shawntabrizi shawntabrizi added the A0-please_review Pull request needs code review. label Jan 11, 2020
// Find the user who falls on that point
let primary = accepted.iter().find(|e| e.1 > primary_point)
// Find the zero bid or the user who falls on that point
let primary = accepted.iter().find(|e| e.2.is_zero() || e.1 > primary_point)
Copy link
Member

@gavofyork gavofyork Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the zero bid always be the first in the list? if not then the primary_point bidder will be chosen if it comes before the zero bidder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We must assume bids is sorted by value. If so, then candidates will be sorted by value. If so, then accepted will be sorted by value.

If you would like me to write this assumption down near this code I can do that.

@gavofyork gavofyork added A5-grumble and removed A0-please_review Pull request needs code review. labels Jan 13, 2020
Note that this extra logic currently does not do anything per the implementation of `binary_search` in Rust.
@shawntabrizi
Copy link
Member Author

I will work on another implementation of this logic introducing a new storage item ZeroBids, but if you like this, then feel free to merge it in and I can scrap the other work.

@shawntabrizi shawntabrizi added A0-please_review Pull request needs code review. and removed A5-grumble labels Jan 13, 2020
@gavofyork
Copy link
Member

i think it would still be worth cleaning it up if you've already started, but can merge this as is since it's strictly better.

@gavofyork gavofyork merged commit 70f1d8d into paritytech:master Jan 13, 2020
@shawntabrizi shawntabrizi deleted the shawntabrizi-bump-society branch January 13, 2020 18:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants