MCPcopy Create free account
hub / github.com/Vectorized/function-selector-miner / mine

Function mine

src/main.rs:31–108  ·  view source on GitHub ↗
(
    function_name: &SmallString,
    function_params: &SmallString,
    selector: u32,
    num_threads: usize,
)

Source from the content-addressed store, hash-verified

29}
30
31fn mine<const N: usize>(
32 function_name: &SmallString,
33 function_params: &SmallString,
34 selector: u32,
35 num_threads: usize,
36) {
37 let end = 0xfffffffff0000000u64;
38 let go = AtomicBool::new(true);
39
40 #[cfg(target_feature = "avx2")]
41 const STEP: u64 = 4;
42 #[cfg(not(target_feature = "avx2"))]
43 const STEP: u64 = 1;
44
45 ThreadPoolBuilder::new()
46 .num_threads(num_threads)
47 .build_global()
48 .expect("Failed to create thread pool.");
49
50 println!("Starting mining with {num_threads} threads.");
51
52 let stopwatch = Instant::now();
53
54 (0..num_threads).into_par_iter().for_each(|thread_idx| {
55 let mut idx = 0u64;
56 let mut nonce = thread_idx as u64 * STEP;
57 let step = num_threads as u64 * STEP;
58 while nonce < end {
59 nonce += step;
60 if !go.load(Ordering::Relaxed) {
61 break;
62 }
63
64 #[cfg(not(target_feature = "avx2"))]
65 {
66 log_progress!(thread_idx, idx, 0x3fffff, nonce);
67
68 let mut s0 = Sponge::default();
69 unsafe { s0.fill::<N>(&function_name, nonce, &function_params) };
70
71 if selector == unsafe { s0.compute_selectors() } {
72 let out = unsafe {
73 s0.fill_and_get_name::<N>(&function_name, nonce, &function_params)
74 };
75 log_result_and_break!(out, stopwatch, go);
76 }
77 }
78 #[cfg(target_feature = "avx2")]
79 {
80 log_progress!(thread_idx, idx, 0x1fffff, nonce);
81
82 let mut sponges =
83 unsafe { SpongesAvx::new::<N>(&function_name, nonce, &function_params) };
84
85 let maybe_idx = unsafe {
86 sponges
87 .compute_selectors()
88 .iter()

Callers

nothing calls this directly

Calls 1

compute_selectorsMethod · 0.45

Tested by

no test coverage detected