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

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

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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