Skip to content
Snippets Groups Projects
Commit d8848486 authored by Boqin Qin's avatar Boqin Qin Committed by GitHub
Browse files

client/api: fix possible deadlock when comparing with itself (#6277)

parent 15ecac5c
No related merge requests found
......@@ -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<Block: BlockT> Blockchain<Block> {
/// 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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment