Move initialisations to simplify cancelled checks
This commit is contained in:
parent
5a360a5c6a
commit
1655db285d
|
@ -357,6 +357,7 @@ template<unsigned int N, unsigned int K>
|
||||||
std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled)
|
std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled)
|
||||||
{
|
{
|
||||||
eh_index init_size { 1 << (CollisionBitLength + 1) };
|
eh_index init_size { 1 << (CollisionBitLength + 1) };
|
||||||
|
eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) };
|
||||||
|
|
||||||
// First run the algorithm with truncated indices
|
// First run the algorithm with truncated indices
|
||||||
|
|
||||||
|
@ -364,6 +365,8 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||||
// Each element of partialSolns is dynamically allocated in a call to
|
// Each element of partialSolns is dynamically allocated in a call to
|
||||||
// GetTruncatedIndices(), and freed at the end of this function.
|
// GetTruncatedIndices(), and freed at the end of this function.
|
||||||
std::vector<eh_trunc*> partialSolns;
|
std::vector<eh_trunc*> partialSolns;
|
||||||
|
std::set<std::vector<eh_index>> solns;
|
||||||
|
int invalidCount = 0;
|
||||||
{
|
{
|
||||||
|
|
||||||
// 1) Generate first list
|
// 1) Generate first list
|
||||||
|
@ -458,7 +461,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||||
}
|
}
|
||||||
|
|
||||||
i += j;
|
i += j;
|
||||||
if (cancelled(FinalColliding)) break;
|
if (cancelled(FinalColliding)) goto cancelsolver;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
LogPrint("pow", "- List is empty\n");
|
LogPrint("pow", "- List is empty\n");
|
||||||
|
@ -469,10 +472,6 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||||
|
|
||||||
// Now for each solution run the algorithm again to recreate the indices
|
// Now for each solution run the algorithm again to recreate the indices
|
||||||
LogPrint("pow", "Culling solutions\n");
|
LogPrint("pow", "Culling solutions\n");
|
||||||
std::set<std::vector<eh_index>> solns;
|
|
||||||
eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) };
|
|
||||||
int invalidCount = 0;
|
|
||||||
if (cancelled(StartCulling)) goto cancelsolver;
|
|
||||||
for (eh_trunc* partialSoln : partialSolns) {
|
for (eh_trunc* partialSoln : partialSolns) {
|
||||||
size_t hashLen;
|
size_t hashLen;
|
||||||
size_t lenIndices;
|
size_t lenIndices;
|
||||||
|
|
|
@ -118,7 +118,6 @@ enum EhSolverCancelCheck
|
||||||
RoundEnd,
|
RoundEnd,
|
||||||
FinalSorting,
|
FinalSorting,
|
||||||
FinalColliding,
|
FinalColliding,
|
||||||
StartCulling,
|
|
||||||
PartialGeneration,
|
PartialGeneration,
|
||||||
PartialSorting,
|
PartialSorting,
|
||||||
PartialSubtreeEnd,
|
PartialSubtreeEnd,
|
||||||
|
|
|
@ -51,12 +51,6 @@ TEST(equihash_tests, check_basic_solver_cancelled) {
|
||||||
}), EhSolverCancelledException);
|
}), EhSolverCancelledException);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
ASSERT_NO_THROW(Eh48_5.BasicSolve(state, [](EhSolverCancelCheck pos) {
|
|
||||||
return pos == StartCulling;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ASSERT_NO_THROW(Eh48_5.BasicSolve(state, [](EhSolverCancelCheck pos) {
|
ASSERT_NO_THROW(Eh48_5.BasicSolve(state, [](EhSolverCancelCheck pos) {
|
||||||
return pos == PartialGeneration;
|
return pos == PartialGeneration;
|
||||||
|
@ -130,25 +124,9 @@ TEST(equihash_tests, check_optimised_solver_cancelled) {
|
||||||
}), EhSolverCancelledException);
|
}), 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) {
|
ASSERT_THROW(Eh48_5.OptimisedSolve(state, [](EhSolverCancelCheck pos) {
|
||||||
return pos == StartCulling;
|
return pos == FinalColliding;
|
||||||
}), EhSolverCancelledException);
|
}), EhSolverCancelledException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue