-
Notifications
You must be signed in to change notification settings - Fork 1.2k
approval-voting: Make importing of duplicate assignment idempotent #6971
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
Changes from 3 commits
24f8fdd
443309f
4e2788b
a49f7e0
fd9c784
1a18e57
8d610ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,7 +172,7 @@ impl ApprovalEntry { | |
| }); | ||
|
|
||
| our.map(|a| { | ||
| self.import_assignment(a.tranche(), a.validator_index(), tick_now); | ||
| self.import_assignment(a.tranche(), a.validator_index(), tick_now, false); | ||
|
|
||
| (a.cert().clone(), a.validator_index(), a.tranche()) | ||
| }) | ||
|
|
@@ -197,6 +197,7 @@ impl ApprovalEntry { | |
| tranche: DelayTranche, | ||
| validator_index: ValidatorIndex, | ||
| tick_now: Tick, | ||
| is_duplicate: bool, | ||
| ) { | ||
| // linear search probably faster than binary. not many tranches typically. | ||
| let idx = match self.tranches.iter().position(|t| t.tranche >= tranche) { | ||
|
|
@@ -213,8 +214,17 @@ impl ApprovalEntry { | |
| self.tranches.len() - 1 | ||
| }, | ||
| }; | ||
|
|
||
| self.tranches[idx].assignments.push((validator_index, tick_now)); | ||
| // We already know already if we seen already an assignment from this validator | ||
| // and since this function is on the hot path we can avoid going through tranches | ||
| // if the assignment is not a duplicate. | ||
| if !is_duplicate || | ||
|
||
| !self.tranches[idx] | ||
alexggh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .assignments | ||
| .iter() | ||
| .any(|(validator, _)| validator == &validator_index) | ||
| { | ||
| self.tranches[idx].assignments.push((validator_index, tick_now)); | ||
| } | ||
| self.assigned_validators.set(validator_index.0 as _, true); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.