From f6444b2e704aab725320580104e1f97e68bdf9e1 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Wed, 11 Sep 2024 16:33:56 +0200 Subject: [PATCH] fix(tree): avoid holding two locks simultaneously (#10843) --- crates/chain-state/src/in_memory.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index 2b1f9e8ce3..79eb8b11fc 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -113,10 +113,8 @@ impl InMemoryState { /// Returns the current chain head state. pub(crate) fn head_state(&self) -> Option> { - self.numbers - .read() - .last_key_value() - .and_then(|(_, hash)| self.blocks.read().get(hash).cloned()) + let hash = *self.numbers.read().last_key_value()?.1; + self.state_by_hash(hash) } /// Returns the pending state corresponding to the current head plus one,