diff --git a/client/api/src/in_mem.rs b/client/api/src/in_mem.rs index 45c41fbcb7b20..1de2747eb4c76 100644 --- a/client/api/src/in_mem.rs +++ b/client/api/src/in_mem.rs @@ -19,6 +19,7 @@ //! In memory client backend use std::collections::HashMap; +use std::ptr; use std::sync::Arc; use parking_lot::RwLock; use sp_core::{ @@ -191,11 +192,19 @@ impl Blockchain { /// Compare this blockchain with another in-mem blockchain pub fn equals_to(&self, other: &Self) -> bool { + // Check ptr equality first to avoid double read locks. + if ptr::eq(self, other) { + return true; + } self.canon_equals_to(other) && self.storage.read().blocks == other.storage.read().blocks } /// Compare canonical chain to other canonical chain. pub fn canon_equals_to(&self, other: &Self) -> bool { + // Check ptr equality first to avoid double read locks. + if ptr::eq(self, other) { + return true; + } let this = self.storage.read(); let other = other.storage.read(); this.hashes == other.hashes