Skip to content

Commit

Permalink
runtime: fix possible deadlock in bank (#10466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boqin Qin authored Jun 10, 2020
1 parent 6eb5ef6 commit 1e3554b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use std::{
mem,
ops::RangeInclusive,
path::PathBuf,
ptr,
rc::Rc,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
sync::{Arc, RwLock, RwLockReadGuard},
Expand Down Expand Up @@ -2508,6 +2509,9 @@ impl Bank {
}

pub fn compare_bank(&self, dbank: &Bank) {
if ptr::eq(self, dbank) {
return;
}
assert_eq!(self.slot, dbank.slot);
assert_eq!(self.collector_id, dbank.collector_id);
assert_eq!(self.epoch_schedule, dbank.epoch_schedule);
Expand All @@ -2523,21 +2527,29 @@ impl Bank {
dbank.is_delta.load(Ordering::Relaxed)
);

let st = self.stakes.read().unwrap();
let dst = dbank.stakes.read().unwrap();
assert_eq!(*st, *dst);
{
let bh = self.hash.read().unwrap();
let dbh = dbank.hash.read().unwrap();
assert_eq!(*bh, *dbh);
}

let bh = self.hash.read().unwrap();
let dbh = dbank.hash.read().unwrap();
assert_eq!(*bh, *dbh);
{
let st = self.stakes.read().unwrap();
let dst = dbank.stakes.read().unwrap();
assert_eq!(*st, *dst);
}

let bhq = self.blockhash_queue.read().unwrap();
let dbhq = dbank.blockhash_queue.read().unwrap();
assert_eq!(*bhq, *dbhq);
{
let bhq = self.blockhash_queue.read().unwrap();
let dbhq = dbank.blockhash_queue.read().unwrap();
assert_eq!(*bhq, *dbhq);
}

let sc = self.src.status_cache.read().unwrap();
let dsc = dbank.src.status_cache.read().unwrap();
assert_eq!(*sc, *dsc);
{
let sc = self.src.status_cache.read().unwrap();
let dsc = dbank.src.status_cache.read().unwrap();
assert_eq!(*sc, *dsc);
}
assert_eq!(
self.rc.accounts.bank_hash_at(self.slot),
dbank.rc.accounts.bank_hash_at(dbank.slot)
Expand Down

0 comments on commit 1e3554b

Please sign in to comment.