Skip to content

Commit 8b5d949

Browse files
eddyashtonachamayou
andcommitted
Delay lock taking slightly (#6627)
Co-authored-by: Amaury Chamayou <[email protected]> (cherry picked from commit d8020c0)
1 parent 4873a6c commit 8b5d949

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/node/history.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ namespace ccf
612612
bool init_from_snapshot(
613613
const std::vector<uint8_t>& hash_at_snapshot) override
614614
{
615-
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
616615
// The history can be initialised after a snapshot has been applied by
617616
// deserialising the tree in the signatures table and then applying the
618617
// hash of the transaction at which the snapshot was taken
@@ -626,6 +625,10 @@ namespace ccf
626625
return false;
627626
}
628627

628+
// Delay taking this lock until _after_ the read above, to avoid lock
629+
// inversions
630+
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
631+
629632
CCF_ASSERT_FMT(
630633
!replicated_state_tree.in_range(1),
631634
"Tree is not empty before initialising from snapshot");

0 commit comments

Comments
 (0)