Skip to content

feat(miner): add validate_deadlines flag to recheck new best deadlines - #63

Open
JohnnyFFM wants to merge 2 commits into
masterfrom
feature/validate-deadlines
Open

JohnnyFFM wants to merge 2 commits into
masterfrom
feature/validate-deadlines

Conversation

@JohnnyFFM

Copy link
Copy Markdown
Collaborator

Summary

Adds an opt-in validate_deadlines config flag (default false) that independently re-derives every new best deadline before the miner trusts it — a best-effort safeguard for users with failing hard drives.

Problem

A failing disk can read a scoop back corrupted, which then hashes to an essentially random — and sometimes lower (better) — deadline. Today that bogus deadline is:

  1. submitted to the chain, where it fails verification (wasted submission); and worse,
  2. recorded as the account's best_quality, so a genuine, slightly-higher deadline found later (in another warp/file) is filtered out by the adjusted_quality < best_quality gate. The bad solution overshadows a valid one locally.

Fix

When validate_deadlines is enabled, the nonce-submission task — the single place that tracks and updates best — re-derives the canonical scoop from (account_id, seed, nonce, scoop) through the scalar (non-SIMD) code path, recomputes the quality, and compares it against the on-disk value. On mismatch (or any decode/regeneration error) the candidate is rejected: best is not updated and nothing is submitted, so a genuine solution can still win.

The scalar and SIMD quality computations are bit-identical (already asserted by existing tests), so a healthy scoop always reproduces its quality exactly; only corrupt data mismatches. Re-derivation runs only on the rare new-best event over a single small scoop — a fair tradeoff for the protection it provides.

Changes

  • pocx_hashlib: refactor generate_scoop to share its loop, add scalar generate_scoop_scalar, calculate_quality_raw_scalar, and calculate_quality_from_height_scalar (built on generate_nonces_32 + find_best_quality_32).
  • pocx_miner: add validate_deadlines (default false) to Cfg, CfgBuilder, and miner_config.yaml.
  • pocx_miner: add the revalidate_deadline gate in create_nonce_submission_tasks.
  • tests: scalar/SIMD quality equivalence and corruption detection.

Known limitation

find_best_quality returns only the single minimum per warp buffer. If a corrupt scoop and a genuine better scoop live in the same warp buffer, rejecting the corrupt one does not recover the genuine one (it was never surfaced). This PR fixes the cross-warp/cross-file overshadowing, which is the main harm; intra-warp masking would require re-scanning inside the hasher and is out of scope.

Verification

  • cargo test -p pocx_hashlib — 53 passed (incl. new test_scalar_quality_matches_simd, test_validate_deadline_detects_corruption).
  • cargo test -p pocx_miner — 29 passed.
  • cargo fmt --all --check — clean.
  • cargo clippy -p pocx_hashlib -p pocx_miner --all-targets -- -D warnings — clean.

JohnnyFFM added 2 commits May 27, 2026 21:32
Add an opt-in `validate_deadlines` config flag (default false) that
independently re-derives each new best deadline before trusting it.

On a failing disk a scoop can be read back corrupted and hash to a
bogus low (good) deadline. That bogus deadline gets submitted (and
fails network verification) and, worse, is recorded as the account's
best quality, filtering out genuine solutions found later in other
warps/files. This is a best-effort safeguard for users with bad drives.

When enabled, the nonce submission task regenerates the canonical scoop
from (account_id, seed, nonce, scoop) via the scalar (non-SIMD) code
path, recomputes the quality, and compares it to the on-disk value. On
mismatch (or any decode/regeneration error) the candidate is rejected:
best is not updated and nothing is submitted, so a genuine solution can
still win. Re-derivation runs only on the rare new-best event over a
single small scoop, a fair tradeoff for the protection it provides.

- pocx_hashlib: add scalar generate_scoop_scalar, calculate_quality_raw_scalar
  and calculate_quality_from_height_scalar (generate_nonces_32 + find_best_quality_32)
- pocx_miner: add validate_deadlines to Cfg/CfgBuilder and miner_config.yaml
- pocx_miner: add revalidation gate in create_nonce_submission_tasks
- tests: scalar/SIMD quality equivalence and corruption detection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant