Skip to content

Commit

Permalink
Fix wrong ref counting (#1358)
Browse files Browse the repository at this point in the history
* Fix wrong ref counting

in case of multiple inserts at same height.

* More warn

---------

Co-authored-by: eskimor <eskimor@no-such-url.com>
  • Loading branch information
eskimor and eskimor authored Sep 1, 2023
1 parent a2b6470 commit 23a2b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions polkadot/node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ impl Initialized {
if import_result.has_fresh_byzantine_threshold_against() {
let blocks_including = self.scraper.get_blocks_including_candidate(&candidate_hash);
for (parent_block_number, parent_block_hash) in &blocks_including {
gum::trace!(
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
?parent_block_number,
Expand All @@ -1282,7 +1282,7 @@ impl Initialized {
if blocks_including.len() > 0 {
ctx.send_message(ChainSelectionMessage::RevertBlocks(blocks_including)).await;
} else {
gum::debug!(
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
?session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ impl ScrapedCandidates {
}

pub fn insert(&mut self, block_number: BlockNumber, candidate_hash: CandidateHash) {
self.candidates.insert(candidate_hash);
self.candidates_by_block_number
if self
.candidates_by_block_number
.entry(block_number)
.or_default()
.insert(candidate_hash);
.insert(candidate_hash)
{
self.candidates.insert(candidate_hash);
}
}

// Used only for tests to verify the pruning doesn't leak data.
Expand All @@ -159,6 +162,8 @@ mod scraped_candidates_tests {
let mut candidates = ScrapedCandidates::new();
let target = CandidateHash(BlakeTwo256::hash(&vec![1, 2, 3]));
candidates.insert(1, target);
// Repeated inserts at same height should be fine:
candidates.insert(1, target);

assert!(candidates.contains(&target));

Expand Down

0 comments on commit 23a2b7b

Please sign in to comment.