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

Feat/two keepers #90

Merged
merged 11 commits into from
Sep 6, 2023
Merged

Feat/two keepers #90

merged 11 commits into from
Sep 6, 2023

Conversation

dvilelaf
Copy link
Collaborator

@dvilelaf dvilelaf commented Sep 5, 2023

Proposed changes

  • Updates twitter api call rounds so only half of the agents make the call

Fixes

n/a

Types of changes

What types of changes does your code introduce? (A breaking change is a fix or feature that would cause existing functionality and APIs to not work as expected.)
Put an x in the box that applies

  • Non-breaking fix (non-breaking change which fixes an issue)
  • Breaking fix (breaking change which fixes an issue)
  • Non-breaking feature (non-breaking change which adds functionality)
  • Breaking feature (breaking change which adds functionality)
  • Refactor (non-breaking change which changes implementation)
  • Messy (mixture of the above - requires explanation!)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the main branch (left side). Also you should start your branch off our main.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have locally run services that could be impacted and they do not present failures derived from my changes

Further comments

n/a

Comment on lines +177 to +207
needed_keepers = math.ceil(
self.synchronized_data.nb_participants / 2
) # half or 1

# Check if we need random selection
if len(relevant_set) <= needed_keepers:
keeper_addresses = list(relevant_set)
self.context.logger.info(f"Selected new keepers: {keeper_addresses}.")
return keeper_addresses

# Random seeding and shuffling of the set
random.seed(self.synchronized_data.keeper_randomness)
random.shuffle(relevant_set)

# If the keeper is not set yet, pick the first address
keeper_addresses = relevant_set[0:2]

# If the keepers have been already set, select the next ones.
if (
self.synchronized_data.are_keepers_set
and len(self.synchronized_data.participants) > 2
):
old_keeper_index = relevant_set.index(
self.synchronized_data.most_voted_keeper_addresses[0]
)
keeper_addresses = [
relevant_set[
(old_keeper_index + 2) % len(relevant_set)
], # skip the previous 2
relevant_set[(old_keeper_index + 3) % len(relevant_set)],
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the part I've modified

Comment on lines +192 to +207
keeper_addresses = relevant_set[0:2]

# If the keepers have been already set, select the next ones.
if (
self.synchronized_data.are_keepers_set
and len(self.synchronized_data.participants) > 2
):
old_keeper_index = relevant_set.index(
self.synchronized_data.most_voted_keeper_addresses[0]
)
keeper_addresses = [
relevant_set[
(old_keeper_index + 2) % len(relevant_set)
], # skip the previous 2
relevant_set[(old_keeper_index + 3) % len(relevant_set)],
]
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit odd to me, we're slicing the keepers from the set of relevant keepers and after that we are checking if the keepers are set and using the index of the existing keepers to select the next ones. The problem here is that we're shuffling the keepers which means the relevant_set is none deterministic and we cannot use indexes to select different keepers. I would suggest we loop through the relevant set and select keepers which are not in self.synchronized_data.most_voted_keeper_addresses

Copy link
Collaborator Author

@dvilelaf dvilelaf Sep 6, 2023

Choose a reason for hiding this comment

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

This follows the current implementation for single keeper selection, which is tested code, but I'd like to have @Adamantios opinion as well since he implemented the original code IIRC.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is deterministic across the agents because they are using the same seed when shuffling.
This was implemented in this manner to ensure that we consistently choose all the agents as keepers.

@Adamantios Adamantios merged commit ff877b7 into main Sep 6, 2023
19 checks passed
@Adamantios Adamantios deleted the feat/two-keepers branch September 6, 2023 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants