diff --git a/src/node/history.h b/src/node/history.h index d14e60f3456c..8796deb97a3e 100644 --- a/src/node/history.h +++ b/src/node/history.h @@ -612,7 +612,6 @@ namespace ccf bool init_from_snapshot( const std::vector& hash_at_snapshot) override { - std::lock_guard 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 @@ -626,6 +625,10 @@ namespace ccf return false; } + // Delay taking this lock until _after_ the read above, to avoid lock + // inversions + std::lock_guard guard(state_lock); + CCF_ASSERT_FMT( !replicated_state_tree.in_range(1), "Tree is not empty before initialising from snapshot");