Skip to content

Commit 1e99254

Browse files
committed
Reuse fork choice read lock instead of re-acquiring it immediately (#4688)
## Issue Addressed I went through the code base and look for places where we acquire fork choice locks (after the deadlock bug was found and fixed in #4687), and discovered an instance where we re-acquire a lock immediately after dropping it. This shouldn't cause deadlock like the other issue, but is slightly less efficient.
1 parent 4b6cb3d commit 1e99254

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -754,22 +754,16 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
754754
// reboot if the `observed_block_producers` cache is empty. In that case, without this
755755
// check, we will load the parent and state from disk only to find out later that we
756756
// already know this block.
757-
if chain
758-
.canonical_head
759-
.fork_choice_read_lock()
760-
.contains_block(&block_root)
761-
{
757+
let fork_choice_read_lock = chain.canonical_head.fork_choice_read_lock();
758+
if fork_choice_read_lock.contains_block(&block_root) {
762759
return Err(BlockError::BlockIsAlreadyKnown);
763760
}
764761

765762
// Do not process a block that doesn't descend from the finalized root.
766763
//
767764
// We check this *before* we load the parent so that we can return a more detailed error.
768-
check_block_is_finalized_checkpoint_or_descendant(
769-
chain,
770-
&chain.canonical_head.fork_choice_read_lock(),
771-
&block,
772-
)?;
765+
check_block_is_finalized_checkpoint_or_descendant(chain, &fork_choice_read_lock, &block)?;
766+
drop(fork_choice_read_lock);
773767

774768
let block_epoch = block.slot().epoch(T::EthSpec::slots_per_epoch());
775769
let (parent_block, block) = verify_parent_block_is_known(chain, block)?;

0 commit comments

Comments
 (0)