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

Merged
merged 4 commits into from
Nov 5, 2024

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 (5180af2) to head (4a26919).
Report is 2 commits behind head on main.

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     72%     71%    -0%     
======================================
  Files        495     495            
  Lines      86276   86152   -124     
  Branches   86276   86152   -124     
======================================
- Hits       61717   61525   -192     
- Misses     21783   21837    +54     
- Partials    2776    2790    +14     

☔ 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
@dandanlen dandanlen enabled auto-merge November 4, 2024 11:07
@dandanlen dandanlen added this pull request to the merge queue Nov 4, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 4, 2024
@dandanlen dandanlen added this pull request to the merge queue Nov 4, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 4, 2024
@dandanlen dandanlen added this pull request to the merge queue Nov 5, 2024
Merged via the queue into main with commit 87ba274 Nov 5, 2024
47 of 49 checks passed
@dandanlen dandanlen deleted the updateMonitoringSuspendedValidators branch November 5, 2024 14:45
dandanlen added a commit that referenced this pull request Nov 6, 2024
* keep into account only active suspensions

* filter out duplicates and properly count keygen suspensions

* addressed comments

---------

Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
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