Skip to content

Commit

Permalink
[release/5.x] Cherry pick: Delay lock taking slightly (#6627) (#6635)
Browse files Browse the repository at this point in the history
Co-authored-by: Eddy Ashton <[email protected]>
  • Loading branch information
CCF [bot] and eddyashton authored Nov 12, 2024
1 parent 4873a6c commit 95614d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ namespace ccf
bool init_from_snapshot(
const std::vector<uint8_t>& hash_at_snapshot) override
{
std::lock_guard<ccf::pal::Mutex> guard(state_lock);
// The history can be initialised after a snapshot has been applied by
// deserialising the tree in the signatures table and then applying the
// hash of the transaction at which the snapshot was taken
Expand All @@ -626,6 +625,10 @@ namespace ccf
return false;
}

// Delay taking this lock until _after_ the read above, to avoid lock
// inversions
std::lock_guard<ccf::pal::Mutex> guard(state_lock);

CCF_ASSERT_FMT(
!replicated_state_tree.in_range(1),
"Tree is not empty before initialising from snapshot");
Expand Down

0 comments on commit 95614d0

Please sign in to comment.