Add host re-verification for CUDA results and new metrics
Reject false positives from device by verifying on host and add Prometheus counters for estimated rates, found and false-positive candidates per engine and job.
This commit is contained in:
@@ -443,15 +443,28 @@ impl CudaEngine {
|
||||
.with_context(|| "copy distance")?;
|
||||
let distance = U512::from_big_endian(&h_dist);
|
||||
let work = nonce.to_big_endian();
|
||||
log::info!(target: "miner", "CUDA G2: early-exit found at idx={k}");
|
||||
return Ok(EngineStatus::Found {
|
||||
candidate: engine_cpu::EngineCandidate {
|
||||
nonce,
|
||||
work,
|
||||
distance,
|
||||
},
|
||||
hash_count,
|
||||
});
|
||||
// Host re-verification to ensure device result matches chain semantics
|
||||
let host_distance = pow_core::distance_for_nonce(ctx, nonce);
|
||||
if pow_core::is_valid_distance(ctx, host_distance) {
|
||||
log::info!(target: "miner", "CUDA G2: early-exit found at idx={k}");
|
||||
return Ok(EngineStatus::Found {
|
||||
candidate: engine_cpu::EngineCandidate {
|
||||
nonce,
|
||||
work,
|
||||
distance: host_distance,
|
||||
},
|
||||
hash_count,
|
||||
});
|
||||
} else {
|
||||
// Treat as not found: account coverage and advance like the "not found" path
|
||||
log::warn!(target: "miner", "CUDA G2: candidate rejected by host re-verification (false positive): idx={k}");
|
||||
hash_count = hash_count.saturating_add(covered);
|
||||
if covered < total_elems_u64 {
|
||||
return Ok(EngineStatus::Exhausted { hash_count });
|
||||
}
|
||||
current = current.saturating_add(U512::from(1u64 + total_elems_u64));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Not found in this window
|
||||
|
||||
@@ -185,6 +185,51 @@ static JOB_HASH_RATE: Lazy<GaugeVec> = Lazy::new(|| {
|
||||
g
|
||||
});
|
||||
|
||||
static JOB_ESTIMATED_RATE: Lazy<GaugeVec> = Lazy::new(|| {
|
||||
let g = GaugeVec::new(
|
||||
opts!(
|
||||
"miner_job_estimated_rate",
|
||||
"Estimated work rate (nonces per second) per job and engine"
|
||||
),
|
||||
&["engine", "job_id"],
|
||||
)
|
||||
.expect("create miner_job_estimated_rate");
|
||||
REGISTRY
|
||||
.register(Box::new(g.clone()))
|
||||
.expect("register miner_job_estimated_rate");
|
||||
g
|
||||
});
|
||||
|
||||
static CANDIDATES_FOUND_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
|
||||
let c = IntCounterVec::new(
|
||||
opts!(
|
||||
"miner_candidates_found_total",
|
||||
"Total candidates found per job and engine"
|
||||
),
|
||||
&["engine", "job_id"],
|
||||
)
|
||||
.expect("create miner_candidates_found_total");
|
||||
REGISTRY
|
||||
.register(Box::new(c.clone()))
|
||||
.expect("register miner_candidates_found_total");
|
||||
c
|
||||
});
|
||||
|
||||
static CANDIDATES_FALSE_POSITIVE_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
|
||||
let c = IntCounterVec::new(
|
||||
opts!(
|
||||
"miner_candidates_false_positive_total",
|
||||
"Total false-positive candidates rejected by host re-verification per engine"
|
||||
),
|
||||
&["engine"],
|
||||
)
|
||||
.expect("create miner_candidates_false_positive_total");
|
||||
REGISTRY
|
||||
.register(Box::new(c.clone()))
|
||||
.expect("register miner_candidates_false_positive_total");
|
||||
c
|
||||
});
|
||||
|
||||
static THREAD_HASHES_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
|
||||
let c = IntCounterVec::new(
|
||||
opts!(
|
||||
@@ -281,6 +326,24 @@ pub fn set_job_hash_rate(engine: &str, job_id: &str, rate: f64) {
|
||||
JOB_HASH_RATE.with_label_values(&[engine, job_id]).set(rate);
|
||||
}
|
||||
|
||||
pub fn set_job_estimated_rate(engine: &str, job_id: &str, rate: f64) {
|
||||
JOB_ESTIMATED_RATE
|
||||
.with_label_values(&[engine, job_id])
|
||||
.set(rate);
|
||||
}
|
||||
|
||||
pub fn inc_candidates_found(engine: &str, job_id: &str) {
|
||||
CANDIDATES_FOUND_TOTAL
|
||||
.with_label_values(&[engine, job_id])
|
||||
.inc();
|
||||
}
|
||||
|
||||
pub fn inc_candidates_false_positive(engine: &str) {
|
||||
CANDIDATES_FALSE_POSITIVE_TOTAL
|
||||
.with_label_values(&[engine])
|
||||
.inc();
|
||||
}
|
||||
|
||||
pub fn inc_thread_hashes(engine: &str, job_id: &str, thread_id: &str, n: u64) {
|
||||
THREAD_HASHES_TOTAL
|
||||
.with_label_values(&[engine, job_id, thread_id])
|
||||
|
||||
Reference in New Issue
Block a user