Skip to content

Commit d8020c0

Browse files
Delay lock taking slightly (#6627)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 728d5df commit d8020c0

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
@@ -674,7 +674,6 @@ namespace ccf
674674
bool init_from_snapshot(
675675
const std::vector<uint8_t>& hash_at_snapshot) override
676676
{
677-
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
678677
// The history can be initialised after a snapshot has been applied by
679678
// deserialising the tree in the signatures table and then applying the
680679
// hash of the transaction at which the snapshot was taken
@@ -688,6 +687,10 @@ namespace ccf
688687
return false;
689688
}
690689

690+
// Delay taking this lock until _after_ the read above, to avoid lock
691+
// inversions
692+
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
693+
691694
CCF_ASSERT_FMT(
692695
!replicated_state_tree.in_range(1),
693696
"Tree is not empty before initialising from snapshot");

0 commit comments

Comments
 (0)