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

Update disputes prioritisation in dispute-coordinator #6130

Merged
merged 39 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
56731cf
Scraper processes CandidateBacked events
tdimitrov Oct 5, 2022
056a606
Change definition of best-effort
tdimitrov Oct 5, 2022
9794e99
Fix `dispute-coordinator` tests
tdimitrov Oct 7, 2022
d44055e
Unit test for dispute filtering
tdimitrov Oct 7, 2022
032475a
Clarification comment
tdimitrov Oct 8, 2022
a70d7d8
Add tests
tdimitrov Oct 8, 2022
8bafd7a
Fix logic
tdimitrov Oct 10, 2022
dd6fbc0
Add metrics for refrained participations
tdimitrov Oct 10, 2022
baa7e20
Revert "Add tests"
tdimitrov Oct 10, 2022
d7af3f7
Revert "Unit test for dispute filtering"
tdimitrov Oct 10, 2022
18f7a14
fix dispute-coordinator tests
tdimitrov Oct 10, 2022
b82df59
Fix scraping
tdimitrov Oct 11, 2022
1523bce
new tests
tdimitrov Oct 11, 2022
2c6272f
Small fixes in guide
tdimitrov Oct 13, 2022
cd42bcb
Apply suggestions from code review
tdimitrov Oct 20, 2022
0551b7c
Fix some comments and remove a pointless test
tdimitrov Oct 20, 2022
2906d2a
Code review feedback
tdimitrov Oct 31, 2022
eaa250f
Clarification comment in tests
tdimitrov Nov 2, 2022
9b40f11
Some tests
tdimitrov Nov 7, 2022
7e3040b
Reference counted `CandidateHash` in scraper
tdimitrov Nov 7, 2022
77cc49e
Proper handling for Backed and Included candidates in scraper
tdimitrov Nov 8, 2022
dcd0465
Update comments in tests
tdimitrov Nov 9, 2022
f925dd3
Guide update
tdimitrov Nov 9, 2022
9dd091a
Fix cleanup logic for `backed_candidates_by_block_number`
tdimitrov Nov 9, 2022
e533e6d
Simplify cleanup
tdimitrov Nov 9, 2022
fcb99d0
Merge branch 'master' into disputes-backed
tdimitrov Nov 9, 2022
56f4e2a
Make spellcheck happy
tdimitrov Nov 9, 2022
aecc3e0
Update tests
tdimitrov Nov 9, 2022
a97e29a
Extract candidate backing logic in separate struct
tdimitrov Nov 10, 2022
d29b300
Code review feedback
tdimitrov Nov 10, 2022
0d498dc
Treat backed and included candidates in the same fashion
tdimitrov Nov 11, 2022
40b4115
Update some comments
tdimitrov Nov 11, 2022
4c030a1
Small improvements in test
tdimitrov Nov 11, 2022
76bca96
spell check
tdimitrov Nov 11, 2022
a57ffaa
Fix some more comments
tdimitrov Nov 11, 2022
f9a4407
clean -> prune
tdimitrov Nov 11, 2022
c441720
Code review feedback
tdimitrov Nov 11, 2022
f283517
Reword comment
tdimitrov Nov 11, 2022
f7393a7
spelling
tdimitrov Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Scraper processes CandidateBacked events
  • Loading branch information
