From 33c5a9835a47f2007a6aa10064e77f5c29709020 Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Fri, 6 Apr 2018 18:46:07 +0100 Subject: [PATCH] Avoid double-locking on add eviction. Fixes #936 --- chain/src/chain.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 34fe38f82..53842534f 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -87,7 +87,7 @@ impl OrphanBlockPool { let mut heights = height_idx.keys().cloned().collect::>(); heights.sort_unstable(); for h in heights.iter().rev() { - let _ = self.remove_by_height(h); + let _ = self.remove_by_height_nolock(h); if orphans.len() < MAX_ORPHAN_SIZE { break; } @@ -102,6 +102,10 @@ impl OrphanBlockPool { fn remove_by_height(&self, height: &u64) -> Option> { let mut orphans = self.orphans.write().unwrap(); let mut height_idx = self.height_idx.write().unwrap(); + self.remove_by_height_nolock(height) + } + + fn remove_by_height_nolock(&self, height: &u64) -> Option> { height_idx .remove(height) .map(|hs| hs.iter().filter_map(|h| orphans.remove(h)).collect())