Skip to content

Commit

Permalink
Add commented-out prints of solution candidates for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 authored and str4d committed Apr 19, 2024
1 parent 0fe0843 commit ed22417
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions components/equihash/src/tromp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern "C" {
///
/// This function uses unsafe code for FFI into the tromp solver.
#[allow(unsafe_code)]
#[allow(clippy::print_stdout)]
unsafe fn worker(eq: *mut CEqui, p: Params, curr_state: &State) -> Vec<Vec<u32>> {
// SAFETY: caller must supply a valid `eq` instance.
//
Expand All @@ -70,13 +71,21 @@ unsafe fn worker(eq: *mut CEqui, p: Params, curr_state: &State) -> Vec<Vec<u32>>
let nsols = equi_nsols(eq);
let sols = equi_sols(eq);
let solution_len = 1 << p.k;
//println!("{nsols} solutions of length {solution_len} at {sols:?}");

// SAFETY:
// - caller must supply a `p` instance that matches the hard-coded values in the C code.
// - `sols` is a single allocation containing at least `nsols` solutions.
// - this slice is a shared ref to the memory in a valid `eq` instance supplied by the caller.
let solutions: &[u32] = slice::from_raw_parts(sols, nsols * solution_len);

/*
println!(
"{nsols} solutions of length {solution_len} as a slice of length {:?}",
solutions.len()
);
*/

let mut chunks = solutions.chunks_exact(solution_len);

// SAFETY:
Expand All @@ -98,6 +107,17 @@ unsafe fn worker(eq: *mut CEqui, p: Params, curr_state: &State) -> Vec<Vec<u32>>
solutions
};

/*
println!(
"{} solutions as cloned vectors of length {:?}",
solutions.len(),
solutions
.iter()
.map(|solution| solution.len())
.collect::<Vec<_>>()
);
*/

solutions
}

Expand Down
11 changes: 9 additions & 2 deletions components/equihash/tromp/equi_miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,15 @@ typedef struct equi equi;
listindices1(eq, WK, t, prf); // assume WK odd
qsort(prf, PROOFSIZE, sizeof(u32), &compu32);
for (u32 i=1; i<PROOFSIZE; i++)
if (prf[i] <= prf[i-1])
if (prf[i] <= prf[i-1]) {
/*
printf(
"failed dup indexes check: wanted: proof[%d] > proof[%d], actual: %d <= %d\n",
i, i-1, prf[i], prf[i-1]
);
*/
return;
}
#ifdef EQUIHASH_TROMP_ATOMIC
u32 soli = std::atomic_fetch_add_explicit(&eq->nsols, 1U, std::memory_order_relaxed);
#else
Expand Down Expand Up @@ -678,7 +685,7 @@ nc++, candidate(eq, tree_from_bid(bucketid, s0, s1));
}
}
}
//printf(" %d candidates ", nc);
//printf(" %d candidates\n", nc);
}

size_t equi_nsols(const equi *eq) {
Expand Down

0 comments on commit ed22417

Please sign in to comment.