pub fn find_solution(
challenge: &IronShieldChallenge,
config: Option<PoWConfig>,
start_offset: Option<usize>,
stride: Option<usize>,
progress_callback: Option<&dyn Fn(u64)>,
) -> Result<IronShieldChallengeResponse, String>Expand description
Find a solution for the given IronShieldChallenge using optimized multithreaded computation.
Implements thread-stride approach delegated to multiple threads (e.g. Web Workers or Tokio tasks) for maximum performance. The lack of chunking of nonces between threads dramatically increases performance since threads don’t have to constantly communicate and distribute work. Each thread is mathematically guaranteed to not check overlapping nonces with other threads.
§Algorithm:
- Pre-computes the random_nonce bytes once to avoid repeated hex decoding
- Assigns each thread a start_offset and stride
- Each thread performs the single-threaded algorithm with a stride and offset
- Returns immediately when a solution is found
§Arguments
challenge: The IronShieldChallenge struct containing random_nonce and challenge_paramnum_threads: Ignored (for compatibility only)start_offset: Starting nonce for this worker’s search range (JavaScript coordination)stride: Nonce increment step for thread-stride pattern (JavaScript coordination)
§Returns
Result<IronShieldChallengeResponse, String>:Ok(IronShieldChallengeResponse)that contains the successful nonce, or an error (Err(String)) message if no solution is found withinconfig.max_attempts.
§Example
use ironshield_core::{
IronShieldChallenge,
find_solution,
SigningKey
};
let dummy_key = SigningKey::from_bytes(&[0u8; 32]);
let challenge = IronShieldChallenge::new(
"website".to_string(),
1, // difficulty
dummy_key,
[0x00; 32], // public_key
);
// JavaScript worker coordination mode
let response = find_solution(&challenge, None, Some(0), Some(8), None)?;
println!("Found solution: {}", response.solution);