Add helper methods to AssignedCollators to avoid is_empty checks#43
Draft
tmpolaczyk wants to merge 8 commits intomasterfrom
Draft
Add helper methods to AssignedCollators to avoid is_empty checks#43tmpolaczyk wants to merge 8 commits intomasterfrom
tmpolaczyk wants to merge 8 commits intomasterfrom
Conversation
Contributor
Author
|
On hold because making the field private made too many tests fail to compile, but I can't think of any better alternatives |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AssignedCollatorsstruct has this field:It is a map of container chain para id to list of collators assigned to that chain. A common query is "does this chain have any assigned collators?". The naive solution is to do
container_chains.contains(para_id), but that's wrong because the chain could be in theBTreeMapbut with an empty collator list. The correct solution is something likecontainer_chains.get(para_id).unwrap_or(&vec![]).is_empty() == false, which is more complex and easy to forget.This PR tries to avoid that problem by making the
container_chainsfield private, and only allow reading through getters that automatically check the empty vector case and convert it intoNone. Example:And now callers can simply do
assigned_collators.get_container_chain(para_id).is_some()to check if a chain has any collators.Also added more helper methods that are needed because the field is private.