This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update disputes prioritisation in dispute-coordinator
#6130
Merged
Merged
Changes from 25 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
56731cf
Scraper processes CandidateBacked events
tdimitrov 056a606
Change definition of best-effort
tdimitrov 9794e99
Fix `dispute-coordinator` tests
tdimitrov d44055e
Unit test for dispute filtering
tdimitrov 032475a
Clarification comment
tdimitrov a70d7d8
Add tests
tdimitrov 8bafd7a
Fix logic
tdimitrov dd6fbc0
Add metrics for refrained participations
tdimitrov baa7e20
Revert "Add tests"
tdimitrov d7af3f7
Revert "Unit test for dispute filtering"
tdimitrov 18f7a14
fix dispute-coordinator tests
tdimitrov b82df59
Fix scraping
tdimitrov 1523bce
new tests
tdimitrov 2c6272f
Small fixes in guide
tdimitrov cd42bcb
Apply suggestions from code review
tdimitrov 0551b7c
Fix some comments and remove a pointless test
tdimitrov 2906d2a
Code review feedback
tdimitrov eaa250f
Clarification comment in tests
tdimitrov 9b40f11
Some tests
tdimitrov 7e3040b
Reference counted `CandidateHash` in scraper
tdimitrov 77cc49e
Proper handling for Backed and Included candidates in scraper
tdimitrov dcd0465
Update comments in tests
tdimitrov f925dd3
Guide update
tdimitrov 9dd091a
Fix cleanup logic for `backed_candidates_by_block_number`
tdimitrov e533e6d
Simplify cleanup
tdimitrov fcb99d0
Merge branch 'master' into disputes-backed
tdimitrov 56f4e2a
Make spellcheck happy
tdimitrov aecc3e0
Update tests
tdimitrov a97e29a
Extract candidate backing logic in separate struct
tdimitrov d29b300
Code review feedback
tdimitrov 0d498dc
Treat backed and included candidates in the same fashion
tdimitrov 40b4115
Update some comments
tdimitrov 4c030a1
Small improvements in test
tdimitrov 76bca96
spell check
tdimitrov a57ffaa
Fix some more comments
tdimitrov f9a4407
clean -> prune
tdimitrov c441720
Code review feedback
tdimitrov f283517
Reword comment
tdimitrov f7393a7
spelling
tdimitrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use polkadot_primitives::v2::CandidateHash; | ||
| use std::collections::HashMap; | ||
|
|
||
| /// Keeps `CandidateHash` in reference counted way. | ||
| /// Each `insert` saves a value with `reference count == 1` or increases the reference | ||
| /// count if the value already exists. | ||
| /// Each `remove` decreases the reference count for the corresponding `CandidateHash`. | ||
| /// If the reference count reaches 0 - the value is removed. | ||
| pub struct RefCountedCandidates { | ||
| candidates: HashMap<CandidateHash, usize>, | ||
| } | ||
|
|
||
| impl RefCountedCandidates { | ||
| pub fn new() -> Self { | ||
| Self { candidates: HashMap::new() } | ||
| } | ||
| // If `CandidateHash` doesn't exist in the `HashMap` it is created and its reference | ||
| // count is set to 1. | ||
| // If `CandidateHash` already exists in the `HashMap` its reference count is increased. | ||
| pub fn insert(&mut self, candidate: CandidateHash) { | ||
| *self.candidates.entry(candidate).or_default() += 1; | ||
| } | ||
|
|
||
| // If a `CandidateHash` with reference count equals to 1 is about to be removed - the | ||
| // candidate is dropped from the container too. | ||
| // If a `CandidateHash` with reference count biger than 1 is about to be removed - the | ||
| // reference count is decreased and the candidate remains in the container. | ||
| pub fn remove(&mut self, candidate: &CandidateHash) { | ||
| match self.candidates.get_mut(candidate) { | ||
| Some(v) if *v > 1 => *v -= 1, | ||
| Some(v) => { | ||
| assert!(*v == 1); | ||
| self.candidates.remove(candidate); | ||
| }, | ||
| None => {}, | ||
| } | ||
| } | ||
|
|
||
| pub fn contains(&self, candidate: &CandidateHash) -> bool { | ||
| self.candidates.contains_key(&candidate) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use polkadot_primitives::v2::{BlakeTwo256, HashT}; | ||
|
|
||
| #[test] | ||
| fn element_is_removed_when_refcount_reaches_zero() { | ||
| let mut container = RefCountedCandidates::new(); | ||
|
|
||
| let zero = CandidateHash(BlakeTwo256::hash(&vec![0])); | ||
| let one = CandidateHash(BlakeTwo256::hash(&vec![1])); | ||
| // add two separate candidates | ||
| container.insert(zero); // refcount == 1 | ||
| container.insert(one); | ||
|
|
||
| // and increase the reference count for the first | ||
| container.insert(zero); // refcount == 2 | ||
|
|
||
| assert!(container.contains(&zero)); | ||
| assert!(container.contains(&one)); | ||
|
|
||
| // remove once -> refcount == 1 | ||
| container.remove(&zero); | ||
| assert!(container.contains(&zero)); | ||
| assert!(container.contains(&one)); | ||
|
|
||
| // remove once -> refcount == 0 | ||
| container.remove(&zero); | ||
| assert!(!container.contains(&zero)); | ||
| assert!(container.contains(&one)); | ||
|
|
||
| // remove the other element | ||
| container.remove(&one); | ||
| assert!(!container.contains(&zero)); | ||
| assert!(!container.contains(&one)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.