diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index 0fd2b2910..e71a9788f 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -357,6 +357,7 @@ template std::set> Equihash::OptimisedSolve(const eh_HashState& base_state, const std::function cancelled) { eh_index init_size { 1 << (CollisionBitLength + 1) }; + eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) }; // First run the algorithm with truncated indices @@ -364,6 +365,8 @@ std::set> Equihash::OptimisedSolve(const eh_HashState // Each element of partialSolns is dynamically allocated in a call to // GetTruncatedIndices(), and freed at the end of this function. std::vector partialSolns; + std::set> solns; + int invalidCount = 0; { // 1) Generate first list @@ -458,7 +461,7 @@ std::set> Equihash::OptimisedSolve(const eh_HashState } i += j; - if (cancelled(FinalColliding)) break; + if (cancelled(FinalColliding)) goto cancelsolver; } } else LogPrint("pow", "- List is empty\n"); @@ -469,10 +472,6 @@ std::set> Equihash::OptimisedSolve(const eh_HashState // Now for each solution run the algorithm again to recreate the indices LogPrint("pow", "Culling solutions\n"); - std::set> solns; - eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) }; - int invalidCount = 0; - if (cancelled(StartCulling)) goto cancelsolver; for (eh_trunc* partialSoln : partialSolns) { size_t hashLen; size_t lenIndices; diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h index f561b0249..044b67de9 100644 --- a/src/crypto/equihash.h +++ b/src/crypto/equihash.h @@ -118,7 +118,6 @@ enum EhSolverCancelCheck RoundEnd, FinalSorting, FinalColliding, - StartCulling, PartialGeneration, PartialSorting, PartialSubtreeEnd, diff --git a/src/gtest/test_equihash.cpp b/src/gtest/test_equihash.cpp index 52636ba7d..7e281990a 100644 --- a/src/gtest/test_equihash.cpp +++ b/src/gtest/test_equihash.cpp @@ -51,12 +51,6 @@ TEST(equihash_tests, check_basic_solver_cancelled) { }), EhSolverCancelledException); } - { - ASSERT_NO_THROW(Eh48_5.BasicSolve(state, [](EhSolverCancelCheck pos) { - return pos == StartCulling; - })); - } - { ASSERT_NO_THROW(Eh48_5.BasicSolve(state, [](EhSolverCancelCheck pos) { return pos == PartialGeneration; @@ -130,25 +124,9 @@ TEST(equihash_tests, check_optimised_solver_cancelled) { }), EhSolverCancelledException); } - { - // More state required here, because in OptimisedSolve() the - // FinalColliding cancellation check can't throw because it will leak - // memory, and it can't goto because that steps over initialisations. - bool triggered = false; - ASSERT_THROW(Eh48_5.OptimisedSolve(state, [=](EhSolverCancelCheck pos) mutable { - if (triggered) - return pos == StartCulling; - if (pos == FinalColliding) { - triggered = true; - return true; - } - return false; - }), EhSolverCancelledException); - } - { ASSERT_THROW(Eh48_5.OptimisedSolve(state, [](EhSolverCancelCheck pos) { - return pos == StartCulling; + return pos == FinalColliding; }), EhSolverCancelledException); }