tdimitrov committed Oct 20, 2022
commit 56731cf6feed7801571ab288dc955accf462a9c6
65 changes: 47 additions & 18 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const LRU_OBSERVED_BLOCKS_CAPACITY: NonZeroUsize = match NonZeroUsize::new(20) {
pub struct ChainScraper {
/// All candidates we have seen included, which not yet have been finalized.
included_candidates: HashSet<CandidateHash>,
/// All candidates we have seen backed
backed_candidates: HashSet<CandidateHash>,
/// including block -> `CandidateHash`
///
/// We need this to clean up `included_candidates` on finalization.
tdimitrov marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -97,6 +99,7 @@ impl ChainScraper {
{
let mut s = Self {
included_candidates: HashSet::new(),
backed_candidates: HashSet::new(),
candidates_by_block_number: BTreeMap::new(),
last_observed_blocks: LruCache::new(LRU_OBSERVED_BLOCKS_CAPACITY),
};
Expand All @@ -111,6 +114,11 @@ impl ChainScraper {
self.included_candidates.contains(candidate_hash)
}

/// Check whether the candidate is backed
pub fn is_candidate_backed(&mut self, candidate_hash: &CandidateHash) -> bool {
self.backed_candidates.contains(candidate_hash)
}

/// Query active leaves for any candidate `CandidateEvent::CandidateIncluded` events.
///
/// and updates current heads, so we can query candidates for all non finalized blocks.
Expand Down Expand Up @@ -182,28 +190,49 @@ impl ChainScraper {
where
Sender: overseer::DisputeCoordinatorSenderTrait,
{
// Get included events:
let included =
// Get included and backed events:
let events =
get_candidate_events(sender, block_hash)
.await?
.into_iter()
.filter_map(|ev| match ev {
CandidateEvent::CandidateIncluded(receipt, _, _, _) => Some(receipt),
_ => None,
.filter(|ev| match ev {
CandidateEvent::CandidateIncluded(_, _, _, _) => true,
CandidateEvent::CandidateBacked(_, _, _, _) => true,
_ => false,
});
for receipt in included {
let candidate_hash = receipt.hash();
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_number,
"Processing included event"
);
self.included_candidates.insert(candidate_hash);
self.candidates_by_block_number
.entry(block_number)
.or_default()
.insert(candidate_hash);
for ev in events {
match ev {
CandidateEvent::CandidateIncluded(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_number,
"Processing included event"
);
self.included_candidates.insert(candidate_hash);
self.candidates_by_block_number
.entry(block_number)
.or_default()
.insert(candidate_hash);
},
CandidateEvent::CandidateBacked(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_number,
"Processing backed event"
);
self.backed_candidates.insert(candidate_hash);
},
_ => {
tdimitrov marked this conversation as resolved.
Show resolved Hide resolved
debug_assert!(
false,
"Candidates are already filtered out. There should be nothing unexpected."
)
},
}
}
Ok(())
}
Expand Down
29 changes: 21 additions & 8 deletions node/core/dispute-coordinator/src/scraping/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,22 @@ fn get_block_number_hash(n: BlockNumber) -> Hash {
}

/// Get a dummy event that corresponds to candidate inclusion for the given block number.
fn get_candidate_included_events(block_number: BlockNumber) -> Vec<CandidateEvent> {
vec![CandidateEvent::CandidateIncluded(
make_candidate_receipt(get_block_number_hash(block_number)),
HeadData::default(),
CoreIndex::from(0),
GroupIndex::from(0),
)]
fn get_candidate_events(block_number: BlockNumber) -> Vec<CandidateEvent> {
let candidate_receipt = make_candidate_receipt(get_block_number_hash(block_number));
vec![
CandidateEvent::CandidateIncluded(
candidate_receipt.clone(),
HeadData::default(),
CoreIndex::from(0),
GroupIndex::from(0),
),
CandidateEvent::CandidateBacked(
candidate_receipt,
HeadData::default(),
CoreIndex::from(0),
GroupIndex::from(0),
),
]
}

async fn assert_candidate_events_request(virtual_overseer: &mut VirtualOverseer, chain: &[Hash]) {
Expand All @@ -163,7 +172,7 @@ async fn assert_candidate_events_request(virtual_overseer: &mut VirtualOverseer,
)) => {
let maybe_block_number = chain.iter().position(|h| *h == hash);
let response = maybe_block_number
.map(|num| get_candidate_included_events(num as u32))
.map(|num| get_candidate_events(num as u32))
.unwrap_or_default();
tx.send(Ok(response)).unwrap();
}
Expand Down Expand Up @@ -236,7 +245,9 @@ fn scraper_provides_included_state_when_initialized() {
let TestState { mut chain, mut scraper, mut ctx } = state;

assert!(!scraper.is_candidate_included(&candidate_2.hash()));
assert!(!scraper.is_candidate_backed(&candidate_2.hash()));
assert!(scraper.is_candidate_included(&candidate_1.hash()));
assert!(scraper.is_candidate_backed(&candidate_1.hash()));

// After next active leaves update we should see the candidate included.
let next_update = next_leaf(&mut chain);
Expand All @@ -253,6 +264,7 @@ fn scraper_provides_included_state_when_initialized() {
.await;

assert!(scraper.is_candidate_included(&candidate_2.hash()));
assert!(scraper.is_candidate_backed(&candidate_2.hash()));
});
}

Expand Down Expand Up @@ -282,6 +294,7 @@ fn scraper_requests_candidates_of_leaf_ancestors() {
for block_number in 1..next_block_number {
let candidate = make_candidate_receipt(get_block_number_hash(block_number));
assert!(scraper.is_candidate_included(&candidate.hash()));
assert!(scraper.is_candidate_backed(&candidate.hash()));
}
});
}
Expand Down