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(nns): Count stale and expired voting power neurons. #3090

Merged

Conversation

daniel-wong-dfinity-org
Copy link
Contributor

@daniel-wong-dfinity-org daniel-wong-dfinity-org commented Dec 10, 2024

Here,

  • stale = time since voting power was refreshed is between strictly 6 and 7 months (or whatever VotingPowerEconomics dictates).
  • expired = time since voting power was refreshed is >= 7 months (again, per VotingPowerEconomics).

I think the main thing we really care about here is the number of such neurons in those two (sub)categories. However, it is not much harder to gather additional statistics (thanks to existing code for compiling statistics for arbitrary neuron (sub)categories). Therefore, a whole bunch of other stats about these two subcategories of neurons is also exported.

FWIW, if you strip away the highly repetitive code (and don't count test code), this change is actually pretty small.

References

This is part of the "periodic confirmation" feature that was recently approved in proposal 132411.

Closes NNS1-3418.

👈 Previous PR

@daniel-wong-dfinity-org daniel-wong-dfinity-org marked this pull request as ready for review December 10, 2024 15:18
@daniel-wong-dfinity-org daniel-wong-dfinity-org requested a review from a team as a code owner December 10, 2024 15:18
github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2024
Most of the changes here are for breaking out voting power into deciding
vs. potential, and copying those around, because of duplicate types.

Another metric in this PR: When the current prune following cycle began.

# References

This is part of the "periodic confirmation" feature that was recently
approved in proposal [132411][prop].

[prop]: https://dashboard.internetcomputer.org/proposal/132411

[Next PR 👉][next]

[next]: #3090
Base automatically changed from periodic-confirmation-metrics-daniel-wong to master December 10, 2024 21:12
@daniel-wong-dfinity-org daniel-wong-dfinity-org force-pushed the count-stale-and-expired-voting-power-neurons-daniel-wong branch from deed965 to c5239e0 Compare December 10, 2024 21:42
@daniel-wong-dfinity-org daniel-wong-dfinity-org added this pull request to the merge queue Dec 10, 2024
@daniel-wong-dfinity-org daniel-wong-dfinity-org removed this pull request from the merge queue due to a manual request Dec 10, 2024
// Here, we assume that the neuron was not refreshed in the future.
// This doesn't always hold in tests though, due to the difficulty
// of constructing realistic data/scenarios.
now_seconds.saturating_sub(neuron.voting_power_refreshed_timestamp_seconds());
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a comment interrupting setting a variable here - could we move the comment up above the let statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

I think this is slightly better though. In general, comments should be as close to the thing that they are talking about as possible. In particular, this comment is not about the variable; it is about the expression (that we use to set the variable). More specifically, this comment tries to justify that use of saturating_sub (which is unusual).

// of constructing realistic data/scenarios.
now_seconds.saturating_sub(neuron.voting_power_refreshed_timestamp_seconds());
let Some(seconds_losing_voting_power) = seconds_since_voting_power_refreshed
.checked_sub(voting_power_economics.get_start_reducing_voting_power_after_seconds())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kind of a clever way to do this, but wouldn't it be simpler to use a comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Is this really exotic??

Yes, None is not as explicit as observed < limit.

For better or worse, we have pledged to Andy to use checked_sub (et. al.) instead of the - operator. Therefore, I assume the team is familiar with checked_sub. In that case, I think this should not be considered particularly "clever".

Tangent

In an ideal world, we wouldn't use u64 et. al. Instead, we should be like Motoko and Python (and to a lesser degree, the Google C++ style guide): Int. Int is closed under subtraction (and all the other math operations, except divide by 0 is ofc undefined), just like math. In that case, I would consider doing it like this:

let excess = observed - limit; // no checked_sub tyranny
if excess < 0 {
  return;
}

if excess < uber_limit {
  // merely stale
} else {
  // expired
}

@max-dfinity max-dfinity added this pull request to the merge queue Dec 10, 2024
Merged via the queue into master with commit c606036 Dec 10, 2024
27 checks passed
@max-dfinity max-dfinity deleted the count-stale-and-expired-voting-power-neurons-daniel-wong branch December 10, 2024 23:23
@daniel-wong-dfinity-org
Copy link
Contributor Author

daniel-wong-dfinity-org commented Dec 11, 2024

omnibus follow up ticket: https://dfinity.atlassian.net/browse/NNS1-3446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants