From 9a4895c86a67b69e99dbcdb9c53d0d4d7035be44 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Sat, 15 Dec 2018 20:44:33 +0000 Subject: [PATCH] take lock once in get_header_for_output (#2161) --- chain/src/chain.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index d845841fa..be4dd05ec 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -1123,11 +1123,9 @@ impl Chain { &self, output_ref: &OutputIdentifier, ) -> Result { - let pos = { - let txhashset = self.txhashset.read(); - let (_, pos) = txhashset.is_unspent(output_ref)?; - pos - }; + let txhashset = self.txhashset.read(); + + let (_, pos) = txhashset.is_unspent(output_ref)?; let mut min = 1; let mut max = { @@ -1137,8 +1135,8 @@ impl Chain { loop { let search_height = max - (max - min) / 2; - let h = self.get_header_by_height(search_height)?; - let h_prev = self.get_header_by_height(search_height - 1)?; + let h = txhashset.get_header_by_height(search_height)?; + let h_prev = txhashset.get_header_by_height(search_height - 1)?; if pos > h.output_mmr_size { min = search_height; } else if pos < h_prev.output_mmr_size {