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

Extract and test count_no_shows method for approval voting #3264

Merged
3 commits merged into from
Jun 17, 2021

Conversation

Lldenaurois
Copy link
Contributor

This commit extracts no_show computation into a pure function so that it can be
extensively unit tested.

This commit extracts no_show computation into a pure function so that it can be extensively unit tested. So far the tests behave mostly as I would expect, though I plan on further expanding them to better test the interactions of the Tick parameters.

The main thing that currently sticks out is the next_no_show calculation, which I suspect is adding an extra clock_drift factor. For example, in the current test harness, a validator assigned at tick 20 is counted as a no_show when drifted_tick_now is also 20. However, a validator assigned at tick 21 (which would be counted as a no_show at a drifted_tick_now of 21) is reported as a next_no_show of 31 (21 + clock_drift). If this is the correct behavior I can continue to add unit tests on this interaction, but wanted to clarify before proceeding.

@Lldenaurois Lldenaurois added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jun 16, 2021
},
];

for test in tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: I'd prefer each test to get its own #[test] function which uses a helper function as the body of this loop

Copy link
Contributor Author

@Lldenaurois Lldenaurois Jun 16, 2021

Choose a reason for hiding this comment

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

Good to know, will take note of that going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rphmeier force pushed the change to create each test case individually. Should be good to go.

@rphmeier
Copy link
Contributor

rphmeier commented Jun 16, 2021

For example, in the current test harness, a validator assigned at tick 20 is counted as a no_show when drifted_tick_now is also 20. However, a validator assigned at tick 21 (which would be counted as a no_show at a drifted_tick_now of 21) is reported as a next_no_show of 31 (21 + clock_drift). If this is the correct behavior I can continue to add unit tests on this interaction, but wanted to clarify before proceeding.

Yes, I think this is correct. The reasoning is that the next_no_show is measured in ticks (time), not tranches, so the scheduler can schedule a wake-up at the next no-show. With clock_drift = 10, drifted_tick_now = 20, the absolute tick is 30 and so a wakeup will be scheduled 1 tick from now at tick 31 to check for the no-show.

I do think that a comment explaining logic in the API would be useful.

cc @burdges to confirm

This commit extracts no_show computation into a pure function so that it can be
extensively unit tested.
@burdges
Copy link
Contributor

burdges commented Jun 16, 2021

Yes, we want being no-show to indicate that you'll likely not show within any sane time period, like your power when off or you got DoS. If your assignment was late then your approval vote will likely be late too, so we measure no shows in wall time since we learned about your assignment.

clock_drift: 10,
no_show_duration: 10,
drifted_tick_now: 20,
exp_no_shows: 1, // TODO(ladi): should this be counted or ignored?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should validator indexes past the length of the approvals vector be ignored or handled?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be ignored; Garbage-in-Garbage-out

@rphmeier
Copy link
Contributor

I do think that a comment explaining logic in the API would be useful.

Please add a commit adding a comment to the + clock_drift line which explains the logic. Remembering why that's correct was not obvious at all so it'll be good to have it there for posterity

Previously indexes that were past the length of the approvals bitvector
would contribute to the no_show count or the next_no_show value. This
commit changes the behavior to ignore garbage values.
@Lldenaurois
Copy link
Contributor Author

@rphmeier Added comment and modified logic such that we ignore indexes past the length of the approval vector.

Should be ready to go.

@rphmeier
Copy link
Contributor

bot merge

@ghost
Copy link

ghost commented Jun 17, 2021

Trying merge.

@ghost ghost merged commit a968261 into paritytech:master Jun 17, 2021
ordian added a commit that referenced this pull request Jun 18, 2021
* master:
  Set new staking limits (#3299)
  Bump derive_more from 0.99.11 to 0.99.14 (#3248)
  add revert consensus log (#3275)
  Add bridge team as codeowners of `bridges` Subtree (#3291)
  Extract and test count_no_shows method for approval voting (#3264)
This pull request was closed.
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants