Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
client/api: fix possible deadlock when comparing with itself (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boqin Qin authored Jun 8, 2020
1 parent 39a3372 commit 4a56061
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a56061

Please sign in to comment.