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

Commit

Permalink
Fix scraping
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed Oct 12, 2022
1 parent 48bb73b commit fa9ef2d
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ 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.
Expand All @@ -77,6 +75,8 @@ pub struct ChainScraper {
/// We assume that ancestors of cached blocks are already processed, i.e. we have saved
/// corresponding included candidates.
last_observed_blocks: LruCache<Hash, ()>,
/// All candidates we have seen backed
backed_candidates: HashSet<CandidateHash>,
}

impl ChainScraper {
Expand All @@ -99,9 +99,9 @@ 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),
backed_candidates: HashSet::new(),
};
let update =
ActiveLeavesUpdate { activated: Some(initial_head), deactivated: Default::default() };
Expand Down Expand Up @@ -175,6 +175,7 @@ impl ChainScraper {
// Clean up finalized:
for finalized_candidate in finalized.into_values().flatten() {
self.included_candidates.remove(&finalized_candidate);
self.backed_candidates.remove(&finalized_candidate);
}
}

Expand All @@ -191,16 +192,7 @@ impl ChainScraper {
Sender: overseer::DisputeCoordinatorSenderTrait,
{
// Get included and backed events:
let events =
get_candidate_events(sender, block_hash)
.await?
.into_iter()
.filter(|ev| match ev {
CandidateEvent::CandidateIncluded(_, _, _, _) => true,
CandidateEvent::CandidateBacked(_, _, _, _) => true,
_ => false,
});
for ev in events {
for ev in get_candidate_events(sender, block_hash).await? {
match ev {
CandidateEvent::CandidateIncluded(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
Expand All @@ -227,10 +219,7 @@ impl ChainScraper {
self.backed_candidates.insert(candidate_hash);
},
_ => {
debug_assert!(
false,
"Candidates are already filtered out. There should be nothing unexpected."
)
// skip the rest
},
}
}
Expand Down

0 comments on commit fa9ef2d

Please sign in to comment.