Add tests that exercise the cancellation code branches
This commit is contained in:
@@ -193,7 +193,7 @@ eh_trunc* TruncatedStepRow<WIDTH>::GetTruncatedIndices(size_t len, size_t lenInd
|
||||
}
|
||||
|
||||
template<unsigned int N, unsigned int K>
|
||||
std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& base_state, const std::function<bool()> cancelled)
|
||||
std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled)
|
||||
{
|
||||
eh_index init_size { 1 << (CollisionBitLength + 1) };
|
||||
|
||||
@@ -206,7 +206,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
for (eh_index i = 0; i < init_size; i++) {
|
||||
X.emplace_back(N, base_state, i);
|
||||
// Slow down checking to prevent segfaults (??)
|
||||
if (i % 10000 == 0 && cancelled()) throw solver_cancelled;
|
||||
if (i % 10000 == 0 && cancelled(ListGeneration)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// 3) Repeat step 2 until 2n/(k+1) bits remain
|
||||
@@ -215,7 +215,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
// 2a) Sort the list
|
||||
LogPrint("pow", "- Sorting list\n");
|
||||
std::sort(X.begin(), X.end(), CompareSR(CollisionByteLength));
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(ListSorting)) throw solver_cancelled;
|
||||
|
||||
LogPrint("pow", "- Finding collisions\n");
|
||||
int i = 0;
|
||||
@@ -245,7 +245,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
}
|
||||
|
||||
i += j;
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(ListColliding)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// 2e) Handle edge case where final table entry has no collision
|
||||
@@ -265,7 +265,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
|
||||
hashLen -= CollisionByteLength;
|
||||
lenIndices *= 2;
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(RoundEnd)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// k+1) Find a collision on last 2n(k+1) bits
|
||||
@@ -274,6 +274,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
if (X.size() > 1) {
|
||||
LogPrint("pow", "- Sorting list\n");
|
||||
std::sort(X.begin(), X.end(), CompareSR(hashLen));
|
||||
if (cancelled(FinalSorting)) throw solver_cancelled;
|
||||
LogPrint("pow", "- Finding collisions\n");
|
||||
int i = 0;
|
||||
while (i < X.size() - 1) {
|
||||
@@ -293,7 +294,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
|
||||
}
|
||||
|
||||
i += j;
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(FinalColliding)) throw solver_cancelled;
|
||||
}
|
||||
} else
|
||||
LogPrint("pow", "- List is empty\n");
|
||||
@@ -354,7 +355,7 @@ void CollideBranches(std::vector<FullStepRow<WIDTH>>& X, const size_t hlen, cons
|
||||
}
|
||||
|
||||
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()> 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) };
|
||||
|
||||
@@ -375,7 +376,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
for (eh_index i = 0; i < init_size; i++) {
|
||||
Xt.emplace_back(N, base_state, i, CollisionBitLength + 1);
|
||||
// Slow down checking to prevent segfaults (??)
|
||||
if (i % 10000 == 0 && cancelled()) throw solver_cancelled;
|
||||
if (i % 10000 == 0 && cancelled(ListGeneration)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// 3) Repeat step 2 until 2n/(k+1) bits remain
|
||||
@@ -384,7 +385,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
// 2a) Sort the list
|
||||
LogPrint("pow", "- Sorting list\n");
|
||||
std::sort(Xt.begin(), Xt.end(), CompareSR(CollisionByteLength));
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(ListSorting)) throw solver_cancelled;
|
||||
|
||||
LogPrint("pow", "- Finding collisions\n");
|
||||
int i = 0;
|
||||
@@ -413,7 +414,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
}
|
||||
|
||||
i += j;
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(ListColliding)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// 2e) Handle edge case where final table entry has no collision
|
||||
@@ -433,7 +434,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
|
||||
hashLen -= CollisionByteLength;
|
||||
lenIndices *= 2;
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(RoundEnd)) throw solver_cancelled;
|
||||
}
|
||||
|
||||
// k+1) Find a collision on last 2n(k+1) bits
|
||||
@@ -441,7 +442,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
if (Xt.size() > 1) {
|
||||
LogPrint("pow", "- Sorting list\n");
|
||||
std::sort(Xt.begin(), Xt.end(), CompareSR(hashLen));
|
||||
if (cancelled()) throw solver_cancelled;
|
||||
if (cancelled(FinalSorting)) throw solver_cancelled;
|
||||
LogPrint("pow", "- Finding collisions\n");
|
||||
int i = 0;
|
||||
while (i < Xt.size() - 1) {
|
||||
@@ -459,7 +460,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
}
|
||||
|
||||
i += j;
|
||||
if (cancelled()) break;
|
||||
if (cancelled(FinalColliding)) break;
|
||||
}
|
||||
} else
|
||||
LogPrint("pow", "- List is empty\n");
|
||||
@@ -473,7 +474,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
std::set<std::vector<eh_index>> solns;
|
||||
eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) };
|
||||
int invalidCount = 0;
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(StartCulling)) goto cancelsolver;
|
||||
for (eh_trunc* partialSoln : partialSolns) {
|
||||
size_t hashLen;
|
||||
size_t lenIndices;
|
||||
@@ -488,7 +489,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
for (eh_index j = 0; j < recreate_size; j++) {
|
||||
eh_index newIndex { UntruncateIndex(partialSoln[i], j, CollisionBitLength + 1) };
|
||||
icv.emplace_back(N, base_state, newIndex);
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(PartialGeneration)) goto cancelsolver;
|
||||
}
|
||||
boost::optional<std::vector<FullStepRow<FinalFullWidth>>> ic = icv;
|
||||
|
||||
@@ -504,7 +505,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
ic->reserve(ic->size() + X[r]->size());
|
||||
ic->insert(ic->end(), X[r]->begin(), X[r]->end());
|
||||
std::sort(ic->begin(), ic->end(), CompareSR(hashLen));
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(PartialSorting)) goto cancelsolver;
|
||||
size_t lti = rti-(1<<r);
|
||||
CollideBranches(*ic, hashLen, lenIndices,
|
||||
CollisionByteLength,
|
||||
@@ -527,9 +528,9 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
X.push_back(ic);
|
||||
break;
|
||||
}
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(PartialSubtreeEnd)) goto cancelsolver;
|
||||
}
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(PartialIndexEnd)) goto cancelsolver;
|
||||
}
|
||||
|
||||
// We are at the top of the tree
|
||||
@@ -537,7 +538,7 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
|
||||
for (FullStepRow<FinalFullWidth> row : *X[K]) {
|
||||
solns.insert(row.GetIndices(hashLen, lenIndices));
|
||||
}
|
||||
if (cancelled()) goto cancelsolver;
|
||||
if (cancelled(PartialEnd)) goto cancelsolver;
|
||||
continue;
|
||||
|
||||
invalidsolution:
|
||||
@@ -604,18 +605,18 @@ bool Equihash<N,K>::IsValidSolution(const eh_HashState& base_state, std::vector<
|
||||
|
||||
// Explicit instantiations for Equihash<96,3>
|
||||
template int Equihash<96,3>::InitialiseState(eh_HashState& base_state);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,3>::BasicSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,3>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,3>::BasicSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,3>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template bool Equihash<96,3>::IsValidSolution(const eh_HashState& base_state, std::vector<eh_index> soln);
|
||||
|
||||
// Explicit instantiations for Equihash<96,5>
|
||||
template int Equihash<96,5>::InitialiseState(eh_HashState& base_state);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,5>::BasicSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,5>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,5>::BasicSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<96,5>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template bool Equihash<96,5>::IsValidSolution(const eh_HashState& base_state, std::vector<eh_index> soln);
|
||||
|
||||
// Explicit instantiations for Equihash<48,5>
|
||||
template int Equihash<48,5>::InitialiseState(eh_HashState& base_state);
|
||||
template std::set<std::vector<eh_index>> Equihash<48,5>::BasicSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<48,5>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool()> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<48,5>::BasicSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template std::set<std::vector<eh_index>> Equihash<48,5>::OptimisedSolve(const eh_HashState& base_state, const std::function<bool(EhSolverCancelCheck)> cancelled);
|
||||
template bool Equihash<48,5>::IsValidSolution(const eh_HashState& base_state, std::vector<eh_index> soln);
|
||||
|
||||
Reference in New Issue
Block a user