mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Fix wrong ref counting (#1358)
* Fix wrong ref counting in case of multiple inserts at same height. * More warn --------- Co-authored-by: eskimor <eskimor@no-such-url.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user