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

fix: take into account only active suspensions #5359

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

marcellorigotti
Copy link
Contributor

Pull Request

Closes: PRO-xxx

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

Changed the way we count for suspensions, we now keep into account if the suspension is still valid, based on the current block.

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 7.69231% with 12 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (5baa3dd) to head (3ac5deb).

Files with missing lines Patch % Lines
state-chain/runtime/src/lib.rs 8% 0 Missing and 12 partials ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5359    +/-   ##
======================================
- Coverage     71%     71%    -0%     
======================================
  Files        496     496            
  Lines      86485   86361   -124     
  Branches   86485   86361   -124     
======================================
- Hits       61751   61553   -198     
- Misses     21971   22026    +55     
- Partials    2763    2782    +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -2147,7 +2147,8 @@ impl_runtime_apis! {
}

fn cf_suspended_validators() -> Vec<(Offence, u32)> {
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, elem)| (key, elem.len() as u32)).collect()
let current_block = <frame_system::Pallet<Runtime>>::block_number();
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, elem)| (key, elem.iter().filter(|(suspended_until, _)| *suspended_until < current_block).collect::<Vec<_>>().len() as u32)).collect()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be > (or >=)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, elem)| (key, elem.iter().filter(|(suspended_until, _)| *suspended_until < current_block).collect::<Vec<_>>().len() as u32)).collect()
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, elem)| (key, elem.iter().filter(|(suspended_until, _)| *suspended_until > current_block).count() as u32)).collect()

@marcellorigotti
Copy link
Contributor Author

Is there a better way to filter out duplicates without collecting to a set?
I tried to use https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.unique, but with no std features those method are disabled..

@msgmaxim
Copy link
Contributor

Is there a better way to filter out duplicates without collecting to a set? I tried to use https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.unique, but with no std features those method are disabled..

Not really, and I believe even unique from itertools uses a hashset internally.

@dandanlen dandanlen changed the title keep into account only active suspensions fix: take into account only active suspensions Oct 28, 2024
@dandanlen dandanlen added this pull request to the merge queue Oct 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 28, 2024
@dandanlen dandanlen added this pull request to the merge queue Oct 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2024
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.

3 participants