Skip to content
Snippets Groups Projects
Unverified Commit 23a2b7b5 authored by eskimor's avatar eskimor Committed by GitHub
Browse files

Fix wrong ref counting (#1358)


* Fix wrong ref counting

in case of multiple inserts at same height.

* More warn

---------

Co-authored-by: default avatareskimor <eskimor@no-such-url.com>
parent a2b64706
Branches
No related merge requests found
Pipeline #386308 failed with stages
in 48 minutes and 45 seconds
......@@ -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,
......@@ -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,
......
......@@ -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.
......@@ -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));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment