From 42cfe667e8b85339127f055c8fa5ab01e094d0bb Mon Sep 17 00:00:00 2001 From: FiveMovesAhead Date: Tue, 14 Oct 2025 12:25:27 +0100 Subject: [PATCH] Add verbose to tig-verifier. --- scripts/test_algorithm | 36 +++++++++++++++++++++--------------- tig-verifier/src/main.rs | 25 ++++++++++++++++++++----- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/scripts/test_algorithm b/scripts/test_algorithm index 4edc5f6..d11864b 100644 --- a/scripts/test_algorithm +++ b/scripts/test_algorithm @@ -176,23 +176,29 @@ f"""Library not found at {so_path}: output_file = f"{temp_dir}/{nonce}.json" ret2 = None elapsed2 = 0 - if os.path.exists(output_file): - cmd2 = [ - args.tig_verifier_path, - json.dumps(settings, separators=(',',':')), - args.seed, - str(nonce), - f"{temp_dir}/{nonce}.json", + + cmd2 = [ + args.tig_verifier_path, + json.dumps(settings, separators=(',',':')), + args.seed, + str(nonce), + output_file, + ] + if ptx_path is not None: + cmd2 += [ + "--ptx", ptx_path, + "--gpu", str(nonce % len(VISIBLE_GPUS)), ] - if ptx_path is not None: - cmd2 += [ - "--ptx", ptx_path, - "--gpu", str(nonce % len(VISIBLE_GPUS)), - ] + if args.verbose: + cmd2 += ["--verbose"] + print(f"[nonce {nonce}] {' '.join(cmd2[:1] + [f"'{cmd2[1]}'"] + cmd2[2:])}") + ret2 = subprocess.Popen(cmd2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, universal_newlines=True) + for line in ret2.stdout: if args.verbose: - print(f"[nonce {nonce}] {' '.join(cmd2[:1] + [f"'{cmd2[1]}'"] + cmd2[2:])}") - ret2 = subprocess.run(cmd2, capture_output=True, text=True) - elapsed2 = now() - start - elapsed + print(f"[nonce {nonce}] {line.strip()}") + ret2.wait() + elapsed2 = now() - start - elapsed + if args.verbose: out = f"[nonce {nonce}] finished\n\ttig-runtime\n\t\telapsed: {elapsed}ms\n\t\texit code: {ret.returncode}\n\t\tstderr: " if ret.returncode != 0: diff --git a/tig-verifier/src/main.rs b/tig-verifier/src/main.rs index d823f48..ddf5c7d 100644 --- a/tig-verifier/src/main.rs +++ b/tig-verifier/src/main.rs @@ -28,6 +28,7 @@ fn cli() -> Command { ) .arg(arg!(--ptx [PTX] "Path to a CUDA ptx file").value_parser(clap::value_parser!(PathBuf))) .arg(arg!(--gpu [GPU] "Which GPU device to use").value_parser(clap::value_parser!(usize))) + .arg(arg!(--verbose "Enable verbose output").action(clap::ArgAction::SetTrue)) } fn main() { @@ -40,6 +41,7 @@ fn main() { matches.get_one::("SOLUTION").unwrap().clone(), matches.get_one::("ptx").cloned(), matches.get_one::("gpu").cloned(), + matches.get_one::("verbose").cloned().unwrap_or(false), ) { eprintln!("Error: {}", e); std::process::exit(1); @@ -53,9 +55,9 @@ pub fn verify_solution( solution_path: String, ptx_path: Option, gpu_device: Option, + verbose: bool, ) -> Result<()> { let settings = load_settings(&settings); - let solution = load_solution(&solution_path); let seed = settings.calc_seed(&rand_hash, nonce); let mut err_msg = Option::::None; @@ -64,12 +66,21 @@ pub fn verify_solution( ($c:ident, cpu) => {{ let challenge = $c::Challenge::generate_instance(&seed, &settings.difficulty.into()).unwrap(); + if verbose { + println!("{:?}", challenge); + } + let solution = load_solution(&solution_path); match serde_json::from_str::<$c::Solution>(&solution) { - Ok(solution) => match challenge.verify_solution(&solution) { - Ok(_) => println!("Solution is valid"), - Err(e) => err_msg = Some(format!("Invalid solution: {}", e)), - }, + Ok(solution) => { + if verbose { + println!("{:?}", solution); + } + match challenge.verify_solution(&solution) { + Ok(_) => println!("Solution is valid"), + Err(e) => err_msg = Some(format!("Invalid solution: {}", e)), + } + } Err(_) => { err_msg = Some(format!( "Invalid solution. Cannot convert to {}::Solution", @@ -105,8 +116,12 @@ pub fn verify_solution( ) .unwrap(); + let solution = load_solution(&solution_path); match serde_json::from_str::<$c::Solution>(&solution) { Ok(solution) => { + if verbose { + println!("{:?}", solution); + } match challenge.verify_solution( &solution, module.clone(),