Fix race between observing tick height being set to last tick and blockhash being observed on a bank (#6013)
This commit is contained in:
parent
02647c25a9
commit
261ea00efb
|
@ -768,19 +768,29 @@ impl Bank {
|
|||
|
||||
// TODO: put this assert back in
|
||||
// assert!(!self.is_frozen());
|
||||
if self.ticks_per_slot() != 1 || self.slot() != 0 {
|
||||
self.tick_height.fetch_add(1, Ordering::Relaxed);
|
||||
inc_new_counter_debug!("bank-register_tick-registered", 1);
|
||||
}
|
||||
|
||||
let current_tick_height = self.tick_height.load(Ordering::Relaxed) as u64;
|
||||
let should_register_hash = {
|
||||
if self.ticks_per_slot() != 1 || self.slot() != 0 {
|
||||
let lock = {
|
||||
if (current_tick_height + 1) % self.ticks_per_slot == self.ticks_per_slot - 1 {
|
||||
Some(self.blockhash_queue.write().unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
self.tick_height.fetch_add(1, Ordering::Relaxed);
|
||||
inc_new_counter_debug!("bank-register_tick-registered", 1);
|
||||
lock
|
||||
} else if current_tick_height % self.ticks_per_slot == self.ticks_per_slot - 1 {
|
||||
// Register a new block hash if at the last tick in the slot
|
||||
Some(self.blockhash_queue.write().unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Register a new block hash if at the last tick in the slot
|
||||
if current_tick_height % self.ticks_per_slot == self.ticks_per_slot - 1 {
|
||||
self.blockhash_queue
|
||||
.write()
|
||||
.unwrap()
|
||||
.register_hash(hash, &self.fee_calculator);
|
||||
if let Some(mut w_blockhash_queue) = should_register_hash {
|
||||
w_blockhash_queue.register_hash(hash, &self.fee_calculator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue